Home

Awesome

Wizardly Tips Vim

A fast way to benefit from vim's power. Ideally you should read a good book and the :h section. But if you're in a hurry this should serve you well. This is a list of somewhat unknown but highly useful Vim tips and tricks. I try and keeep the list succint by not showing well known or less useful commands.

More guides that I wrote

simple-awk - A simple but practical guide to awk. <br> useful-sed - Useful sed tips, techniques & tricks for daily usage <br> quick-grep - Quick grep reference and tutorial.

HOW TO READ SHORTCUTS:

<Esc> - Escape. Usually you should press the key, not type it. When you see ii<Esc> you type ii and then Escape, not 'ii<Esc>` literally.

<C-g> - means Ctrl+G

g<C-g> - means press g then press Ctrl+g

<S-g> - means press SHift+g

<C-Z> - means Ctrl+Shift+Z (Shift is not shown but implied since we have an uppercase Z)

<zZ> - z followed by Shift+Z

<C-m><CR> - type Ctrl+M followed by Enter. <CR> is Carriage Return (another word for Enter key)

Find files and send them to vim.

find ~ -size +10M | vim -

Encrypt

Macros

Open files in own tab/win

Info

Enter special chars

Quickly write buffer to disk

Sort

Paste register

Insert mode navig

Autocomplete

How to quit Vim

Repeat Insert

On the fly computations

History of past searches

Useful selection of g commands

Paste word under cursor

Create and use abbreviation.

iab sep #-----------------------------------------------<CR>

now in Insert mode type sep and press Tab. Your long separator is inserted. By using :iab you only create abbreviations for Insert mode and keep the other modes clean.

List words under cursor.

Pattern searching tricks

Use expression register to store and iterate

Save and load your sessions.

Go back in history.

Go back to the line you last edited

Terminal inside vim

Persistent undo

set undodir=~/.vim/undo-dir
set undofile

Load the previous command

Append your registers.

Range shortcut

Visual Block Syntax

I'm a long line, very vory long, YEAH.
Shory.
I'm a long line, very vory long, YEAH.

Quickly run an external command

Replace with confirmation

Documentation at your fingertips

Input/output with external commands.

  1. :!date - execute date command and print the results
  2. :r !date - execute date command and append the output after range last line. If no range provided use current line. Thus the results from date will be appended after the current line in our case.
  3. :w !date - send all the lines as stdin to date command. Print the results (no insertion into current buffer)
  4. :1,3!date send lines 1 to 3 as stdin to date command. Replace the lines in range (1,3) with output from date.

Put each word on a new line

Buffer delete

Autocomplete with files/lines

Repeat your insert

Better wrap

hello wo
rld of v
im
hello 
world of 
vim

Indent in Insert mode

Smart folding

Increment numbers

Copy a protected file and edit it immediately.

Comment a whole file (or a portion)

Keep temp commands in registers

#bla bla
-1,+1norm i#

Open extra files with terminal commands like find

:args `find /var/log -size +1M -name '*.py' \|\| true`

(OR)

:args `find /var/log -size +1M -name '*.py' \| xargs -n1`

Format with care

patterns

Quickly edit and reload your .vimrc