# Vim Cheatsheet This is a quick reference guide for common Vim commands. Vim has several modes: Normal (default), Insert, Visual, and Command-line. ## Modes - **Normal Mode**: Default mode for navigation and commands (press `Esc` to return). - **Insert Mode**: For typing text (enter with `i`, `a`, etc.). - **Visual Mode**: For selecting text (enter with `v`, `V`, or `Ctrl-v`). - **Command Mode**: For extended commands (enter with `:` from Normal mode). ## Basic Navigation (Normal Mode) - `h` / `j` / `k` / `l`: Move left/down/up/right. - `w` / `b`: Jump to next/previous word. - `0` / `$`: Start/end of line. - `gg` / `G`: Top/bottom of file. - `Ctrl-f` / `Ctrl-b`: Page down/up. - `{number}G`: Go to line {number}. ## Editing Commands (Normal Mode) - `i`: Insert before cursor. - `a`: Append after cursor. - `o` / `O`: New line below/above. - `x`: Delete character under cursor. - `dd`: Delete current line. - `yy`: Yank (copy) current line. - `p` / `P`: Paste after/before cursor. - `u`: Undo last change. - `Ctrl-r`: Redo. - `.`: Repeat last command. ## Visual Mode - `v`: Start visual selection (character-wise). - `V`: Start visual selection (line-wise). - `Ctrl-v`: Start visual block selection. - Use navigation to select, then apply commands like `d` (delete), `y` (yank). ## Saving and Quitting (Command Mode) - `:w`: Save file. - `:q`: Quit (if no changes or saved). - `:wq` or `ZZ`: Save and quit. - `:q!`: Quit without saving. - `:wqa`: Save and quit all. ## Search and Replace - `/pattern`: Search forward for pattern. - `?pattern`: Search backward. - `n` / `N`: Next/previous match. - `:%s/old/new/g`: Replace all occurrences of 'old' with 'new' in file. - `:s/old/new/`: Replace in current line. ## Other Useful Commands - `:set number`: Show line numbers. - `:set nonumber`: Hide line numbers. - `:help {topic}`: Open help for topic. - `Ctrl-w v` / `Ctrl-w s`: Split window vertically/horizontally. - `Ctrl-w w`: Switch between windows. ## Tips - Use counts: e.g., `5dd` deletes 5 lines. - Combine motions: e.g., `dw` deletes to end of word. - Record macros: `q{letter}` to start, `q` to stop, `@{letter}` to replay. - Vim is highly customizable via `.vimrc`. ## Advanced Commands - `:e filename`: Open a file - `:bd`: Close current buffer - `:sp` / `:vsp`: Split horizontal / vertical - `Ctrl + ]` : Jump to tag (with ctags) - `q:` : Open command history - `:%s/old/new/gc` : Replace with confirmation ## Plugins and Extensions - Popular plugins: NERDTree for file exploration, vim-fugitive for Git integration. - Install with Vim-plug or Pathogen. Sources: Based on https://devhints.io/vim and other web resources. For more, type `:help` in Vim!