vim Getting started with vim Basics


Example

Run interactive vim tutorials as many times as needed to feel comfortable with the basics.

Vim features several modes, e.g. normal mode, insert mode and command-line mode.

Normal mode is for editing and navigating text. In this mode h, j, k and l correspond to the cursor keys , , and . Most commands in normal mode can be prefixed with a "count", e.g. 3j moves down 3 lines.

Insert mode is for inserting the text directly, in this mode vim is similar to other more simple text editors. To enter insert mode press i in normal mode. To leave it press <ESC> (escape key).

Command-line mode is for running more complex commands like saving the file and exiting vim. Press : to start the command-line mode. To leave this mode you can also press <ESC>. To save the changes to the file use :w (or :write). To exit vim without saving your changes use :q! (or :quit!).

These are some of the more useful commands in vim:

CommandDescription
i(insert) enters insert mode before the current cursor position
Ienters insert mode before the first printable character of the current line
a(append) enters insert mode after the current cursor position
Aenters insert mode after the last printable character of the current line
xdelete character at the current cursor position
Xdelete character at the left to the current cursor position
wmove to next word
bmove to previous word
0move to the beginning of line
$move to the end of line
rreplace – enters replace mode for one character. The next character you type will replace the character under the cursor.
Renters replace mode indefinitely. Every character you type will replace the character under the cursor and advance the cursor by one.
ssubstitute – deletes the character at the current cursor position and then enters insert mode
Sdelete the current line that the cursor is currently on and enter insert mode
<Esc>, <C-c>exit insert mode and returns to normal mode
uundo
<C-r>redo
dd, dw, dl, d$cut the current line, from the cursor to next word, or the character, current position to end of current line respectively, note: D is the equivalent of d$
cc, cw, clchange the current line, from the cursor to next word, or the character, respectively
yy, yw, yl, y$yank ("copy") the current line, from the cursor to next word, or the character, current position to end of current line respectively
p, Pput ("paste") after, or before current position, respectively
o, Oto create a new empty line, after or before the current one and enter insert mode
:wwrite the current buffer to disk
:q!, ZQquit without writing
:x, :wq, ZZwrite and quit
:helpopen a window with help file
:help {subject}show help for a specific subject
qzbegin recording actions to register z, q to end recording, @z to play back the actions. z can be any letter: q is often used for convenience. Read more: Macros