vim command
Created:
Updated:
Here I summarized vim commands that are used frequently for development.
-
How to move cursor to the location in history
command Description CTRL + o move to cursor to previous location in history CTRL + I move to cursor to next location in history
- How to use system’s clipboard
- "* and “+ registers are for the system’s clipboard
- ex) “+yy, “+3yy, “+p, “*p
- http://vim.wikia.com/wiki/Copy,_cut_and_paste
- "* and “+ registers are for the system’s clipboard
- How to use vim registers
- ex) “ayy, “ap, :reg
- bookmark
- in one file : m+[a~z]
- move to bookmark : ‘ + [a~z]
- in multiple files : m+[A~Z]
- move to bookmark : ‘+[A~Z]
- http://vim.wikia.com/wiki/Using_marks
- How to search for “a or b” in the current file. ‘\c’ means ignore case.
1
:vimgrep /\ca\|b/ <CTRL-R><SHIFT-%>
- How to search two words(“a” and “b”) in either order in the current file. ‘\c’ means ignore case.
1
:vimgrep /\c.*a\&.*b/ <CTRL-R><SHIFT-%>
- reference
- https://vim.fandom.com/wiki/Search_patterns
- reference
- How to show each buffer in a tab on gvim.
1
:tab ball
- How to switch between tabs on gvim.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
In normal mode gt //next tab gT //Previous tab 3gt //go to 3rd tab In command mode :tabfirst> :tabnext :tabprev :tablast :tabnext :tabm :tabclose :tabnew
- how to show trailing whitespace.(assuming you use :set hlsearch)
1
:/\s\+$
- $ matches the end of a line or string.
- \s matches whitespace character.
- + matches the preceding pattern element one or more times.
- how to delete any trailing whitespace at the end of each line.
1
:%s/\s\+$//g
- reference
- https://vim.fandom.com/wiki/Remove_unwanted_spaces
- reference
- how to delete ^M in a file(^M is Ctrl + v + m)
1 2 3
:set ffs=unix :e! // reload :%s/^M//g // ^M = ctrl + v + m
- how to delete ^M for multiple files(^M is Ctrl + v + m)
1
$ find ./ -iname * -exec dos2unix {} \;
- how to delete trailing whitespaces for multiple files
1
$ find . -type f -name '*.txt' -exec sed --in-place 's/[[:space:]]\+$//' {} \;
- how to compare 2 directories in vim
1
:DirDiff folder_1 folder_2
- how to compare 2 directory lists with vimdiff
1
$ vimdiff <(cd android-4.0.1_r1; find . | sort) <(cd android-4.0.2_r1; find . | sort)
Leave a comment