Essential Vim Commands

December 1, 2024

  1. Do you think you're cool?
  2. Do you use Vim?

If your answers to these questions differ, then you're mistaken!

Jokes aside, here are some super cool Vim commands that I can't live without:

Change surrounding chars

'hello' -> "world"

When the cursor is within the word:

  • Command:
    c s ' "

Add surrounding chars

hello -> " hello "

When the cursor is within the word:

  • Command:
    y s i w "

{ hello } -> `{ hello }`

When the cursor is within the word:

  • Command:
    y s a { `
    or
    y s a } `

Replace Text Globally

hello -> world

  • Command:
    %s/hello/world/g
    • without % every occurrences in current line change
    • with /gc tag at the end, the user gets prompted on every occurrence to accept or deny the substitution

Switch back and forth between positions / files

file0.ts <-> file1.ts

  • Command:
    ctrl O
    O for older position
  • Command:
    ctrl I

Final Boss: Macro

Recommended Video

This is how you record a macro and then use it:

  • Command:
    q w
    (w or any other button you want to save your macro to) + do some stuff
  • q
    again to save the macro
  • now you can replay it by pressing
    @ W