Personal Vim Cheat Sheet

A Software › Vim cheat sheet in English by brennanmeadowcroft
10,700 views 3,686 downloads 21 Jan 2017 History
3.7 avg · 0 ratings

Notes

Command derived from plugin
Command derived from prefer­ences
.vimrc for this cheatsheet available on Github brenna­nme­ado­wcr­oft­/do­tfiles

Global

:help <ke­ywo­rd>
Open help for a keyword
:o <fi­le>
Open file
:saveas <fi­le>
Save file as
:close
Close current pane
<n>­<co­mma­nd>
Do n of command (e.g. 5dd)
<Es­c>
Change to normal mode
<Le­ade­r> is ,

Exiting

:w
Write (save) current file but don't exit
:Q
Quit ALL buffers (fails if unsaved changes)
:q
Quit current buffer (fails if unsaved changes)
:q!
Force quit
:wq/:x
Write (save) and quit

Macros

qa
Record macro a
qq
Stop recording macro
@@
Rerun last macro
_n_@a
Run macro a _n_ times

Visual Mode


Marking Text
v
start visual mode
V
start linewise visual mode
Ctrl+v
Start visual block mode
aw
Mark a WORD
ab
Mark AROUND block of ()
aB
Mark AROUND block with {}
ib
Mark INSIDE block with ()
iB
Mark INSIDE block with {}

Visual Commands
>
Shift highli­ghted lines right
<
Shift highli­ghted lines left
y
Yank (copy) marked text
d
Delete marked text
~
Switch case of marked text

Insert Mode

A
Append to end of line
a
Start inserting after cursor
i
Start inserting before cursor

Keyword Completion
Ctrl+n
Keyword completion (e.g. variable names)
Tab
Keyword completion
Ctrl+n
Move DOWN in autoco­mplete window
Ctrl+p
Move UP in autoco­mplete window

Normal Mode - Inserting Text

i
Insert BEFORE cursor
I
Insert at beginning of line
a
Insert AFTER cursor
A
Insert at end of line
o
Insert new line BELOW current line
O
Insert new line ABOVE current line
ea
Insert at end of the word

Normal Mode - Cursor Movement

h
Move cursor left
j
Move cursor down
k
Move cursor up
l
Move cursor right
H
Move cursor to TOP of screen
M
Move cursor to MIDDLE of screen
L
Move cursor to BOTTOM of screen
w
Jump forward to START of word
e
Jump forward to END of word
^
Jump to first non-blank character of line
$
Jump to end of the line
O
Jump to start of the line
Ctrl+b
Page Up
Ctrl+f
Page Down
_n_G
Go to line _n_
gg
Go to the first line of the document
G
Go to the last line of the document
}
Jump to next paragraph (or functi­on/­block)
{
Jump to previous paragraph (or functi­on/­block)
Ctrl+y
Scroll up without moving cursor
Ctrl+e
Scroll down without moving cursor

Normal Mode - Search & Replace


Within Buffer
/_keyword_
Search buffer for _keyword_
n
Move DOWN to next instance
N
Move UP to next instance
*
Search buffer for word under cursor

Within Working Directory
<Le­ade­r>+a
Search (ack) INSIDE files in working directory
v
Open file from search (ack) in VERTICAL split
h
Open file from search (ack) in HORIZONTAL split

Replace
:%s/_old_/_new_/g
Replace all _old_ throughout file with _new_
:%s/_old_/_new_/gc
Replace _old_ with _new_ WITH CONFIR­MATIONS

Marks/­Reg­isters


Marks
:marks
List of marks
ma
Set current position for mark a
`a
Jump to position of mark a

Registers
:reg
Show registers content
"xy
yank into register x
"0p
Paste contents of register x
Unsure what these do... calling them out for research

Normal Mode - Editing

J
Join line below to current one
cc
change (replace) entire line
cw
change (replace) to end of word
c$
change (replace) to end of line
s
delete character and substitute text
xp
transpose two letters
u
undo
Ctrl+r
redo
.
Repeat last action
ci_char_
Change INSIDE _char_ (e.g. ci")
ca_char_
Change AROUND (inclu­ding) _char_ (e.g. ca")

Normal Mode - Code Folding

zc
Close a fold
zo
Open a fold
zA
Toggle all folds
za
Toggle single fold
zM
Close ALL folds in buffer

Normal Mode - Buffers

:ls
List all buffers
:bd
Close the current buffer
:bd_n_
Close _n_ buffer
:bn
Navigate to next buffer
:bp
Navigate to previous buffer
Ctrl+c
Close the current buffer
Ctrl+h
Navigate to previous buffer
Ctrl+l
Navigate to next buffer

Normal Mode - Splits

Ctrl+ws
Split current window horizo­ntally
Ctrl+wv
Split window vertically
Ctrl+wq
Quit a window

Navigating Splits
Ctrl+ww
Move to next split
Ctrl+wh
Move to split located LEFT of current
Ctrl+wl
Move to split located RIGHT of current
Ctrl+wj
Move to split located BELOW current
Ctrl+wk
Move to split located ABOVE current

Normal Mode - Cut/Paste

yy
Yank (copy) a line
yw
Yank (copy) a word
y$
Yank (copy) to end of line
p
Paste BEFORE cursor
P
Paste AFTER cursor
dd
Delete (cut) a line
dw
Delete (cut) a word
d$
Delete (cut) to end of line
x
Delete (cut) single character
Deleting is basically cutting; anything deleted will be on clipboard.

Ctrl-P

Ctrl+p
Start Ctrl-P to search for files
<en­ter>
Open file in new buffer
Ctrl+k
Navigate UP in file list
Ctrl+j
Navigate DOWN in file list
Ctrl+f
Move FORWARD in search locations (files, buffers, most recent files)
Ctrl+b
Move BACKWARD in search locations

Ack.vim

v
Open highli­ghted file in VERTICAL split
h
Open highli­ghted file in HORIZONTAL split
<en­ter>
Open highli­ghted file in new buffer
<le­ade­r>+a
Open ack.vim for searching
q
Close search results window

NerdTree

<Le­ade­r>+n
Toggle NerdTree
P
Move to ROOT of working directory
p
Move to parent folder above cursor

NerdCo­mment

<le­ade­r>+­c<s­pac­e>
Toggle comment
<le­ade­r>+cl
Line comment
<le­ade­r>+cu
Uncomment

Buffer­gator

Ctrl+c
Close the current buffer
Ctrl+h
Navigate to previous buffer
Ctrl+l
Navigate to next buffer

Vimdiff - Layout

{{fa-plug}} Vimdiff - Layout
Access vimdiff for a branch with git mergetool from bash

VimDiff - Commands

:diffget lo
Use local version
:diffget ba
Use base version
:diffget re
Use remote version
[c
Navigate to PREVIOUS conflict
]c
Navigate to NEXT conflict
It is possible to edit the code in the merged pane directly if none of the options (local, base, remote) are prefer­able.

Badges

Nice Cheat Sheet Good Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.