Learning Philosophy

There is no super method to learn vim but just deliberate practice and repetition. Remember by usage instead of memorization, so it is necessary to integrate it into normal coding workflow.

Suggestions from a vim user since 2000s:

  1. Make it your primary note taker, diary and IDE
  2. It’s all about muscle memory - the key bindings
  3. Stick on 1&2 for about a month and you will be a champ
  4. Read the Man and :h while stuck (after internet search); it may be overwhelming but pays well

Basic Commands

  • Use A to append text in normal mode → it quickly jumps to the end of the line and changes mode to insert, so we are free to write anything
  • Delete characters with x
  • Visual line navigation: j and k navigate visual lines rather than logical ones

Quick Comment Multiple Lines

  1. Press v to enter visual mode
  2. Go down to the end of the part you want to comment
  3. Press Shift + I, which puts you in insert mode, then press #
  4. Press Esc

Effect

Macros and Incrementing Numbers

Recording and Using Macros

Macros are incredibly useful for repetitive tasks. Here’s how they work:

Recording a macro:

  1. Press qw to start recording a macro in the w register
  2. Perform the actions you want to repeat
  3. Press q to stop recording

Playing back a macro:

  • @w - repeat the macro once
  • 10@w - repeat the macro 10 times
  • @@ - repeat the last played macro

Example use case: If you need to paste text at the beginning of multiple lines:

  1. Yank the text you want to paste
  2. Record macro: qw → j0P → q
  3. Play it: 10@w to repeat 10 times

Incrementing Numbers

When working with sequences of numbers, you can use visual block mode:

  1. Select numbers in a column using Ctrl-V
  2. Press g Ctrl-A to increment all numbers sequentially
  3. Ctrl-A increments, Ctrl-X decrements
  4. The g prefix makes each line increment by an increasing amount (0, 1, 2, 3…)

This is perfect for creating numbered lists or IDs!

Reference: Macros and Incrementing Numbers in Vim | Josh Morony

Vim in Obsidian

See Vim - In Obsidian.

Resources