NVIM Cheat Sheet

Here’s a cheat sheet for using Neovim (nvim), a modern and extensible text editor:

Modes

  • Normal Mode:
    • Default mode for navigating and manipulating text.
    • Press Esc to enter Normal Mode.
  • Insert Mode:
    • Mode for inserting and editing text.
    • Press i in Normal Mode to enter Insert Mode.
  • Visual Mode:
    • Used for selecting and manipulating text.
    • Press v in Normal Mode to enter Visual Mode.
  • Command-Line Mode:
    • Mode for entering commands.
    • Press : in Normal Mode to enter Command-Line Mode.

Navigation

  • Basic Movement:
    • h: Move left
    • j: Move down
    • k: Move up
    • l: Move right
  • Word Movement:
    • w: Move to the beginning of the next word
    • b: Move to the beginning of the previous word
    • e: Move to the end of the current word
  • Line Movement:
    • 0: Move to the beginning of the line
    • ^: Move to the first non-blank character of the line
    • $: Move to the end of the line
  • Page Movement:
    • Ctrl + u: Move half a page up
    • Ctrl + d: Move half a page down
    • Ctrl + b: Move one page up
    • Ctrl + f: Move one page down
    • gg: Move to the beginning of the file
    • G: Move to the end of the file
    • :<line-number>: Move to a specific line

Editing

  • Inserting Text:
    • i: Insert before the cursor
    • I: Insert at the beginning of the line
    • a: Insert after the cursor
    • A: Insert at the end of the line
    • o: Open a new line below
    • O: Open a new line above
  • Deleting Text:
    • x: Delete the character under the cursor
    • dd: Delete the current line
    • dw: Delete from the cursor to the next word
    • D: Delete from the cursor to the end of the line
  • Copying and Pasting:
    • yy: Copy the current line
    • yw: Copy from the cursor to the end of the current word
    • p: Paste after the cursor
    • P: Paste before the cursor

Visual Mode

  • Selecting Text:
    • v: Enter Visual Mode
    • V: Enter Visual Line Mode
    • Ctrl + v: Enter Visual Block Mode
  • Indentation:
    • >: Indent selected lines
    • <: Unindent selected lines

Saving and Quitting

  • Saving:
    • :w: Save changes
  • Quitting:
    • :q: Quit (close the current window)
    • :q!: Quit without saving changes
    • :wq or :x: Save and quit
    • ZZ: Save and quit
  • Multiple Files:
    • :e <file>: Open a new file
    • :ls: List open buffers
    • :b <buffer>: Switch to a specific buffer
    • :bd: Close the current buffer

Search and Replace

  • Searching:
    • /: Enter search mode
    • n: Move to the next search result
    • N: Move to the previous search result
  • Replace:
    • :s/old/new/g: Replace all occurrences of “old” with “new” in the current line
    • :%s/old/new/g: Replace all occurrences in the entire file

Miscellaneous

  • Undo and Redo:
    • u: Undo
    • Ctrl + r: Redo
  • Help:
    • :help: Open the help documentation

This cheat sheet covers some essential Neovim commands. Neovim is highly extensible, and there are many plugins and configurations available to enhance its functionality. For more in-depth information, refer to the official Neovim documentation.