Vim
Modes​
- Default mode is command mode or NORMAL. This is where you can run all your vim commands.
- Insert mode is accessed by pressing
i, this lets you edit the file. You can get out of insert mode with eitherESCorCTRL + C. oputs you on a new line below and in insert mode.Oput you on a new line above and in insert mode.aputs you in insert mode in front of the selected char.
Exiting​
:qquits the program (won't let you if you haven't saved).:wwrites to the file (saves).:wqwrites and quits.q!quits without saving unsaved changes.
Movement​
-
Either use the arrow keys (self explanatory).
-
Or
HJKL.HleftJdownKupLright
-
0Jump to start of the line. -
^Jump to start of the line (not whitespace). -
$Jump to the end of the line.- If you press this and then move up and down, the cursor will stay at the end of each line.
-
ggJump to top of the file. -
GJump to end of the file.
Deleting​
xdeletes a characterddelete from:ddcurrent lined$the cursor to the end of the line.d0ord^the cursor to the start of the line.dGthe current position to the end of the file.dggthe current position to the start of the file.djthe current line and the line below.dkthe current line and the line above.
2dd,3dddeletes the next N lines.d/PATTERNdeletes everything from the current position to the first match (not including the match).dndeletes everything until the next occurrence of the pattern used in previous command.
Searching​
/PATTERNsearch forward for PATTERN?PATTERNsearch backward for PATTERNnjump to the next matchNjump to previous match
Jumping​
f + CHARsearch forward on the current line to CHAR.t + CHARsearch forward on the current line to the character before CHAR.F + CHARsearch backward on the current line to CHAR.T + CHARsearch backward on the current line to the character after CHAR.
Search & Replace​
:s/PATTERN/REPLACEMENT/FLAGSfor a line (just a regex):%s/PATTERN/REPLACEMENT/FLAGSfor a file- Will only do the replacement for the first match unless you supply the
gflag.
Visual Select​
yyanks the selected text into the paste buffer.ppastes what is in the paste buffer.xorddeletes selected text and puts it in the paste buffer.>>indent the text right by shift width.<<indent the text left by shift width.Vputs you in visual line mode, great for selecting lines.Jmove the next line to the end of the current line.(backtick) + .go to the last edit.
Inserting​
:r FILEPATHinserts the file into the current file.:r! COMMANDinserts the output of the command into the current file.
Terminal​
- Run
set -o vi. - You can put your command line into vim mode by hitting
ESC.
Recording​
q+THE KEY YOU WANT TO MAP TO, then type your stuff in, when done hitqto stop recording.- Press
@+THE KEY YOU MAPPED TO, to use the recording. - Eg. Converting string to template string:
const = 'text'
// press q + t (for example)
// recording has started
const = `text` // manually change it now using f in vim
// press q to stop recording
// now you can use @ + t to redo this wherever else you want.