VIM
filesystem
:e - open a file
:w - write a file
:q - quit
:q! - quit without saving
:x - write and quit (only wtites if there are changes). “exit”
view
:set nu! toggle line numbering
Modes
Normal Mode
Esc Enter normal mode. This is the mode vim starts in.
While in Normal mode use the following commands:
xdelete the character under the cursordddelete and copy the current lineppasteuundohjklbasic cursor movement (←↓↑→):put vim in “last-line” modegsubsequent command will be performed globally./search forwards (pressEnterto highlight all):nohclear higlighting?search backwards:help <command>help on specific<command>
:g/<string-to-search>/d will delete the line with the last instance of <string-to-search>
All the filesystem commands
Insert mode
i - enter/exit insert mode
While in Insert mode use the following commands:
ainsert after the cursoroinsert a new line after the current one (lower case ‘o’)Oinset a nwe line before the current one (upper case ‘O’)cwreplace from the cursor to the end of the word
Visual mode
v - enter/exit “visual” mode. This can be used to select text. Once you’ve selected it there are several things you can do
ddelete the textyyank (copy) the text ("+yto copy to system clipboard)yyto copy the current lineppaste the text