iOS engineer who likes clean, simple designs and sans-serif.

Loading

frequently used vim commands

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!

Shortcut What it does
esc Returns vim to “normal” mode or state.
:set nu Show line numbers in vim.
:w newfile.txt Save file as “newfile.txt”.
:wq Save and quit vim.
:q! Quit with no save vim.
^ Move cursor to the beginning of the current line.
$ Move cursor to the end of the current line.
u Undo last command.
i Change to insert mode to freeform type text. Hit esc to exit back to normal vim mode.
A Move to end of line and enter insert mode. (Note this is a combination of $ and then i.)
O Insert a blank line before the cursor and enter insert mode.
x Delete current character at cursor. 9x will delete the next nine characters.
r Delete current character and replace it with next character typed. vim will enter insert mode for one character.
dw Delete current word. 4dw will delete the next 4 words starting at the cursor.
dd Delete current line. 4dd will delete the next 4 lines from the cursor.
Y Copy line (Yank). 2Y will copy the next two lines after the cursor.
P Paste copied text.
/searchFor 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.
:s/searchFor/replaceWith/g On this line, search for ‘searchFor’ text and replace with ‘replaceWith’.
:%s/searchFor/replaceWith/g Search for ‘searchFor’ text and replace with ‘replaceWith’ globally (for all lines).
:1,10%s/searchFor/replaceWith/g Search for ‘searchFor’ text and replace with ‘replaceWith’ from line number 1 to line number 10.

Leave a Comment