Skip to main content

Vim Cheetsheet

VIM Cheetsheet

For use in Vim, NeoVim or other.

search tags: neovim,nvim

Opening files

open without config

(n)vim --clean

open multiple files at once

Separate tabs:

(n)vim -p file1 file2

Separate windows horizontal split:

(n)vim -o file1 file2

Separate windows vertical split:

(n)vim -O file1 file2

ranges

:s       # current line
:%s      # entire document
:1,10s   # from line 1 to 10
:.,10    # current line to line 10
:.+1,10  # one after current line to line 10
:.-1,10  # starting one before current line to line 10
:10,$    # line 10 to end of document

Search in visual selection

<visually select something> <ESC> /\%Vsearch-term

change case (\u uppercase \L lowercase)

:%s/\v( <something> )/\L\1

search for word, not WORDlet, preWORD, or subWORDlet

/\<word\>

Count occurences of something, see :help count-items

:%s/search//n # n is a flag to not change anything

lookaround

/\v(thepattern )@<=somethingelse
#matches:  v-----------v
thepattern somethingelse
< means lookbehind (leave out if lookahead)
= means is present (use ! instead if it should not be present)

# lookahead example
/\vthepattern( bad case)@!
thepattern good case # match!
thepattern bad case # no match

Bindings

unmap / unbind / remove binding

(i/n/etc)unmap

example, unmap insert mode mapping:

iunmap fj

Movements

Redo/reverse-do f and t motions

; and , # remapped to ö and Ö

Jumping: back to location before jump

<C-o>

Jumping: back to location after jump (undo C-o):

<C-i>

Move to next/previous method

]m / [m

Undo / Change history

Undo Tree

u and C-r are not guaranteed to show you all changes you made, moving through the undo tree is. To move through the undo tree:

g-
g+

Move through edit tree

g; # further back
g, # further forward

Buffer management

Reload file

:e

Open blank files

new / vnew / tabnew

Window Management

<C-w> (for Control Windows)
    # switch split
    h,j,k,l
    # move
    H,J,K,L
    # rotate
    r (down/right), R (up/left)
    # move split to new tab
    T
    # resizing vertically
    +/-
    # resizing horizontally
    >/<

List windows (buffers):

:buffers

Edit a buffer:

:buffer <buffer #>

Open another buffer in current tab (split + buffer = sb):

:sb[uffer] <buffer #>

Folds

Save:

:mkview

Load:

:loadview

Misc commands

Digraphs / 2 keys to enter special characters

When in insert mode:

<Ctrl+k> ->
<Ctrl+k> ?I
<Ctrl+k> ss
#list all available
:dig
#add new (can't one that starts with whitespace)
:dig <key1><key2> <output in _decimal_ representation, generally utf8 (make sure to convert from hex to decimal)>

Trigger autocommand

:doautocmd <event> # <FileType tex>

count lines/words/characters/bytes

g <C-G>

Or as a function:

wordcount()
wordcount().words

Remote files

(vim | :e) scp://remoteuser@server.tld//path/to/document

sorting lines:

:help sort