Skip to content
sym3tri edited this page Dec 5, 2012 · 1 revision

vim

Moving

H top of screen
M middle of screen
L bottom of screen
gg jump to beginning of file
G jump to end of file
<num>G Go To command (prefix with number - 5G goes to line 5)
w jump to beginning of word
e jump to end of word
b jump by word (backwards)
f<char> Jump to first occurrance of in the line (semicolon to repeat)
:g; move back to position of last edit (back in the changelist)
g, move to the next position of changelist
ctl-o navigate backwards in the jumplist
ctl-i navigate forward in the jumplist
:jumps view entire jumplist

zR open all code folds
zo open one fold under cursor
zO open all folds under cursor
zc close one fold under cursor
zC close all folds under cursor
za toggle a fold
zM close all code folds
zR open all code folds

z. Put line with cursor in center
zt Put line with cursor at top
zb Put line with cursor at bottom

`` Jump back to previous position

MARKS

m{a-z} Adds a temporary file mark
m{A-Z} Adds a permanent file mark
'{a-zA-Z} Jump to the specified mark
:marks Show all marks
:delmarks {a-zA-Z} Delete the specified mark
:delmarks! Delete all marks

EDITING

I insert at beginning line
A insert at end of line
:e open a file for editing
:e! Reload file from disk (revert to previous saved version)
:r file Insert file after cursor
:r !command Run command, and insert output after current line
. repeat the previous edit
u undo the previous edit
ctrl-r redo
cc change line
yy copy a line
dd cut a line
p paste after cursor
P paste before cursor
r<char> replace selection with char
s delete character at cursor and subsitute text
A append at the end of the line
o open (append) blank line below current line (no need to press return)
O open blank line above current line
v start Visual character mode
V start Visual line mode
ctl-v start Visual block mode
<Esc> exit Visual mode without making any changes
:set spell turn on spell checker
]s navigate to next spelling mistake
[s navigate to prev spelling mistake
z= replace misspelled word
zg mark a misspelled word as ok (adds to spellfile)
J Remove the between current line and next line
Ctrl+X, Ctrl+O OmniComplete auto complete

OPERATORS

~ switch case
d delete
c change
C delete from cursor to end of line
y yank (copy)
> shift right
< shift left
>> indent current line
<< un-indent current line
= auto-indent current line (in visual mode auto-indents all selected lines)

REGISTERS

"aY yank current line into register a
"_ select the black hole register
"* select system clipboard register
:registers view contents of all registers

BUFFERS

:ls list all buffers
:bn switch to next buffer
:bp switch to previous buffer
:bd! forcibly remove from buffer list discarding changes
:ctr+^ switch to last buffer

COMPLETION

TABS

WINDOWS

ctrl-w s split window horizontally (same file)
ctrl-w v split window vertically (same file)
ctrl+w < resize vertical split smaller ctrl+w > resize vertical split bigger :sp <filename> split window horizontally and open file
:vsp <filename> split window vertically and open file
:q quits current window
:only quits all but current window
ctl-w w cycle focus through all open windows
ctl-w [hjkl] cycle focus using hjkl movement keys
ctl-w = resizes all windows to equal size
ctl-w _ maximize current window horizontally
ctl-w | maximize current window vertically
ctl-w T move current window into new tab
gt go to next tab
gT go to prev tab

SEARCH

/ search forward
? search backward
n move to next occurrence of word
N move to prev occurrence of word

* search forward for word under cursor
# search backward for word under cursor

:%s/search/replace/g Replace the string "search" with "replace"
:%s/\%Vsearch/replace/g Same as above, but limited to current selection

USEFUL COMBOS

gv reselect previously selected text (after selection has been lost)
ggVG select entire file
=G auto-indent entire file
vi} auto-select everything within curly brace block
vaw select current word
/search c<insert><esc> search, change, insert, esc. continue to next hit n then .
:cd %:p:h change dir to that of current file
:source $MYVIMRC reload the vimrc file

MACROS

q{0-9a-zA-Z} Start recording macro with specified id
q Stop recording macro
@{0-9a-zA-Z} Play back specified macro

MOTIONS

:help text-objects (must enter visual mode first to see selections)

v<motion> selects everything for the motion
<cmd><motion> executes cmd for everything within the motion

i} all inner text within curly braces
i' all inner text within single quotes
iB all inner text within current block
a) all text within parens including parens
aB all text within current block including block chars
gg go to beginning of file
<num>G go to specified line num

FILE EXPLORER (default not NerdTree)

% create a new file
- go up a dir from any position
d create new dir
R rename file
D delete file/dir

USEFUL COMMANDS

:setf <language> Change language syntax highlighting to specified lanaguage
:! <shell-cmd> Execute any shell command
:g/^$/d Delete all empty lines
:w !sudo tee % save a file without write access.

FUGITIVE (git plugin)

:Gread revert the current file
:Gremove remove current file from git tracking. same as git rm % but also removes buffer
:Gblame show last commits and messages in vertical window

RESOURCES