Vim

Vim Tips #

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. Here are some general tips and commands organized by mode.

Normal Mode #

Normal mode is the default mode where you navigate and manipulate text.

  • dd: Quick delete line. Deletes the current line and copies it to the clipboard.
  • gg=G: Quick format document. gg goes to the top of the file, = formats the code, and G tells it to format until the end of the file.
  • u: Undo. Undoes the last change.
  • Ctrl + r: Redo. Redoes the last undone change.
  • yy: Yank (copy) line. Copies the current line.
  • p: Paste. Pastes the copied or deleted text after the cursor.
  • /pattern: Search. Searches forward for the given pattern. Press n for next match, N for previous.
  • 0 or ^: Start of line. Moves the cursor to the beginning of the current line.
  • $: End of line. Moves the cursor to the end of the current line.

Insert Mode #

Insert mode is where you actually type text into the file.

  • i: Insert. Enters insert mode before the cursor.
  • I: Insert at start. Enters insert mode at the beginning of the line.
  • a: Append. Enters insert mode after the cursor.
  • A: Append at end. Enters insert mode at the end of the line.
  • o: Open new line below. Opens a new line below the current one and enters insert mode.
  • O: Open new line above. Opens a new line above the current one and enters insert mode.
  • Esc or Ctrl + c: Exit insert mode. Returns to Normal mode.

Terminal Mode #

Terminal mode allows you to interact with a shell session from within Vim.

  • :term: Open terminal. Opens a terminal buffer in a new window split.
  • Ctrl + w, N: Exit terminal mode. Switches the terminal buffer back to Normal mode (useful for copying text from terminal output).
  • i or a: Re-enter terminal mode. If you are in Normal mode within a terminal buffer, press i or a to start typing in the shell again.
  • Ctrl + w, w: Switch windows. Moves the cursor to the next window (e.g., to go back to your code from the terminal).