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 b
cut:
C
ce
cc
|| S
s
copy:
y$
yy
yw
bye
v0
paste
p
P
:set paste
will help with special charactersdeleting
D
or $d
d0
dd
ctrl+w
daw
caw
dw
diw
will delete the entire word without touching whitespace around it4dd
3x
ci{
ci(
commenting
ctrl+v
(visual block mode)Shift+i
(capital I)#
esc
v
V
ctrl+v
o
Some 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
n
N
5n
:%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:noh
$
A
0
^
I
ctrl-f
ctrl-b
:222
H
M
L
{
&& }
w
W
b
/e
B
/E
gg
/G
'.
g;
fx
{
, [
or (
: %
vim
, :E
or :Explore
i
echo "let g:netrw_liststyle=3" >> ~/.vimrc
d
%
D
R
o
v
:tabe path/to/file
:tabn
:tabp
:tabfir
|| :tabfirst
:tablast
ZZ
|| :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/file
ctrl-ww
auto completion
ctrl+n
line numbers
:set number
, :set nu
:set nonumber
, set nonu
echo "set number" >> ~/.vimrc
echo "set relativenumber" >> ~/.vimrc
tab 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" >> ~/.vimrc
back 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 15m
set list