Build awareness and adoption for your software startup with Circuit.

How to Vim Like a Pro: A How-To Guide for Maximum Productivity

Ted Naleid's wallpaper

It's time to ditch the mouse and say hello to Vim.

This powerful text editor may have a tough reputation, but with some practice, you'll be slicing through keystrokes like a pro in no time.

Grab your keyboard, and let's get started!

Note: This article assumes prior Vim knowledge. If you're new, check out Ben Awad's Vim Tutorial before diving in.

Open a file in Vim

:e filename --- edit file :tabe filename --- edit file in new tab (similar to :tabnew)

💡Tip: Use gt / gT --- switch to next/previous tab

Open file(s) in terminal

vim filename --- open a specific file vim -p filename1 filename2 filename3 --- open multiple files in different tabs

Vim's Help

To open Vim's quit documentation, type :help quit or :h quit Use :h keyword to learn about specific keywords.

💡Tip: tab key for autocompletion in command mode

Saving and Exiting

:w --- write (save) :q --- quit (close) :wq --- write-quit file (similar to *:x*) :qa --- quit-all files :wqa --- write-quit-all (similar to :xa) :q! --- force quit and discard changes

Insert Mode

i --- insert text a --- append text (insert after cursor position) I --- insert at line start (shortcut for ^i) A --- append at line end (shortcut for $a) o / O--- insert new line below/above Esc --- exit insert mode

Basic Vim Motions

h j k l --- (Arrow Keys: left, down, up, right) move the cursor one space

Arrow Keys

{count}j{count}k--- move by {count} lines down/up {count}h{count}l --- move by {count} characters left/right

For example, 5j jumps 5 lines down and 9k jumps 9 lines up.

Recover Changes

u --- undo ctrl + r --- redo

Moving around

w / b --- next/previous word e / ge --- next/previous end of word 0 / $ --- start/end of line gg / G--- start/end of file


d for delete y for yank (copy) c for change (delete and insert) v for visual select

Command pattern: {operator}{count}{motion} or {count}{operator}{motion} e.g. d5j or 5dj to delete 5 lines downwards, c2w to change 2 words

If you believe in yourself and have dedication and pride --- and never quit --- you'll be a winner. The price of victory is high, but so are the rewards.

Delete / Change

dw --- delete word dd --- delete line ddp --- swap two lines cc --- change line (similar to C and S) x --- delete (ex-out) single character r --- replace one character R --- enter replace mode s / S --- delete char/line and insert


v --- character-wise visual mode V --- line-wise visual mode C-v --- block-wise visual mode

Copy and Paste

y --- yank text yy --- yank current line :%y+ --- yank whole file p / P--- paste after/before cursor position

Moving horizontally with high precision

f --- find text forward F --- find text backward t<char> --- move to next <char> in the line T<char> --- move to previous <char> in the line

Search and replace

/pattern --- search for pattern ?pattern --- search backward for pattern n / N --- next/previous match * / #--- search next/previous word under cursor :%s/old/new/g --- replace all old with new :%s/old/new/gc --- replace old with new with confirmations :noh --- disable search match highlighting (short for :noh[lsearch]`)


> --- indent or shift right < --- unindent or shift left = --- format indentation >> --- indent more in current line << --- indent less in current line


Text Objects

{operator}{a or i}{object}

Operator: d(elete), c(hange), y(ank), v(visual)

Choose between a and i a" --- a double-quoted string i"--- inner double-quoted string

Object: word, sentence, paragraph, tag block, Parentheses (, Brackets {[<, Quotes and Ticks '"

Examples: dap --- delete a paragraph caw --- change a word yas--- yank a sentence (ending with . ! ? followed by space or tab) vat --- select a tag block

di[--- delete inner brackets [...] ci(--- change inner parentheses (...) yi< --- yank inner angle brackets <...> vi"--- select inner quoted strings "..."


qa --- start recording macro a q --- stop recording macro @a --- run macro a 7@a --- run macro a 7 times @@--- repeat last macro


. --- repeat last command % --- jump between matching () or {} ~ --- switch case (small, capital) _cf<char> --- change until next found occurrence of <char> _:read ~/path-to-file/filename --- insert a file below cursor (short *:r\*)

Continue Learning