VIM commands. Part 2


Search “word” from top to bottom
Search “word” from bottom to top
Search “john” or “joan”
/\< the
Search “the”, “theatre” or “then”
Search “the” or “breathe”
/\< the\>
Search “the”
/\< ….\>
Search all words of 4 letters
Search “fred” but not “alfred” or “frederick”
Search “fred” or “joe”
Search exactly 4 digits
Find 3 empty lines
:bufdo /searchstr/
Search in all open files


Replace all occurences of “old” by “new” in file
Replace all occurences with confirmation
Replace all occurences between lines 2 and 35
Replace all occurences from line 5 to EOF
Replace the begining of each line by “hello”
Replace the end of each line by “Harry”
Replace “onward” by “forward” , case unsensitive
:%s/ *$//g
Delete all white spaces
Delete all lines containing “string”
Delete all lines containing which didn't contain “string”
Replace the first occurence of “Bill” by “Steve” in current line
Replace “Bill” by “Steve” in current line
Replace “Bill” by “Steve” in all the file
Delete DOS carriage returns (^M)
Transform DOS carriage returns in returns
Delete HTML tags but keeps text
Delete lines which appears twice
Increment number under the cursor
Decrement number under cursor
Change text to Rot13


Lowercase line
Uppercase line
Invert case
Switch word to uppercase
Modify word case
Set all text to lowercase
:set ignorecase
Ignore case in searches
:set smartcase
Ignore case in searches excepted if an uppercase letter is used
Sets first letter of each word to uppercase
Sets first letter of each word to lowercase
Sets first letter of each line to uppercase
Sets first letter of each line to lowercase

Read/Write files

:1,10 w outfile
Saves lines 1 to 10 in outfile
:1,10 w >> outfile
Appends lines 1 to 10 to outfile
:r infile
Insert the content of infile
:23r infile
Insert the content of infile under line 23

File explorer

:e .
Open integrated file explorer
Split window and open integrated file explorer
:browse e
Graphical file explorer
List buffers
:cd ..
Move to parent directory
List files
:args *.php
Open file list
:grep expression *.php
Returns a list of .php files contening expression
Open file name under cursor

Interact with Unix

Execute the “pwd” unix command, then returns to Vi
Execute the “pwd” unix command and insert output in file
Temporary returns to Unix
Retourns to Vi


Align all lines
Align all lines at the current position
Align the next 5 lines


Creates a new tab
Show next tab
Show first tab
Show last tab
:tabm n(position)
Rearrange tabs
:tabdo %s/foo/bar/g
Execute a command in all tabs
:tab ball
Puts all open files in tabs

Window spliting

:e filename
Edit filename in current window
:split filename
Split the window and open filename
ctrl-w up arrow
Puts cursor in top window
ctrl-w ctrl-w
Puts cursor in next window
Maximise current window
Gives the same size to all windows
10 ctrl-w+
Add 10 lines to current window
:vsplit file
Split window vertically
:sview file
Same as :split in readonly mode
Close current window
Close all windows, excepted current
:b 2
Open #2 in this window


Ctrl+n Ctrl+p (in insert mode)
Complete word
Ctrl+x Ctrl+l
Complete line
:set dictionary=dict
Define dict as a dictionnary
Ctrl+x Ctrl+k
Complete with dictionnary


Marks current position as k
Moves cursor to mark k
Delete all until mark k


:ab mail mail@provider.org
Define mail as abbreviation of mail@provider.org

Text indent

:set autoindent
Turn on auto-indent
:set smartindent
Turn on intelligent auto-indent
:set shiftwidth=4
Defines 4 spaces as indent size
ctrl-t, ctrl-d
Indent/un-indent in insert mode

Syntax highlighting

:syntax on
Turn on syntax highlighting
:syntax off
Turn off syntax highlighting
:set syntax=perl
Force syntax highlighting


+ Bonus:
  • rss
  • Del.icio.us
  • Digg
  • Twitter
  • StumbleUpon
  • Reddit
  • Share this on Technorati
  • Post this to Myspace
  • Share this on Blinklist
  • Submit this to DesignFloat