Created: Jan, 2012
Last modified: Feb, 2016
A tiny subset of VIM commands I find very useful…
Insert characters in multiple lines (such as inserting space at the head of multiple lines): see this post
How to use Vundle to manage VIM plugins.
Open multiple files in new tabs or split windows and navigate: this can be handy when working on multiple files.
w; move forward by 3 words:
b; move backward by 3 words:
0; move to the non-blank character of the line: ‘^’.
); move backward by one sentence:
}; move backward by one paragraph:
Move to the top of screen:
H; middle of screen:
M; and bottom of screen:
This page summarizes it well.
Put the following lines to “~/.vimrc”:
set autoindent set shiftwidth=4 set softtabstop=4 set expandtab
Here “autoindent” does no more than indenting following the previous line. For C/C++ files one may explore “cindent” option.
To disable autoindentation when pasting text, do this in normal mode:
After done with pasting, do this to re-enable autoindentation with
Another trick is to set a key shortcut to toggle this “paste action” by adding this line to ‘~/.vimrc’:
which will associate key F10 with this toggling behavior.
By default, the comments are lightlighted with dark blue in a black background, which is hard to see in a terminal. I find using “desert” color theme in a black ground works better. Add this line to “~/.vimrc”:
To search and replace A with B in the current line
To search and replace A with B globally (all lines)
To search and replace A with B globally with confirmation of each match
:! g++ %
which will compile the current file with GCC C++ compiler.
To change the working directory to the directory the file being editing is in, run
Explanation of the above command: % gives the name of the current file, %:p gives its full path, and %:p:h gives its directory (the “head” of the full path).
For more information on this topic, see this post.
Ctrl+v to enter visual block mode. It is amazing. See this tutorial for a brief introduction.