My VIM command collection

In my work I often need to edit files in a terminal environment. My choice of editor in these environments is VIM. Here are a bunch of commands in command mode that I use.

Start vim

vim <filename>

Start vim with the output of another command/program

<command/program> | vim -

Show vim help


Save file

 :write #or 'w' for short

Quit vim

 :quit #or 'q' for short

Save AND quit


Force save (you can also force edit and quit by appending a exclamation ‘!’ mark)


Show line numbers

:set number

Remove line numbers

:set nonumber

Enable syntax highlighting

:syntax on

Disable syntax highlighting

:syntax off

Change colorscheme

:colorsheme <colorscheme> #E.g. desert

Enable auto indent

:set autoindent

Remove auto indent

:set noautoindent

Set tab spaces

:set ts=4 #Sets tab to 4 spaces

Always show status bar (with filename)

:set ls=2

Show special characters

:set list #Use :set nolist to turn off

Delete all lines between X and Y

:X,Yd #X and Y are linenumbers

Load new file into vim. Can also be used to refresh current file – just use ‘e’ without path or filename

:edit /tmp/myfile #or 'e' for short

Run external command. Vim let you run the command, shows the result and switches back to your Vim window again when you press Enter

:! command #E.g. ':! ls' will show the files of your current location

Go to a specific line numer


Substitute something with something else in the whole file


Search for a string in file (next search result = n)

/<search string>

Use regexp


Undo last action


Split window vertically

ctrl + wv

Split window horizontally

ctrl + ws

Create new vertical window


Move between windows

ctrl + ww

Rotate windows

ctrl + wr

Diff two outputs from standard input (from command line)

vim -d <(command1) <(command2)

Diff two files inside vim

:e file1 #Open first file
:diffthis #Add window to 'diff pool'
ctrl + wv #Open new window
ctrl + ww #Move to new window
:e file2 #Open second file 
:diffthis #Add window to 'diff pool'
:diff #Execute diff
# Extras
:set diffopt+=iwhite #To ignore whitespaces

If you want to diff two windows (and not open files) just add them to 'diff pool' and run the :diff command

Delete 5 lines
Stand on the first line you want to delete and press 5dd
Delete a whole line
Stand on the line and press: dd
Direct search of word
Stand in the word and press: *
Find matching bracket
Stand on a bracket and press: % (press % again to go back to previous bracket)
Expand all nodes in diff mode
Press: zR
Fold all nodes in diff mode
Press: za

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.