Vim Cheat Sheet (rtorr.com)

Philosophy

Think in three layers:

Neovim
├── Buffers  (opened files)
├── Windows  (splits)
└── Tabs     (workspaces)

Remember:

  • Buffer = file
  • Window = viewport
  • Tab = layout/workspace

Files are Buffers, not Tabs.


Opening Files

:e file.go

Open another file

:e another.go

Buffers

List

:ls
:buffers

Next

:bn

Previous

:bp

Jump

:b 3
:b filename

Delete current buffer

:bd

Delete all except current

:%bd|e#

Windows (Splits)

Horizontal

:sp

Vertical

:vsp

Move between splits

Ctrl-w h
Ctrl-w j
Ctrl-w k
Ctrl-w l

Close split

Ctrl-w c

Keep only current split

Ctrl-w o

Equal size

Ctrl-w =

Resize

Ctrl-w +
Ctrl-w -
Ctrl-w >
Ctrl-w <

Tabs

New

:tabnew

Open file in new tab

:tabe file.go

Next

gt

Previous

gT

Go to tab N

3gt

Close

:tabclose

List

:tabs

Useful Navigation

Jump back

Ctrl-o

Jump forward

Ctrl-i

Previous file

Ctrl-^

Current file path

Ctrl-g

Searching

/pattern

Next

n

Previous

N

Word under cursor

*
#

End of word

$
/patern$

Whole word

/\<word\>

Replace

# replace w/o confirm
:%s/old/new/g
# replace with confirm
:%s/old/new/gc
# case insensitive
:%s/old/new/gi
# g: global, replace in every line

Info

\n: new line when search, null character (^@) when replace
\r: carriage return (rare), new line when replace


Copy / Delete / Change

yy
dd
cc # change the current line, delete the line, and enter insert mode

yw
dw
cw

y$
d$
c$

p
P

u
Ctrl-r

Visual Mode

Character

v

Line

V

Block

Ctrl-v

Indent

>
<

Indentation

>>
<<

=
==
gg=G

Marks

Set

ma

Jump

'a

Return to last position

''

Macros

Start recording

qa

Stop

q

Run

@a

Repeat

@@

Registers


Frequently Used

:w
:q
:wq
:x
:q!
ZZ

My Workflow

Most of the time:

  • One tab
  • Multiple buffers
  • Occasionally two splits

Example:

Tab 1
 ├── main.go
 ├── person.go
 ├── calculator.go

Use buffers to switch files.

Create a second tab only when working on another context (README, Git conflict, notes, etc.).


Future Plugins

When installed:

  • fzf → file/buffer searching
  • Telescope (Neovim)
  • Treesitter
  • LSP
  • Git integration
  • Which-key
  • Oil / mini.files