Mastering Vim Quickly


book's website


open file at a specific line

# open file.txt at line 34
vim +34 file.txt

insert content from a file or command

" You can use :read or :r

:r file.txt  " insert file's contents below the cursor

:r!command   " insert command's output below cursor

:0r file.txt " insert before first line

save file with another name, and keep the new name

:save newFileName.txt
" from now on :w saves the buffer in newFileName.txt

the main takeaway here was

searching current word

Useful info about searching with * and #.

File Manager (netrw) in Vim


Things here didn't clicked for me... maybe I need to revisit this later

editing files via SSH

vim scp://user@myserver[:port]//path/to/file.txt

For more info: :help scp

Undo / Redo beyond the u/ctrl+r

" examples of :earlier and :later
:earlier 2d   " undo changes in last 2 days
:earlier 3h   " ... last 3 hours
:earlier 1m   " ... last 1 minute
:earlier 3f   " undo last three file states (buffer writes)

:later 5m     " redo all changes in last 5 minutes
:later 15s    " ... last 15 seconds

Undo branches

I didn't get used to these undo techniques, but I found it interesting...


  1. open a new file, write Hello. Press esc.
  2. hit o to go the line below in Insert mode, write world. Press esc
  3. hit u to undo and remove the world.
  4. hit o to go the line below in Insert mode, write everyone. Press esc
  5. hit u to undo and remove the everyone.

If you hit u again you remove the Hello, but never get the word world again.

after you complete step 4 - and you want to get back world again - you need to run command g-.

Basically, Vim creates an undo branch every time you hit u. The branch represents the state of the file before you executed undo. So you can use g- command to move backward or g+ command to move forward between these branches.

Take a few minutes to experiment with u, ctrl+r g- and g+ and you'll quickly understand how this works.

speak the Vim language

verbs -> modifiers -> nouns


Note: these commands are also known as operator commands or simply operators.


Note: i and a are used to create text-objects


See also vim text-object cheatsheet.

The nouns can be a text-object or a text-movement

search through multiple files


I think this can be improved with ripgrep or something similar. Saw some videos showing some cool features about it.

Search for a PATTERN in all markdown files:

:vimgrep PATTERN *.md

And then use:

the power of the global command

The :g[lobal] command is very useful. The syntax is like this:


examples of the global command

Use :help 10.4 for more info

# delete all lines containing a 'error'

# delete all lines not containing 'important'

# NOTE: deletion sends data to the unnamed register!
# Avoid it sending to the "blackhole" register '_'

# delete all blank lines

# execute macro '@a' in normal mode
:g/pattern/normal @a

# for every line containing "good" replace "bad" with "ugly"

# reverse all the lines - ':help 12.4'
# (':m0' moves a line to the top of the file)


There are 9 types of registers:

  1. unnamed: "
  2. numbered (10): "0 - "9
  3. small delete: "-
  4. named (26): "a - "z or "A - "Z (capital letters append contents)
  5. read-only: ":, "., "% and "#
  6. expression: "=
  7. selection and drop: "*, "+ and "~
  8. blackhole: "_
  9. last search pattern: "/

using named registers


# copy current line to "a register

# append current line to the "a register

# paste content from "a register

# get a preview of your registers


Main concepts: