My Vim Cheat Sheet
replace current file with new file: :e path/to/file
undo: u
redo: ctrl r
increment/decrement number: CTRL A, CTRL X
change case: ~
change case of full word: viw~
join two lines: J
fix line indent: ==
indent/unindent block (vis m): >/</5<
open new line after/before current: o/O
replace the char that the cursor is over: r
rb will change the current char to a bcut:
Ccecc || Sscopy:
y$yyywbyev0paste
pPdeleting
D or $dd0ddctrl+wdawcawdw4dd3xci{ci(commenting
ctrl+v (visual block mode)Shift+i (capital I)#escvVctrl+voSome operator-motion commands are used so often that they have been given a single letter command:
x stands for dl (delete character under the cursor)
X stands for dh (delete character left of the cursor)
D stands for d$ (delete to end of the line)
C stands for c$ (change to end of the line)
s stands for cl (change one character)
S stands for cc (change a whole line)
/foo
nN5n:%s/find this str/replacewiththis/g
:%s/find this str/replacewiththis/gc:%s/find this str/replacewiththis/gi:56,59s/foo/bar/g* || #\c anywhere in pattern\C anywhere in pattern$A0^Ictrl-fctrl-b:222HML{ && }wWb/eB/Egg/G'.g;fx
{, [ or (: %vim, :E or :Exploreiecho "let g:netrw_liststyle=3" >> ~/.vimrcd%DRov:tabe path/to/file:tabn:tabp:tabfir || :tabfirst:tablastZZ || :wq (they do the same)vim -p path/to/first/file path/to/another:ls:arga foo.txt bar.txt, :arga /foo/bar/*.txt:sp path/to/file:vs path/to/filectrl-wwauto completion
ctrl+nline numbers
:set number, :set nu:set nonumber, set nonuecho "set number" >> ~/.vimrcecho "set relativenumber" >> ~/.vimrctab length: set tabstop=4
see/view the path of the current open file:
:f or ctrl+g% will print the current file name: :!echo "current file: %"echo "set statusline += %F" >> ~/.vimrcback to previous buffer: ctrl+o
chaining commands together: use | as a seperator ie. to write a file then go
into tree view you'd use: :w|E
defining functions in .vimrc:
function func()
:command1
:command2
endfunction
to use this command: exec func()
vim http://google.com/:earlier 15mset list