VIM

Remove trailing whitespace


:%s/\s\+$//e

Remove blank lines


:g/^\s*$/d

Swap word with next word


nmap <silent> gw    "_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<cr><c-o><c-l>  

delete all HTML tags


:%s#<[^>]\+>##g

delete all duplicate lines


:%s/^\(.*\)\n\1$/\1/

reverse content of file


:g/^/m0

useful keymaps

xp exchange the right character with his left combatant
^ move to the first non-blank character in the current line
+ move to the first character in the next line
- move to the first character in the previous line
% move to the opposite character
( move a sentence back
) move a sentence forward
{ move a paragraph back
} move a paragraph forward
nyy yanks n lines into the buffer
/string search forward for string
?string search backward for string
n search for next instance of string
N search for previous instance of _string
zf3 fold the next 3 lines (works with VISUAL MODE too
zO open all folds at the cursor
d/string/ delete until string
* find word under cursor
~ change case
:ls list of all buffers
:bn next buffer
:bp previous buffer
:bd remove file from buffer
:b2 go to buffer 3
<C-v> enter VISUAL BLOCK mode
Vip select code block
g<C-g> count all words in document
s<p> surrounding the line with <p> </p> tags (surround plugin in visual mode)
=G apply autoformat to the end of a file in visual mode

replace pattern

:s/pattern/string/flags replace pattern with string according to flags
g Flag - replace all occurences of pattern
c Flag - confirm replaces
. any single caracter except newline
* zwro or more occurances of any character
^ beggining of the line
$ end of line
\< beginning of word
\> end of word

[ Go home ]