VIM

Despite the learning curve, the goal is to save milliseconds of time for each action. Before, my typical way to write a GitHub issue was editing its body and title on a web browser only after hundreds of milliseconds of HTTP requests. I want to finish the content, then submit, and while it is being uploaded, I move on to the next task. Minimize the time between creativity and documentation.

Configuration

Set VIM as default editor

Run gh config set editor vim to set VIM as the default editor for GitHub CLI.

Enable line numbers

Type :set number and press Enter. To make this permanent, add set number to ~/.vimrc.

Editing modes

Insert mode
  • i: Insert before the cursor

  • a: Insert after the cursor

  • I: Insert at the beginning of the line

  • A: Insert at the end of the line

  • o: Insert a new line below and enter insert mode

  • O: Insert a new line above and enter insert mode

Visual mode
  • v: Enter character-wise visual mode

  • V: Enter line-wise visual mode

  • ctrl-v: Enter block-wise visual mode

Deleting text

Character deletion
  • x: Delete the character under the cursor

  • X: Delete the character before the cursor

  • <number>x: Delete multiple characters (e.g., 3x deletes 3 characters)

  • dh: Delete one character to the left

  • dl: Delete one character to the right

  • 3dh: Delete 3 characters to the left

  • 5dl: Delete 5 characters to the right

Word deletion
  • dw: Delete from the cursor to the start of the next word

  • de: Delete from the cursor to the end of the current word

  • db: Delete from the cursor to the start of the previous word

  • dW, dE, dB: Same as above, but skip punctuation marks

  • df<char>: Delete from the cursor to the next <char>

  • dt<char>: Delete from the cursor to just before the next <char>

Line deletion
  • dd: Delete the entire current line

  • D: Delete from the cursor to the end of the line

  • dj: Delete the current line and the line below

  • dk: Delete the current line and the line above

Changing text

Replace and change
  • r<char>: Replace the character under the cursor with <char>

  • cw: Change from the cursor to the start of the next word (enters insert mode)

  • cc: Change the entire line (enters insert mode)

  • C: Change from the cursor to the end of the line (enters insert mode)

Copy and paste

Copying (yanking)
  • yy: Copy the current line

  • y: Copy selected text in visual mode

  • yw: Copy from the cursor to the start of the next word

Pasting
  • p: Paste after the cursor or below the current line

  • P: Paste before the cursor or above the current line

Undo and redo

  • u: Undo the last change

  • <number>u: Undo multiple changes (e.g., 3u undoes the last 3 changes)

  • ctrl-r: Redo the last undone change

Advanced operations

Search
  • /pattern: Search forward for pattern

  • ?pattern: Search backward for pattern

  • n: Jump to next search result

  • N: Jump to previous search result

Repeat command
  • .: Repeat the last change command

Join lines
  • J: Join the current line with the line below (removes line break)

Indent
  • >>: Indent the current line to the right

  • <<: Indent the current line to the left

  • ==: Auto-indent the current line

  • In visual mode, use > or < to indent selected lines

Case change
  • ~: Toggle case of the character under the cursor

  • gU: Change selected text to uppercase (in visual mode)

  • gu: Change selected text to lowercase (in visual mode)

Screen positioning
  • zt: Move current line to top of screen

  • zb: Move current line to bottom of screen

Marks
  • m<char>: Set a mark at the current position (e.g., ma sets mark ‘a’)

  • '<char>: Jump to the line of mark (e.g., 'a jumps to mark ‘a’)

  • `` <char>`: Jump to the exact position of mark

Swap lines

Type :m+1 to move the current line down one position.

Search and replace
  • :%s/old/new/g: Replace all occurrences of “old” with “new” in the file

  • :s/old/new/g: Replace all occurrences on the current line

  • :%s/old/new/gc: Replace all with confirmation

Saving and exiting

  • :w: Save the file

  • :w <filename>: Save as a new filename

  • :q: Quit (only if no unsaved changes)

  • :q!: Quit without saving

  • :wq or :x: Save and quit

  • ZZ: Save and quit (shortcut)

  • ZQ: Quit without saving (shortcut)