Cheatography
https://cheatography.com
Some useful Vim commands. Commands I sometimes need but often forget.
Copy/Paste
yiw |
yank (inner) word |
viwp |
replace word with yanked |
viw"0p |
replace another word with yanked |
ctrl-r + |
paste from OS paste board |
Moving
H / M / L |
move to top/middle/bottom of screen |
ctrl-d/u |
move half screen down/up |
Indenting
ctrl-t/d |
Indent current line forward/back in insert mode |
</> |
Indent block in visual mode (repeat with .) |
:set shiftwidth=4 |
Set indent to 4 |
:set tabstop=8 |
Set tab to 8 |
:set (no)expandtab |
Convert (spaces)tabs |
:set pastetoggle |
change to paste mode |
:set expandtab + set ts=4 + :%retab! |
Convert tabs to four spaces in entire file |
:set noexpandtab + set ts=4 + :%retab! |
Convert spaces to tabs in entire file |
Folding
zM/zR |
fold/unfold buffer |
zc/zo |
fold/unfold paragraph |
zC/zO |
fold/unfold all levels in paragraph |
:set foldmethod=indent |
fold by indentation |
:set foldmethod=syntax |
fold by syntax |
|
|
Windows
n Ctrl-<> |
dec/inc window width by n |
n Ctrl-+/- |
inc/dec window height by n |
Ctrl-W= |
make windows equal size |
Ctrl-w s/v |
split window horizontally/vertically |
Ctrl-w c |
close window |
Ctrl-w w |
move to next window |
Ctrl-w hjkl |
move to hjkl window |
Sessions
:mksession <file> |
Save session |
:source <file> or vim -S <file> |
Open session |
vim --remote |
Open file in existing window |
vim --sessionname <name> |
Create new session <name> |
vim --servername <name> |
Open file in existing session <name> |
Ctags / cscope
ctrl-] |
jump to definition |
ctrl-w } |
show preview |
Marks
ma |
set local mark a |
mA |
set global mark A |
'a |
jump to line with mark a |
`a |
jump to position with mark a |
|
|
Commands
:%!command |
filter buffer through command |
:w !sudo tee % |
save file even if write protected |
:%s//<bar>/g |
replace every occurence of last search term with <bar> |
:%s/<c-rw>/<foo>/g |
replace every occurence under cursor with <foo> |
:g/pattern/d |
delete lines containing pattern |
:v/pattern/d |
delete lines not containing pattern |
:n,m ! cmd |
filter lines n to m through shell cmd |
:new|r ! cmd |
run cmd, put output to new window |
:set wrap linebreak nolist |
set soft wrap |
:set list |
show spaces, tabs, newlines |
:nohlsearch |
clear search highlights |
:%!nl -ba |
Add line numbers (different from :set number) |
My mappings
,cc |
comment code |
,co |
uncomment code |
,c / ,v |
copy/paste from persistent buffer |
,a |
Search for pattern with ack-grep |
,A |
Search word under cursor with ack-grep |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets