高見龍

iOS app/Ruby/Rails Developer, 喜愛非主流的新玩具 :)

« Switch to Presentation Mode Vim與我的工作環境 »

Some Vim Tips and Learning Resources

I’m still pretty new to Vim and keep practicing Vim everyday, and also started to learn some VimScript by myself, I found some nice learning resources and some easy but AWESOME key combinations.

Learning Resources

Screencasts

Books and Articles

Others

  • vimtutor is a great resource, you can type vimtutor in terminal directly to launch it. there’s also some translated version, ex: vimtutor zh would be the tranditional chinese version.
  • last but not the least, the best resource is the built-in HELP manual, just type :h something, and you SHOULD read them through at least one time.

Tips

  • dw : delete a word from current cursor position.
  • diw : delete the whold word which the cursor is parking.
  • dfSpace : delete everything until finding the next Space of the current line.
  • di( : as above, but delete all words within the nearest parenthesis, di[, di", and di' also do pretty much the same thing.
  • gv : re-select last visual select.
  • ma to create a marker named a at the current cursor, then by hitting 'a to jump to the a marker. You can use a to z as the name of the marker.
  • :.![command] will dump the output of the command to your current editing window.
  • %!xxd turn vim to a hex editor, and %!xxd -r will change it back.
  • even you don’t manage your file within any version control system, :earlier 10m can help you to change the current file back to 10 minites ago, and :later 10m will jump back to 10 minites later.
  • :undo 5 will go back by 5 changes, and :undolist will show you undo tree.
  • you can grab web page source code into your editor directly, just like this vim http://www.eddie.com.tw

Some crazy/stupid things

I use Vim almost everyday now, but to be more sophisticated in it, I did some stupid or crazy things.

First, I removed my ESC key from my keyboard temporarily to force myself using Ctrl[, instead of hitting Esc to enter normal mode:

image

Why? actually there’s no good reason, just thought it might keep my fingers on main typing area in mode switching.

and second, I re-map the arrow keys to <NOP> to disable them, both in normal mode and insert mode:

map <UP> <NOP>
map <DOWN> <NOP>
map <LEFT> <NOP>
map <RIGHT> <NOP>
inoremap <UP> <NOP>
inoremap <DOWN> <NOP>
inoremap <LEFT> <NOP>
inoremap <RIGHt> <NOP>

You may think I’m crazy, but I think it’s a faster way to push those things into my muscle memory. I think there’s no shortcut to master Vim, just keep using it everyday.

At last, here is my yet another vimrc configuration. If you have any other tips which are also AWESOME, please let me know :)

Comments