To get started with Vim, first read Basic Text Editing with Vim

Advanced Text Editing with Vim

Wherever this text says gvim you can also read mvim.

Subjects in this page

dot dot dot...

One of the most powerful features of Vim is the . command, also known as the dot command.

The key ., when entered in command mode, will repeat the last performed action.

Example: add a line and then multiply it by 5 is easy. Let's add a line: A <ENTER>This is a line ESC
Now repeat that action 4 times so we end up with 5 identical lines 4 .

Another approach for this specific case would be to put the number first and then what you want to do, e.g. for creating a line with 60 asterisks: 60 A * ESC will give you

Moving around with confidence

Mark a line as a : m a, then move to another line in the file and jump back to line a: ' a

Mark a line as b : m b
Go up a couple of lines and type d ' b to delete up to line b or y ' b yank up to line b, then put the deleted or yanked lines somewhere else in the file: p

Window splitting


gvim -p file [file...]  open all files in one window,
  where each file gets its own tab

gvim -o file [file...]  open all files in multiple split-windows

Advanced search and replace

^ - start of line
$ - end of line


The % is a shortcut that tells vi to search all lines of the file for search_string and change it to replacement_string.

The global (g) flag at

the end of the command tells vi to continue searching for other occurrences of search_string.

To confirm each replacement, add the confirm (c) flag after the global flag

Press * to display all words matching the word under the cursor. Jump to next word using 'n' and backwards using 'N'.

Press [I to display all lines that contain the keyword under the cursor.

Dope for programmers

(({Matching {brackets}} and (parentheses)))

Matching brackets { } and parentheses ( ) is quite easy with these two techniques that Vim offers:

What goes for brackets applies to parentheses as well, so this functionality is great for C, C++, Java and a gift from the gods for Scheme.

Indenting level

Make sure these two lines are in your .vimrc:
vnoremap < <gv
vnoremap > >gv
then you can select a piece of code and use > to move it to the right and < to move it to the left


Try what happens when you do this: ! G sort and be ready to UNDO with u
I'll explain later...

Regular expressions

replace multiple spaces by single space:  %s/ \+/=/g
remove everything from @ to end of line: %s/@.*//g

remove whitespace at start of line
:%s/^[ ]\+//g

remove whitespace at end of line
:%s/[ ]\+$//g

Convert M$ Windows style line-ends (CRLF) to UNIX-style (LF):
replace ^M by newline: %s/^M/\r/\r/g

VIM folding

Folding task lists in Vim