Tip 1 :
Use markers to set a place where you want to go back quickly or to delete some block of codema - mark current position as 'a' [ can use a-z in same file, or can use A-Z between files]
'a - go to mark a
d'a - delete current position to mark a [ can use 'p' after this to paste that block ]
Tip 2:
Do you want to reverse the entire file or a block ?? its easy. Try the following command:g/^/m0 [ Reverse file ]
:'a, 'bg/^/m'b [ Reverse a section a to b ]
Tip 3:
Want to delete all empty lines from a file, here you go:g/^\s*$/d
Tip 4:
Display all lines which matches the pattern:g/<pattern>/
:g/<pattern>/# [ display all line with line numbers (in vi) ]
Tip 5:
Finding some successive lines
:/^\n\{3} [ find 3 successive empty lines ]:/\(^str.*\n\)\{2} [ find 2 successive line starting with str ]
:%s/^\n\{3}// [ delete block of 3 empty line ]
:%s/^\(.*\)\n\1$/\1/ [ delete duplicate lines ]
:%s/^\(.*\)\(\n\1\)\+$/\1/ [ delete multiple duplicate line ]
:%s/\v(.*\n){5}/&\r [ insert a blank line every 5 lines (can write a string also after & )]Tip 6:
changing the caseguu or Vu [ lower case line ]
gUU or VU [ uppercase line ]
vEu [ lower case word ]
vEU [ upper case word ]
g~~ [ flip case ]
guG [ lower case entire file (go to line 1 and execute the command) ]
gUG [ upper case entire file (go to line 1 and execute the command) ]
Tip 7:
gf [ Go to file name under curser ]gd [ Go to declaration of local variable under cursor ]
gD [ Go to declaration of global variable under cursor ]
Tip 8:
*In ESC mode
viB [ Select a block - selecting entire function definition { } ] - useful when indenting a function(viB and = )
ci" [ Edit content within " " ] - useful when replacing string
ci' [ Edit content within ' ' ]