VIM is a powerful text editor.
This document has been written to help people who can already use vi to learn some of VIM's features.
To enter:
for (flightplanIt = fps.begin();
flightplanIt != fps.end(); ++flightplanIt)
Type:
for (flightplanIt = fps.begin();
fl<CTRL-p> != fps.end(); ++
f<CTRL-p><CTRL-p>)
The VIM complete variable (set using ":set complete=options") specifies where VIM will search for words to use when doing word completions (e.g. adding `]' to the option list will cause VIM to search your tags file).
VIM has a nice interface to the grep command. (grep can be used to find where a search pattern appears in a collection of files.)
Display a window which lists all matches.
Double-click on an entry and VIM will load the corresponding file and take you to the selected match.
Visual selections are an easy way to specify the text that a command will operate on. Once a selection has been made, pressing d will delete the selection, y will copy ("yank"), > will increase indentation, etc.
A fold displays several lines as a single line. You can fold "uninteresting" lines so that you can focus on the lines which are relevant to your current task.
Folding was added in VIM version 6.0.
To select the lines to be folded, either make a "visual selection" or follow zf with a "movement" command.
VIM remembers each jump you perform: If you want to return to a place you recently visited then you can press CTRL-o several times until you return there.
I like to use zt after I do a tag jump to a function definition.
To search backwards type ?(Shift-/) instead of /. (Note: The Shift key is often used in vi to perform an action in reverse.)
I have Shift-<ESC> mapped to do ":nohls". (I added
nmap CTRL-v Shift-ESC
:nohls CTRL-v ENTER
to my .vimrc file.)
(This is much quicker than typing ?\<word_under_cursor\>.)
Tags associate a symbol to a location in a file. Tags are often used by programmers to quickly find function definitions.
A tag file for C source code can be generated with ctags
.
(VIM has a nice interface to cscope. cscope
can be
used to find symbol definitions (as with regular tags), but can also
quickly perform other searches such as finding everywhere where a
specified function is called.)
:ptj could be useful if you want to see the types of the parameters which should be passed to a subprogram.
VIM keeps a list of the commands you have entered. Use the up and down arrow keys to move through the list of commands.
Typing the start of a command and then pressing the up key will cause VIM to find the last command which started with the text you just entered (e.g. :tj <Up> will retrieve the last tag jump command you entered).
You can use normal VIM commands to edit command lines (e.g. `$' will take you to end of line).
Don't forget to type `i' (insert) before you enter the text for a new command.
VIM can show pieces of text in different colors. For example; program comments can be shown in a particular color so that they can be immediately recognised.
VIM can color ()'s in Java source code a different color depending on the
level of nesting! This helps in identifying a matching bracket. Type
:help java-syntax for more information. (Note: in VIM
6.1-247 it was necessary to modify the syntax/java.vim
file to
get this feature to work properly. I had to add "transparent
" to
the definitions for javaParenT
, javaParenT1
and
javaParenT2
.)
Some commands allow using a "movement" as a way to specify the text which the command should affect. Updates can be made very quickly this way.
(You can use tag commands to move between topics.)
Last Update: 6 January 2006