:w !sudo tee % = this command will ask you root psw after you edited a file and you are getting the error that file is own by root and need to sudo vim instead
$sudo vim /path/to/file
:wq = write and force quit
:q! = exit and ignore any changes
ZZ = exit and save changes if any have been made
:x = exit, saving changes
dd = delete current line (delete without going into insert mode)
:d = delete current line
yy = yank current line (copy without going into insert mode) u :y = yank current line
y$ = yank to the end of the line
C = change to the end of line (cut and go into insert mode)
cc = change the whole line
p = put after the position or after the line (paste without going into insert mode)
P = Put before the position or before the line
/string = search forward for string
?string = search backward for string
n = search for next instance of string
N = search for previous instance of string
:s/pattern/string/flags = replace pattern with string according to flags.
• Arrow keys - move the cursor around
• j, k, h, l - move the cursor down, up, left and right (similar to the arrow keys)
• ^ (caret) - move cursor to beginning of current line
• $ - move cursor to end of the current line
• nG - move to the nth line (eg 5G moves to 5th line)
• G - move to the last line
• w - move to the beginning of the next word
• nw - move forward n word (eg 2w moves two words forwards)
• b - move to the beginning of the previous word
• nb - move back n word
• { - move backward one paragraph
• } - move forward one paragraph
• x - delete a single character
• nx - delete n characters (eg 5x deletes five characters)
• dd - delete the current line
• dn - d followed by a movement command. Delete to where the movement command would have taken you. (eg d5w
means delete 5 words
• u - Undo the last action (you may keep pressing u to keep undoing)
• U (Note: capital) - Undo all changes to the current line