What is VIM?
VIM is a powerful editor based on
vi, which exists on most platforms and comes pre-installed on most UNIX machines. On Linux platforms,
vi is aliased to invoke
Commands to move cursor around your terminal or window:
|first line of a file
|last line of a file
|beginning of a line
|end of a line
|previous character (left)
|next character (right)
|previous line (up)
|next line (down)
Note that, if you enter a numerical value before typing the command letters, the action is repeated. For example, to move 10 lines up, type
If you want to go to a specific line number in your file, type
To search for a pattern:
After typing and hitting the
Enter. key, your cursor will stop at beginning of the first match from the last cursor position. To cycle forward through all of the matched patterns, type
n. To cycle backward, type
To select characters covered by motion:
To select everything:
gg moves to beginning of file,
G$ motion covers last character of last line in the file.
To insert new texts at current cursor position, type
i; to insert after current cursor position, type
a. To append new texts at end of line, type
A. Once you enter insert/append mode, you will remain in that mode until you hit the
As an aside,
[ is also the same as the
Esc key. But you don't want to use it too often, because you may get the Emacs claws; just because you can doesn't mean you have to.
To delete character at current cursor position, type
x; to delete previous character type
X. To delete one line type
To copy one line, type
Y; if you have made a selection already, type
y to copy your selection. To paste what you copied, type
P to insert before current cursor position; type
p to append after current cursor position.
As with most
vi commands, typing a number before typing commands repeats the action the number of times you specify. So to type:
blah blah blah blah blah
I just need to type the following sequence:
`5iblah ` and hit
Esc key twice.
5 for the number of repeats,
i to enter insert mode.
Global replace target with replacement, both works the same way:
Line justification (useful if you use
vim as an editor for e-mails, such as from within
pine) for texts covered by motion to fit a terminal of 80 columns:
(For example, motion here can be
G$, to cover from present cursor location till end of file.)
Mark current position with label (a key) and then recall it (bring cursor back to the marked position):
First select the text you want to indent, then use
,) keys to indent right and left.
== will indent a range of text automatically.
To enable syntax folding, use command
zO opens one/all fold levels.
zC closes one/all fold levels.
zM folds one/all levels deeper.
zR reduces one/all fold levels.
When you work with terminals, you may want to tell
vim to use 2 space characters are used for each tab:
To toggle line numbers, type:
Other useful commands:
set nu /
set nonu to display/hide line numbers.
set list /
set nolist to display/hide non-printable characters.
set ic /
set noic to perform non-case-sensitive/case-sensitive search.