For the vim newbies out there, here’s a list of the vim commands that I use most on a day-to-day basis. vim seems really intimidating at first, but once you get the hang of it you will miss all the keyboard shortcuts. Also, there are many flavors of vi/vim, but these commands should work universally. Enjoy! PS — Capitals and punctuation matter!
What it does
Returns vim to “normal” mode or state.
Show line numbers in vim.
Save file as “newfile.txt”.
Save and quit vim.
Quit with no save vim.
Move cursor to the beginning of the current line.
Move cursor to the end of the current line.
Undo last command.
Change to insert mode to freeform type text. Hit esc to exit back to normal vim mode.
Move to end of line and enter insert mode. (Note this is a combination of $ and then i.)
Insert a blank line before the cursor and enter insert mode.
Delete current character at cursor. 9x will delete the next nine characters.
Delete current character and replace it with next character typed. vim will enter insert mode for one character.
Delete current word. 4dw will delete the next 4 words starting at the cursor.
Delete current line. 4dd will delete the next 4 lines from the cursor.
Copy line (Yank). 2Y will copy the next two lines after the cursor.
Paste copied text.
Search for and move to the next instance of ‘searchFor’ in the file.
Search for and move to the next instance of your last search. Repeatedly hitting ‘/’ is a quick way to toggle through a file looking for a string.
On this line, search for ‘searchFor’ text and replace with ‘replaceWith’.
Search for ‘searchFor’ text and replace with ‘replaceWith’ globally (for all lines).
Search for ‘searchFor’ text and replace with ‘replaceWith’ from line number 1 to line number 10.