background preloader


Facebook Twitter

Open in iTerm Vim from Finder - The Pug Automatic. When I double-click a code file in Finder, I want it to open in Vim in a terminal.

Open in iTerm Vim from Finder - The Pug Automatic

Not in MacVim. Not in some lesser editor. There’s plenty of prior work, but nothing worked well for me on OS X 10.10 Yosemite, so I rolled my own. The end result: double-clicking a file opens a new iTerm window with the file opened in Vim. Since it execs Vim (replaces the shell process), the window closes when you quit Vim. 1. Download, unzip it and stick the app in /Applications. Or make your own: Open Apple’s “Automator” app.If you get a file dialog, opt to create a “New Document”.Select the “Application” type.Search the action list for “Run AppleScript”, double-click that option.Change the script to this (hat tip to Rob Peck): Save as /Applications/ 2. Vim anti-patterns. The benefits of getting to grips with Vim are immense in terms of editing speed and maintaining your “flow” when you’re on a roll, whether writing code, poetry, or prose, but because the learning curve is so steep for a text editor, it’s very easy to retain habits from your time learning the editor that stick with you well into mastery.

Vim anti-patterns

Because Vim makes you so fast and fluent, it’s especially hard to root these out because you might not even notice them, but it’s worth it. Here I’ll list some of the more common ones. Moving one line at a time If you have to move more than a couple of lines, moving one line at a time by holding down j or k is inefficient. There are many more ways to move vertically in Vim. . { — Move to start of previous paragraph or code block.} — Move to end of next paragraph or code block.Ctrl+F — Move forward one screenful.Ctrl+B — Move backward one screenful. Habit breaking, habit making. Moving your Vim cursor around using the arrow keys is a bad habit, and like many bad habits it’s a difficult one to break!

Habit breaking, habit making

Putting these lines into your vimrc can help: noremap <Up><NOP> noremap <Down><NOP> noremap <Left><NOP> noremap <Right><NOP> This snippet causes each of the arrow keys to execute no operation, or in other words: it disables them. Next time you move your hand to the arrow keys you’ll find that nothing happens when you press them. That should remind you to move your hand back where it belongs: on the home row, where h, j, k, and l keys are waiting for you. Learning to operate Vim without leaving the home row is the first rite of passage. Stop using the h, j, k, l keys! There’s nothing slower than moving one line or column at a time. Change Cursor in Vim in iTerm2. 9 Mar, 2014Tags: vim, OS X.

Change Cursor in Vim in iTerm2

A neat trick I stumbled over in iTerm2’s documentation is that one can change the cursor shape from the block (default) to a vertical bar. This is great to do for Vim’s insert mode where the cursor conceptually is between characters. Adding the following to ~/.vimrc will change the cursor to a vertical bar in insert mode and keep it as a block in the other modes. This should also work in Konsole, as far as I know, so if you use Konsole you should extend/replace the $TERM_PROGRAM check to look for Konsole. " Change cursor shape between insert and normal mode in if $TERM_PROGRAM =~ "iTerm" let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode endif.

Vim and Ctags. Combining vim with ctags yields a powerful combination for working with large or unfamiliar codebases. Ctags is a tool that will sift through your code, indexing methods, classes, variables, and other identifiers, storing the index in a tags file. The tags file contains a single tag per line. Depending on command line arguments and the language ctags is run against, a lot of information can be obtained from this index. Ctags currently supports 41 programming languages, and it’s relatively easy to add definitions for more. Vim Awesome. Making the clipboard work between iTerm2, tmux, vim and OS X. Getting copying and pasting to behave sanely when working with the terminal has been a constant struggle, probably ever since I started working with PuTTY, slackware and what must have been Windows 98.

Making the clipboard work between iTerm2, tmux, vim and OS X.

These days my environment consists of OS X 10.10, tmux, iTerm2 and well, Vim has never gone away. Neither have my issues with copy-pasting though. It seems that every time I have a solution, a few months later a cog in the machine changes and breaks the whole set-up again, which then takes me months to fix due to my lazyness. I finally took the time again to look into this, and figured I should share. So this is the December 2014 solution! iTerm2 First: iTerm2. iTerm2 has a setting that allows terminal applications to access the clipboard. This works through ANSI escape sequences, and you actually want this OFF. So to repeat this, the “Allow clipboard access to terminal apps” must be OFF tmux OS X has two command-line utilities to interact with the clipboard, pbcopy and pbpaste.

Sculpting text with regex, grep, sed and awk. Theory: Regular languages Many tools for searching and sculpting text rely on a pattern language known as regular expressions.

Sculpting text with regex, grep, sed and awk

The theory of regular languages underpins regular expressions. (Caveat: Some modern "regular" expression systems can describe irregular languages, which is why the term "regex" is preferred for these systems.) Regular languages are a class of formal language equivalent in power to those recognized by deterministic finite automata (DFAs) and nondeterministic finite automata (NFAs). [See my post on converting regular expressions to NFAs.] In formal language theory, a language is a set of strings. For example, {"foo"} and {"foo", "foobar"} are formal (if small) languages. (Mathematicians don't typically put quotes around a string, preferring to let the fixed-width typewriter font distinguish it as one, but I'm guessing that programmers are more comfortable with the quotes around strings.) Best of VIM Tips, gVIM's Key Features zzapper.