vim Intermediate

You know the basics. Let's level up with visual mode, registers, and workflows that make vim powerful.

Visual Mode

Select text visually, then act on it.

Terminal
$v
character-wise selection
$V
line-wise selection
$Ctrl+v
block selection (columns)

Select and Act

  1. Enter visual mode (v, V, or Ctrl+v)
  2. Move cursor to expand selection
  3. Act on selection: d delete, y yank, > indent
Terminal
$V
(line select mode)
$5j
(select 5 more lines down)
$d
(delete all selected)

Block Selection (Powerful!)

Select a column of text:

Terminal
$Ctrl+v
(block mode)
$3j
(select down 3 lines)
$I
(insert at selection)
$#
(type prefix)
$Esc
(applies to all lines!)

This adds # to the beginning of 4 lines. Comment multiple lines instantly.

Text Objects

Act on logical units of text:

Terminal
$diw
delete inner word
$daw
delete a word (with space)
$di"
delete inside quotes
$da"
delete quotes and contents
$di(
delete inside parentheses
$dip
delete inner paragraph

i = inner (just content), a = around (content + delimiters)

Game Changer

ci" (change inside quotes) puts you in insert mode with the quoted text deleted. Perfect for editing strings.

The Dot Command

. repeats your last change. This is huge.

Terminal
$dw
(delete word)
$.
(delete next word)
$.
(delete next word)
$.
(delete next word)

Or:

Terminal
$/TODO
(find TODO)
$ciwFIXME
(change to FIXME)
$Esc
$n
(next TODO)
$.
(change to FIXME again)

Registers

vim has multiple clipboards called registers:

Terminal
$"ayy
yank line into register a
$"ap
paste from register a
$"byy
yank into register b
$:reg
(show all registers)

Useful registers:

  • " - default register
  • 0 - last yank
  • + - system clipboard
Terminal
$"+y
(yank to system clipboard)
$"+p
(paste from system clipboard)

Marks

Bookmark positions in files:

ma      " set mark 'a' at cursor
'a      " jump to mark 'a'
:marks  " show all marks

Lowercase marks are per-file. Uppercase marks work across files.

Multiple Files

Buffers

Terminal
$:e file2.txt
(open another file)
$:ls
(list open buffers)
$:b2
(switch to buffer 2)
$:bn
(next buffer)
$:bp
(previous buffer)

Split Windows

Terminal
$:split file.txt
(horizontal split)
$:vsplit file.txt
(vertical split)
$Ctrl+w w
(switch between splits)
$Ctrl+w q
(close split)

Macros

Record and replay keystrokes:

Terminal
$qa
(start recording into register a)
$0i# Esc j
(go to start, insert #, next line)
$q
(stop recording)
$@a
(replay macro a)
$10@a
(replay 10 times)

Macros Are Powerful

Record once, apply hundreds of times. Great for repetitive edits across many lines.

Knowledge Check

What does ci (change inside quotes) do in vim?

Quick Reference

CommandAction
v/V/Ctrl+vVisual modes
diw/dawDelete word
ci"/ci(Change inside quotes/parens
.Repeat last change
"ay/"apRegister operations
ma / apostrophe-aSet/jump to mark
:split/:vsplitSplit window
qa..q/@aRecord/play macro

Key Takeaways

  • Visual mode lets you select before acting
  • Ctrl+v block select is amazing for columns
  • Text objects (diw, ci") are efficient
  • . repeats your last change
  • Registers give you multiple clipboards
  • Macros automate repetitive edits

Next: choosing the right editor for you.