Cheatsheet

Movement

  • h, j, k, l: Move cursor left, down, up, right
  • w, b: Jump forwards / backwards single word
  • W, B: Jump forwards / backwards single ‘word’ (black separated)
  • 0, $: Jump to the start / end of the line
  • ^: Jump to the first non-blank character of the line
  • %: Jump to matching character (e.g., (), {}, [])
  • gg, G: Jump to the beginning / end of the file
  • f_, F_: Jump to next / previous occurrence of _
  • t_, T_: Jump to after next / previous occurrence of _
  • ;: Repeat last jump
  • }, {: Jump to next / previous paragraph
  • zz: Centre cursor on screen
  • <C-e>, <C-y>: Move screen down / up one line, without moving cursor
  • <C-b>, <C-f>: Move screen down / up one page, moving cursor to the last / first line
  • <C-d>, <C-u>: Move screen down / up half page

Insert / Edit

  • i, a: Insert mode before / after the cursor
  • I, A: Insert mode at the beginning / end of the line
  • o, O: Insert a new line below / above the current line and enter insert mode
  • r: Replace a single character.
  • R: Replace character until pressing ESC.
  • J, gJ: Join the line below to the current one, with / without single space inbetween
  • cc (= S): Replace entire line
  • u, C-r: Undo / Redo
  • .: Repeat last command

Visual

  • v: Start visual mode
  • V: Start linewise visual mode
  • o: Move to the other end of the marked area
  • a_, i_: Around / Inside _
    • e.g., aw: Around word, i(: Inside ()
  • y: Yank marked text
  • d: Cut marked text
  • ~: Switch case
  • u, U: Change to lowercase / uppercase
  • >, <: Shift text right / left
  • <C-a>, <C-x>: Increment / decrement by [count] the number or alphabetic character in the highlighted text
  • g<C-a>, g<C-x>: Same as <C-a> / <C-x> but if several lines are highlighted, each will be incremented / decremented by an additional [count]
  • :set wrap: Wrap text around terminal

Macros / Registers

  • @_: Run macro in register _
    • @@: Rerun last macro run
  • :reg: Show registers content
  • "_y, "_p: Yank to / paste from register _
  • "+y, "+p: Yank to / paste from system clipboard register
  • q_: Record macro to register _
  • q: Stop recording

Search / Replace

  • /_, ?_: Search forwards / backwards for pattern _
  • n, N: Next / previous in search results
  • :[range]s/{pattern}/{string}/[flags] [count]: For each line in [range] replace a match of {pattern} with {string}
    • Flags
      • c: Confirm each substitution
      • e: When the search pattern fails, do not issue an error message and continue in maps as if no error occurred
      • g: Replace all occurrences in the line
      • i, I: Ignore / do not ignore case for the pattern
      • n: Report the number of matches, do not actually substitute
  • <C-q>: Add search results to quickfix list (e.g., after telescope search)
    • :cdo {command}: Runs a command on each line in the quickfix list
    • :cfdo {command}: Runs a command on each file in the quickfix list

Buffer

  • :enew: Open new empty buffer
  • :bd: Close current buffer
    • :bd {BUFNO}: Close a specific buffer with number {BUFNO}
    • :bd!: Force close buffer without saving
    • :bufdo bd: Close all buffers except the current one
    • :bufdo bd!: Close all buffers except the current one without saving

Noice

  • :Noice: View notifications history
  • :Noice telescope: View notifications history in Telescope