Move
- h j k l
- Move to file begingg
- Move to file endG
- Move to line 3:3
Copy & Paste
- Copyy
- Cutd
- Pastep
Search & Replace
- Search/Apple
- Search by word/\<Apple\>
- Search ignorecase/Apple\c
- Replace in lines:1,10s/Apple/Banana
- Replace in a file:%s/Apple/Banana/g
- Count items:%s/Apple/&/gn
- Search in filesvimgrep /Apple/ *.txt
grep -R . --include='*.cxx' -i -e 'Apple' (You can open the quickfix list by :copen)
Align several lines
- Go to first line and enter Visual Mode by CRTL-v
- Move to the last line and select the lines by SHIFT-v
- Align the lines to have 4 spaces in the left by entering :'<,'>left 4
(You may need enable ":set expandtab" to insert tab by spaces.)
Undo & Redo
- Undou
- RedoCTRL-r
New Window & Split Window
- New window:new
- Switch between windowsCTRL-w CTRL-w
CTRL-w h (or j, k, l)
- Split horizontal windowCTRL-w s
- Split vertical windowCTRL-w v
- Close a window:q
- Close other windowsCTRL-w o
Display
- Display line number
:set number
- Set tab stop:set tabstop=4
- Insert space to tab:set expandtab (reversely, :set noexpandtab)
- Highlight cursor line and column:set cursorline
:set cursorcolumn
- Folding with marker:set foldenable
:set foldmethod=marker
:set foldmarker={{{,}}}
(Then you can wrap the sections with {{{ and }}} to create folders and sub-folders. You can add comments after {{{ to add the folder comment)
Close a folder by zc
Open a folder by zo
Tag
- Generate tag filectags --extra=+q -R .
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
- Install taglist (http://vim-taglist.sourceforge.net/installation.html)
- Show tag list:Tlist
- Go to a tag:ta class::member
:ta class.member
:ta /disp*
CTRL-] (go to tag)
CTRL-T (go back)
- Set Multiple Tag files:set tags:=~/a/tags;~/b/tags
:set tags+=/my/path/to/tags
- Set Tag Files Recursively:set tags=./tags;/.
Cscope
- Generate cscope filefind . -name '*.hxx' -print > cscope.files
find . -name '*.cxx' -print >> cscope.files
cscope -b
- Find functions calling this function:cs find c foo
- Find a function definition and show the result in a newly splitted window:scs find g foo
- Show cscope file (up to 8):cs show
- Add a cscope file:cs add yourfile
- Add the line to your ~/.vimrc to map "cscope find e" to Ctrl-\nmap <C-\> :cs find e <C-R>=expand("<cword>")<CR><CR>
Word Completion
- C-x C-n