The vim editor
Inserting text
Command | Action |
---|---|
i | Insert text before current cursor position |
a | Append text after current cursor position |
A | Append text at the end of the current line |
o | Open new line below the current line |
O | Open new line above the current line |
Navigating in vi
Command | Action |
---|---|
left arrow / h | move left 1 character |
right arrow / l | more right 1 character |
up arrow / k | move up 1 line |
down arrow / j | move down 1 line |
$ | move to the end of current line |
0 | move to beginning of current line |
Deleting text
Command | Action |
---|---|
x | delete character at current cursor position |
dw | delete word or part of word to the right of cursor |
dd | delete current line |
D | Delete current line starting from the current cursor position |
Undoing and repeating
Command | Action |
---|---|
u | undo the last command |
. (dot) | repeat the last command |
Search and replace text
Command | Action |
---|---|
/[string] | Search forward for string |
?[search] | Search backward for string |
n | Find next occurrence of string |
N | find previous occurrence of string |
:%s/old/new | Search and replace first occurrence of string old with string new |
:%s/old/new/g | Search and replace all occurrence of string old with string new |
cw | Change the word staring from current cursor position |
r | Replace character at current cursor position |
R | Replace/overwrite text on current line |
Copying and Pasting text
Command | Action |
---|---|
yw | Yank the current word in buffer |
yy | Yank the current line in buffer |
p | Paste the yanked data below the current line |
P | Paste the yanked data above the current line |
Saving and quiting
Command | Action |
---|---|
:w | Write change into the file without quitting |
:w! | write change into the file even if you are not owner of the file |
:wq | write change into the file and quit |
:wq! | write change into the file and quit even if you are not owner of the file |
:q | quits when no changes are made |
:q! | quits without saving the changes made |