Wednesday, March 31, 2010

Short Post - My Favorite Vim Tip

Vim is a tricky editor, and there are many tips for using it to its full potential. Out of the tips that I know, I have a favorite.

Place this in your vim config file:
imap jf <Esc>
Now you can press 'jf' instead of Escape to exit Insert mode. Feel free to remove 'jf' and insert anything you want in its place.

Related Tips

cmap jf <Esc>
Exactly like the above, only this works in Command-line mode.
" Don't put this in your Vim config
vmap jf <Esc>
This manages to break part of Visual mode. Specifically, pressing '$' while in Visual mode will select everything from the current position to the end of the NEXT LINE (instead of the current line). Replacing 'jf' with 'jj' seems to prevent this glitch, but it could cause another one. Visual mode seems like a delicate little flower, and it's best not to step on it.

I didn't come up with this

I first saw a version of this tip in an old version of the Vim thread on The Awful Forums, so credit goes to whoever wants it. The old Vim thread is currently stuck in that forum's members-only archives, so I can't provide a link to it. But here's a link to the latest Vim thread that may or may not work for you.

No comments:

Post a Comment