Vim

Published: (December 27, 2025 at 07:57 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

1. Match all occurrences of the word under the cursor

*

2. Replace a word with another word

:%s/word/newword/gc

g – global, c – confirm

3. Visually select a word (i / a – inside / outside)

viw   " selects only the word itself
vaw   " selects the word plus surrounding whitespace
vi(   " visual text inside ()
ci"   " change inside double quotes
va(   " visual around ()
va"   " visual around double quotes

4. Show all registers

:reg

5. Paste from a specific register

"p

6. Yank (copy) the current line to the system clipboard (+ – clipboard register)

"+yy

7. Yank the current file name to the system clipboard

:let @+=@%

Assigns the contents of the % register (current file name) to the + register (system clipboard).

8. Copy the absolute path of the current file

:let @+ = expand('%:p')

9. Record and play a macro

qq   " start recording, perform actions, stop
@h   " replay macro stored in register h

10. :normal mode in Visual selections

When you select lines in Visual mode and press : you get:

:'

You can then execute normal‑mode commands on each selected line:

:'normal 

Common keys

  • I – go to the start of each line and enter Insert mode
  • A – go to the end of each line and append text

Example – prepend var to each line

hello
world
goodbye

:'normal Ivar␣

Result

var hello
var world
var goodbye

Example – append ; to each line

hello
world
goodbye

:'normal A␣;

Result

hello ;
world ;
goodbye ;

Example 1

Example 2

11. Increment / decrement numbers

  • Ctrl‑a – increment number under the cursor
  • Ctrl‑x – decrement number under the cursor
value = 2

Select all lines, press g then Ctrl‑a to increment each number:

list.get(0);
list.get(0);
list.get(0);
list.get(0);
list.get(0);
list.get(0);

After gCtrl‑a:

list.get(1);
list.get(2);
list.get(3);
list.get(4);
list.get(5);
list.get(6);

12. Switching selection direction

  • o – switch to the opposite end of the selection (forward)
  • O – switch to the opposite end of the selection (backward)

13. Word motions with w / W

  • w – move to the start of the next word (letters, digits, or underscores)
  • W – move to the start of the next whitespace‑separated word
Lis:st.get(0) hello world
Back to Blog

Related posts

Read more »

Make Vim Useful Again with VEX

VEX – The Vim Ecosystem eXtension Hey everyone! After months of tweaking, testing, and countless evenings spent in the terminal, I’m really excited to share th...