VI
Moving the cursor
command | Description |
---|---|
h |
move left |
j |
move down |
k |
move up |
l |
move right |
0 |
move to the beginning of the line |
$ |
move to the end of the line |
gg |
move to the beginning of the file |
G |
move to the end of the file |
{ |
move up one paragraph |
} |
move down one paragraph |
Editing text
command | Description |
---|---|
i |
insert text before the cursor |
a |
insert text after the cursor |
o |
insert a new line below the current line and switch to insert mode |
O |
insert a new line above the current line and switch to insert mode |
x |
delete the character under the cursor |
dd |
delete the current line |
yy |
copy the current line |
p |
paste the copied or deleted text after the cursor |
P |
paste the copied or deleted text before the cursor |
u |
undo the last change |
Saving and exiting
command | Description |
---|---|
:w |
save the file |
:q |
quit the editor |
:wq |
save and quit the editor |
:q! |
quit without saving changes |
Searching
command | Description |
---|---|
/pattern |
search forward for a pattern |
?pattern |
search backward for a pattern |
n |
find the next occurrence of the pattern |
N |
find the previous occurrence of the pattern |
Other useful commands
command | Description |
---|---|
:set number |
display line numbers |
:set nonumber |
hide line numbers |
:set tabstop=4 |
set the tab width to 4 spaces |
:set ignorecase |
ignore case when searching |
:set noignorecase |
do not ignore case when searching |
:help |
open the help system |