Vim for programmers

some usefull vim commands

I won’t try to demonstrate why Vim is an excellent editor. But here are some features useful when programming.

commands description
gg=G indent file
== indent line
=a{ indent block
u undo
r redo
: go line number
g go end of file
:cwin print error messages if some
:clist print compiler messages
:cn move next error
:cp move previous error
:tag go tag
] go tag (for windows $)
w] open new tab and go tag under cursor
T go back from tag
gd make search with current word under the cursor
m put a mark name under the cursor
' go the mark
:mak do make
:mak clean all do make clean all
:ls show current buffer
:b[n] go buffer number [n]
:sp split window and open
w[hjkl] move window to left, down, up or right
u go half page up
d go half page down
:diffsplit diff current buffer &
:diffupdate update diff buffers
:DirDiff diff directory ( &) see DirDiff plugin
F11 run VimCommander - see VimCommander plugin
:grep bonjour % search bonjour on current buffer (put results in error buffer)
:grepadd hello *.c search hello in all *c file
:cwin show error buffer
:cn go next entry in the error buffer
q start record
q stop current record
@ repeat record
@@ repeat previous record
:he go help for
zfap create paragraphe fold
zc close fold
zo open fold
zm make fold
zr reduce fold
zi z more or z reduce
:set foldmethod=indent fold according to the file indentation
:set foldlevel=3 fold more than third indent
:set foldcolumn=4 show a margin with folding indications
:stag ou w ] split window and go tag
:tselect /config_* show all tag references that match config_* in error buffer
:vsplit functions open buffer with the function list
:set ignorecase casse independant search
:set smartcase like ignorecase if the exression is lowercase
x completion (insert mode)
o completion (insert mode)
:tabe open file in a new tab
:tabc close current tab
:tab run in a new tab
gt go next tab
go next tab
go previous tab
:set makeprg=gmake under windows, the Gnu Collection Compiler
:map :wa:make shortcut (F9 == save all and 'make')
:map :wa:make clean all shortcut (F10 == save all and 'make clean all')
:argdo %s///ge ""|""w replace by in all buffers
:cs find s show reference in source database
:cs reset reset cscope database connexion
:cs show show cscope database connexion

-  # cscope -R
-  leave : Ctrl-D
-  launch vim
-  :cs add cscope.out
-  :cs kill 0
-  :!cscope -R
-  :cs add cscope.out
-  :cs show

example that update cscope database


hacker emblem Creative Commons License