XNIU’s space

July 24, 2007

VIM tips

Filed under: Tech — xniu @ 8:46 pm

It has not been short time since I began using VIM, or more precisely, studying VIM. Its high efficiency deeply impresses me so that I’m determined to become skilled in using it. I do believe that I’ll benefit a lot from it.

From now on, I would collect the tips which make VIM increasingly powerful, means I would frequently update this post to add new tricks. To not disappoint the readers who also have great interest on it when there are only a few tips available at first, I’d like to place some links I consider quite useful here:

http://www.vim.org/tips/index.php (Tips on official site, however, you would be recommended to go to its wiki site.)

http://rayninfo.co.uk/vimtips.html (Said to be “Best VIM tips”, by a guy “15 Years of Vi + 5 years of Vim and still learning” )

http://www.study-area.org/tips/vim/index.html (A light tutorial)

http://vimdoc.sourceforge.net/htmldoc/usr_toc.html (Official document in HTML format, well organized)

http://www.eandem.co.uk/mrw/vim/usr_doc/a4c_bm.zip (PDF format document, but not up-to-date, just for VIM 6.1)


[Added on July 25th]

– use “J” to join current line and next line, namely deleting the line break
– use “O” to insert a new line above the current line, compared to using “o” to insert a new line under current line.
– use “:e!” to discard current changes and reload original file.
– use “:h index” to list all the commands for each mode.
– “w” and “b” can be used to move to the start of word forward and backward among lines; use “e” to move to the end of word.
– use “W” and “B” to move by white-space separated words.
– instead of using ‘G’, ‘gg’ to locate the line in the file, ‘H’, ‘M’ and ‘L’ can be used to move to the lines in the visible area.
– when searching, use ‘\>’ to limit the match at the end of a word, similarly use ‘\<‘ to match only at the beginning.

[Added on July 26th]

– “*” and “#” match exactly the whole word; “g*” and “g#” can be used to match partial word.
– there are unnamed marks which are created automatically when jumping among lines and named marks which can be created manually by “m{$}”.
– “‘”: last jump position; “””: last edit position; “[“: start of last change; “]”: end of last change
– “<C-I>” and “<C-O>” can be used to move up and down through the jump stack;
– use “‘” to jump to the beginning of the line where the mark is located while use “`” (above “Tab” key) to jump to the exact column of the mark in the line.
– “x” = “dl” “X” = “dh” “D” = “d$” “C” = “c$” “s” = “cl” “S” = “cc”.
– use “r” to replace a single character without switching to insert mode.
– use “.” to repeat any CHANGE command (except for undo, redo, and commands starting with “:”), very powerful.
– use “v” to switch to visual mode and move by character; use “V” to switch to visual mode for selecting lines.
– in visual mode, use “o” to switch sides for selection.
– use “p” to put a line below current cursor or put characters after cursor; while “P” behaves contrariwise.
– use “aw” to operate on a word with space; use “iw” to operate on a word without space.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: