3 min read

Another Vim Cheat Sheet

June 6, 2019

Getting started with Vim is not easy. Fueled by an entirely different ecosystem of plugins, scripts and obscure workflows it is difficult to see the advantage of using Vim. But, to watch experienced people using Vim is always impressive and makes one eager to learn it.

This cheat sheet does not intend to provide you with a list of plugins and dotfiles, but aims at giving an overview of the most common commands. I assmelbed this document while learning to vim.

In order to unsertand these command I recommend to read about the following Vim topics first:

  • leader key
  • plugins with plug
  • modes and buffers

Sections

Plugins

Plugins are managed by vim plug. My vim config including the list of plugins is available at GitHub - janikvonrotz/dotfiles.

fzf vim

Open file with fzf in new split or tab.

ctrl + t # tab split
ctrl + x # split
ctrl + v # vsplit

Search git files with key bindings.
leader + f

fugitive

Resolve merge conflicts.

# open conflicted file

# run diff command
:Gdiff

# navigate between remote and local version

# use diff put to select changes
dp

# write changes
:Gwrite

Checkout file from index.
:Gread

Show file history.
:Gblame

vim indent guides

Show indents.
leader + ig

Basics

Save current file.
:w

Override current file.
:w!

Save and quit.
:wq or ZZ

Reload current file.
:e

Quit vim.
:q

Quite all splits and tabs.
:qa

Profile

Reload vim profile.
:so $MYVIMRC or :source %

Modes

Enter visual character selection mode.
v

Enter visual line selection mode.
V

Enter insert mode. i

Enter insert mode after current character.
a

Exit mode.
ctrl + c or ESC

Open new or existing file inside vim.
:e /path/to/file

Open file browser inside vim.
:e /path/to/direcotry

Navigate with keys.

h # left
j # down
k # up
รถ # right
w # word
e # end
b # back
$ # end of line
0 # beginning of line

Navigate pages.

ctrl + u # page up
ctrl + d # page down
G # go to bottom
gg # go to top

List previous opened files.
:jumps

Open the last file.
:e#

Navigate search results.

n # next
shift + n # previous

Session

Save the current session.
:mksession

Open vim with session file.
vim -S Session.vim

Edit

Undo changes.
u

Redo changes.
ctrl + r

Copy and paste.

# cut current selection
d
# delete word
dw
# copy current selection
y
# cut the current line
dd
# copy current line
yy
# paste
p

Search and replace in file.
:%s/old/new/g

Add line below current line.
o

Tell vim to not autoindent or otherwise alter the format of your pasted text.
:set paste or :set nopaste

Move line up or down.
ddp and dd{j,k}p or :m{+,-}{i} and :m{i}

Select

Select text between character.
vi{c}

Select curren word.
vw

Window

Split window vertically.
:vs

Split window horizontally.
:sp

Switch between splits.
ctrl + w & {h,j,k,l}

Leader

Set leader key.
:let mapleader = "-"

Tabs

Open file in new tab.
:tabnew /path/to/file

Open multiple files in tabs.

:args path/to/files/*
:tab all

Navigate tabs.

gt # go to next tab
gT # go to previous tab
{i}gt # go to tab in position i

Shell

Run shell command in split pane.
:new | 0read ! command

Buffer

Reload all buffers.
:bufdo e

Sources

Learn Vimscript the Hard Way

Jesse Leite - It’s dangerous to Vim alone! Take Fzf

Thoughtbot - Vim Splits - Move Faster and More Naturally

Categories:  Unix

Tags:  vim , cheat sheet , man page

comments powered by Disqus