Common VIM Commands

02 Jan 2016 | vi, vim, common commands

TL;DR Run vimtutor and be enlightened!

Simple Editing

Action Command
Insert i
Append a
Append to end of line A
Insert line (above) O
Insert line (below) o
Delete char x
Delete word dw
Delete line dd
Delete to end of line d$
Undo Change u
Undo Line U
Redo Ctrl+R

Advanced Editing

Action Command
Visual Selection v
Toggle Case select word and ~
Copy-and-paste yy (copy) and p (put)
Cut-and-paste dd (cut line) and p (put)
Replace character r (followed by the char to be replaced)
Replace mode R (enters replace mode)
Change word ce
Change everything to end of line c$
Delete in parenthesis di(
Delete in quotes di"
Delete all lines in file :1,$d
Global replace :%s/old/new/g
Global replace with prompt :%s/old/new/gc
Action Command
Navigate to beginning of line 0
Navigate to end of line $
Navigate to beginning of next word w
Navigate to end of next word e
Move to end of file G
Move to start of file gg
Go to line number :<line number>
Previous Location Ctrl+O
Next Location Ctrl+I
Navigate to matching brace (cursor on the brace) v%
Action Command
Search for pattern /<pattern>
Search Backwards ?<pattern>
Next Hit n
Previous Hit N
Match parentheses % (at the opening/closing parenthesis)

Set Search Options

Action Command
Ignore case :set ic
Show partial matches :set is
Highlight matching phrases :set hls
Unset options :set no<option>
Text stats (e.g: word count) g CTRL-G

External Commands

Action Command
Run External Command :!<command>
Run command and dump output :.!<command>
Command completion :!<start-of-command>Ctrl+D
Save file with sudo :w !sudo tee %

Spell Check (:set spell spelllang=en_gb)

Action Command
Navigate to the next misspelled word ]s
Navigate to the previous misspelled word [s
Alternatives to misspelled word z=
Add word to dictionary zg
Mark word as incorrect zw
comments powered by Disqus

Older · View Archive (17)

How to say a REST-ful NO?

We had an interesting discussion at work yesterday: for a REST api, what HTTP status code to return when a resource does not exist - a 200 OK with an empty result, a 204 NO CONTENT or a 404 NOT FOUND ?


Postgres - Grouping data by date

Easy ways to group counts of data by days, weeks, months or years.