Arrow keys | Move the cursor by one character/line | |
h | Move the cursor to the left character | |
j | Move the cursor to the character below it | |
k | Move the cursor to the character above it | |
l | Move the cursor to the right character | |
b | Move the cursor to the begining of the previous word | |
w | Move the cursor to the begining of the next word | |
$ or End | Move the cursor to the end of the line | |
^ | Move the cursor to the first non-blank character of the line | |
0 or Home | Move the cursor to the beginning of the line | |
Ctrl + d | Show the next half screen | 'd' is short for 'down'. |
Ctrl + u | Show the previous half screen | 'u' is short for 'up'. |
Ctrl + f or Page Down | Show the next screen | 'f' is short for 'foward'. |
Ctrl + b or Page Up | Show the previous screen | 'b' is short for 'back'. |
number G | Move the cursor to the line with line number number | If you don't specify number, the cursor is moved to the end of the file |
m mark | Set a (book)mark mark at the cursor | There are quite a few (book)marks to use (a - z, 0 - 9, ', ", [, and ]). The current location to the (book)mark can be used a text unit in delete, copy, etc. |
` mark | Move the cursor to (book)mark mark | You use backtick symbol |
' mark | Move the cursor to the begining of the line with (book)mark mark | You use single quote symbol |
:marks [ mark ] | Show all the (book)marks or a specific (book)mark mark | |
:vi filename | Open another file in vi to edit | |
:view filename | Open another file in vi in read-only mode | |
:next | Switch to the next opened file in vi | Suppose you pass multiple filenames to vi in the command line. |
:previous or :Next | Switch to the previous opened file in vi | Suppose you pass multiple filenames to vi in the command line. |
:first or :rewind | Switch to the first opened file in vi | |
:args | Show all the opened files | Suppose you pass multiple filenames to vi in the command line. The current file's name is enclosed in square bracket |
f letter | Search to the right in the same line for letter | 'f' is short for 'forward' |
F letter | Search to the left in the same line for letter | |
t letter | Search to the right in the same line for the character before letter | 't' is short for 'till' |
T letter | Search to the left in the same line for the character after letter | |
/pattern | Search from the current location to the end of the file for pattern | After typing '/', you can use Up and Down arrow keys to select a recent search |
?pattern | Search from the current location to the beginning of the file for pattern | |
n | Repeat the search in the same direction | The direction is determined by the previos search operation. If you use '/', the same direction is towards the end of the file; if you use '?', the same direction is towards the begnining of the file. |
N | Repeat the search in the reverse direction | |
:set hlsearch | Turn on highlighting matched strings | |
:set nohlsearch | Turn off search highlighting | |
:nohlsearch | Clear the current highlighting | |
:1,$s/search-string/replace-string[/g] | Substitute search-string with replace-string throughout the file | 'g' means global replacement in each line |
y y | Copy the current line to the anonymous clipboard | 'y' is short for 'yank'. BTW, any delete operation moves the deleted characters to the anonymous clipboard. |
p or P | Paste the characters from the anonymous clipboard after/before the current location | |
" letter y w | Copy the characters from the current location to the end of the word to a named clipboard | The name of the clipboard is letter. You have 26 named clipboards (a-z) to use. The key w can be replaced with other keys, as explained below. |
" LETTER y w | Append the characters from the current location to the end of the word to a named clipboard | The name of the clipboard is letter. Here, you still have 26 named clipboards (a-z) to use, but you need to use an uppercase letter (A-Z). The key w can be replaced with other keys, as explained below. |
" letter p or " letter P | Paste the characters from the named clipboard (a-z) after/before the current location | |
[ lines ] :split [ +command ] [ filename ] | Open a new window | Specify a filename to open a new file in the new window. You can also specify the size of the new window as the number of lines, and run some initial command |
Ctrl-w w | Switch to a different window | |
Ctrl-w + | Increase the current window by 1 line | |
Ctrl-w - | Decrease the current window by 1 line | |
Ctrl-w = | Make windows the same size | |
[ lines ] Ctrl-w _ | Maximize the current window without line numbers. Otherwise, set the window size to the line number | |