vim cheatsheet

[Vim](http://www.vim.org/) is a very efficient text editor. This quick reference cheat sheet was made for Vim 8.0.

#Getting started

#Visualization

▼/▶ Cursor   ▽/▷ Target
┌───────────── 0      
│  ┌────────── ^      $ ──────────────┐
│  │  ┌─────── Fo     fe ────────┐    │
│  │  │┌────── To     te ───────┐│    │
│  │  ││ ┌──── ge     w ───┐    ││    │
│  │  ││ │ ┌── b      e ─┐ │    ││    │ 
│  │  ││ │ │  ┌h      l┐ │ │    ││    │
▽  ▽  ▽▽ ▽ ▽  ▽▼      ▼▽ ▽ ▽    ▽▽    ▽
   echo "A cheatsheet from quickref.me"
                 - SCREEN 1 START
   ┌─┬─────────▷ #!/usr/bin/python
   │ │     ┌───▷     
   │ │     │     print("Hello")
   │ │     { } ▶ print("Vim")
   │ │       │   print("!")
   │ │       └─▷    
   │ │ ┌───┬───▷ print("Welcome")
G gg H M L k j ▶ print("to")
│        │   └─▷ print("quickref.me")
│        │       print("/vim")
│        │     
│        └─────▷ 
│                - SCREEN 1 END
└──────────────▷ print("SCREEN 2")

#Navigating

ShortcutDescription
hjklArrow keys
<C-U>|<C-D>Half-page up/down
<C-B>|<C-F>Page up/down

Words

ShortcutDescription
b|wPrevious/next word
ge|ePrevious/next end of word

Line

ShortcutDescription
0(zero)Start of line
^Start of line (after whitespace)
$End of line

Character

ShortcutDescription
feGo forward to character e
FoGo backward to character o

Document

ShortcutDescription
ggFirst line
GLast line
:nGo to line n
nGGo to line n

Window

ShortcutDescription
zzCenter this line
ztTop this line
zbBottom this line
HMove to top of screen
MMove to middle of screen
LMove to bottom of screen

Search

ShortcutDescription
nNext matching search pattern
NPrevious match
*Next whole word under cursor
#Previous whole word under cursor

Tab pages

ShortcutDescription
:tabedit [file]Edit file in a new tab
:tabfind [file]Open file if exists in new tab
:tabcloseClose current tab
:tabsList all tabs
:tabfirstGo to first tab
:tablastGo to last tab
:tabnGo to next tab
:tabpGo to previous tab

#Editing

ShortcutDescription
aAppend
AAppend from end of line
iInsert
oNext line
OPrevious line
sDelete char and insert
SDelete line and insert
CDelete until end of line and insert
rReplace one character
REnter Replace mode
uUndo changes
<C-R>Redo changes

#Exiting

ShortcutDescription
:qaClose all files
:qa!Close all files, abandon changes
:wSave
:wq|:xSave and close file
:qClose file
:q!Close file, abandon changes
ZZSave and quit
ZQQuit without checking changes

#Clipboard

ShortcutDescription
xDelete character
ddDelete line (Cut)
yyYank line (Copy)
pPaste
PPaste before
"*p|"+pPaste from system clipboard
"*y|"+yPaste to system clipboard

#Visual mode

ShortcutDescription
vEnter visual mode
VEnter visual line mode
<C-V>Enter visual block mode

In visual mode

ShortcutDescription
d|xDelete selection
sReplace selection
yYank selection (Copy)

#Exiting insert mode

ShortcutDescription
Esc|<C-[>Exit insert mode
<C-C>Exit insert mode, and abort current command

See Operators for other things you can do.

#Operators

#Usage

Operators let you operate in a range of text (defined by motion). These are performed in normal mode.

ShortcutDescription
dw
OperatorMotion

#Operators list

ShortcutDescription
dDelete
yYank (copy)
cChange (delete then insert)
>Indent right
<Indent left
=Autoindent
g~Swap case
gUUppercase
guLowercase
!Filter through external program

See :help operator

#Examples

Combine operators with motions to use them.

ShortcutDescription
dd(repeat the letter) Delete current line
dwDelete to next word
dbDelete to beginning of word
2ddDelete 2 lines
dipDelete a text object (inside paragraph)
(in visual mode)dDelete selection

See :help motion.txt

#Text objects

#Usage

Text objects let you operate (with an operator) in or around text blocks (objects).

ShortcutDescription
vi
Operator[i]nside or [a]round

#Text objects

ShortcutDescription
pParagraph
wWord
sSentence
[({<A [], (), or {} block
'"`A quoted string
bA block [(
BA block in [{
tA XML tag block

#Examples

ShortcutDescription
vipSelect paragraph
vipipipipSelect more
yipYank inner paragraph
yapYank paragraph (including newline)
dipDelete inner paragraph
cipChange inner paragraph

See Operators for other things you can do.

#Diff

vimdiff file1 file2 [file3]

See differences between files.

#Misc

#Folds

ShortcutDescription
zo|zOOpen
zc|zCClose
za|zAToggle
zvOpen folds for this line
zMClose all
zROpen all
zmFold more (foldlevel += 1)
zrFold less (foldlevel -= 1)
zxUpdate folds

Uppercase ones are recursive (eg, zO is open recursively).

#Navigation

ShortcutDescription
%Nearest/matching {[()]}
[([{[<Previous ( or { or <
])Next
[mPrevious method start
[MPrevious method end

#Case

ShortcutDescription
~Toggle case (Case => cASE)
gUUppercase
guLowercase
gUUUppercase current line (also gUgU)
guuLowercase current line (also gugu)

Do these in visual or normal mode.

#Counters

ShortcutDescription
<C-A>Increment number
<C-X>Decrement

#Windows

ShortcutDescription
z{height}<Cr>Resize pane to {height} lines tall

#Text alignment

:center [width]
:right [width]
:left

See :help formatting

#Calculator

ShortcutDescription
<C-R>=128/2Shows the result of the division : '64'

Do this in insert mode.

#Tags

ShortcutDescription
:tag ClassnameJump to first definition of Classname
<C-]>Jump to definition
g]See all definitions
<C-T>Go back to last tag
<C-O> <C-I>Back/forward
:tselect ClassnameFind definitions of Classname
:tjump ClassnameFind definitions of Classname (auto-select 1st)

#Exiting with an error

:cq
:cquit

Works like :qa, but throws an error. Great for aborting Git commands.

#Jumping

ShortcutDescription
<C-O>Go back to previous location
<C-I>Go forward
gfGo to file in cursor

#Marks

ShortcutDescription
`^Last position of cursor in insert mode
`.Last change in current buffer
`"Last exited current buffer
`0In last file edited
''Back to line in current buffer where jumped from
``Back to position in current buffer where jumped from
`[To beginning of previously changed or yanked text
`]To end of previously changed or yanked text
`<To beginning of last visual selection
`>To end of last visual selection
maMark this cursor position as a
:marksList all current marks
:delm aDelete mark a
:delm a-dDelete marks a, b, c, d
:delm abcDelete marks a, b, c

#Misc

ShortcutDescription
.Repeat last command
]pPaste under the current indentation level
:set ff=unixConvert Windows line endings to Unix line endings

#Command line

ShortcutDescription
<C-R><C-W>Insert current word into the command line
<C-R>"Paste from " register
<C-X><C-F>Auto-completion of path in insert mode

#Spell checking

ShortcutDescription
:set spell spelllang=en_usTurn on US English spell checking
]sMove to next misspelled word after the cursor
[sMove to previous misspelled word before the cursor
z=Suggest spellings for the word under/after the cursor
zgAdd word to spell list
zwMark word as bad/mispelling
zu / C-X (Insert Mode)Suggest words for bad word under cursor from spellfile

See :help spell

#Also see

#Also see