Skip to content

Instantly share code, notes, and snippets.

@danielkraic
Last active January 17, 2017 11:43
Show Gist options
  • Save danielkraic/9a5f15292f5a2feba3a23dc947323c63 to your computer and use it in GitHub Desktop.
Save danielkraic/9a5f15292f5a2feba3a23dc947323c63 to your computer and use it in GitHub Desktop.
# vim
:set number
:syn on
~/.vimrc: https://github.com/danielkraic/dotfiles/blob/master/vimrc
## files
vim file
vim +10 file
:e file
:new file
:buffers
:ls
:next
:previous
:b 1
:b 3
vim -p file1 file2
:tabedit file
gt next tab
gT previous tab
vim -o file1 file2
vim -O file1 file2
:split file
:vsplit file
CtrlW Up/Down/Left/Right
CtrlW +/-
vim -R file # read-only
view file
:set ro
vim -d file1 file2
vimdiff file1 file2
dp put changes from current window to other window
do get changes from other window
]c jump to next change
[c jump to previous change
CtrlW Left/Right
CtrlW CtrlW
## quit
:q
:q!
:qa
:wq
:wqa
ZZ (same as :wq)
ZQ (same as :q!)
## move
hjkl
0 first char of lin
^ first non-blank char of line
$ end of line
w W words forward
e E forward to end of word
b B words backward
() sentences
{} paragraphs
Ctrl+f page down
Ctrl+d half page down
Ctrl+u half page up
f{char} find to right
F{char} find to left
t{char} till to right
T{char} till to left
; repeat last fFtT to right
, repeat last fFtT to left
:10 jump to line 10
+ 10+
- 10-
gg first line
G last line
H L M
z. zt zb
## search
* search word under cursor
/ search forward
? search backward
n next
N previous
## edit
a A append. append to end
i I insert, insert before start
o O begin new line below, begin new line above
r replace char
x delete char
X delete previous char
p paste
P paste before
xp
s
c cc C change
d dd D delete
y yy yank
~ switch case
CtrlA increment numbe
J join line below
v visual - select range
v visual - select lines
V visual mode linevise
ESC exit visual mode
d delete
c change
y yank
< shift left
> shift right
## fold
:fold
:zo open
:zc clone
## completion
ctrl n
ctrl p
Cctrl n l
## substitution
%s/Nemam/Mam/gc
10,20s/Nemam/Mam/gc
:[range]s/pattern/{string/gci
g globally - replace all occurrences
c confirm each substitution
i ignore case
# sort
:%sort
:10,20sort
:%sort u # unique
:%sort n # numeric
:%sort! # revers
## undo/redo/repeat
u undo
CtrlR redo
. repeat last change
## marks
m{a-z} set mark
'{a-z} move to mark
'' go to previous jump
## registers
:reg
"0p
yy
dd
"0p
"ayy
dd
"ap
v
"ay
"ap
## external commands
! ls -l
! wc %
! php5 -l %
:r file
:r ! date
:r ! who | sort
## plugins
CtrlP
vim-fugitive
nerdtree
ack.vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment