# [Vim](https://www.vim.org/) Cheatsheet Johnny Miller, Sun Oct 2 13:58:53 CST 2022 [**Vim**](https://en.wikipedia.org/wiki/Vim_(text_editor)) ([/vɪm/](https://en.wikipedia.org/wiki/Help:IPA/English); a contraction of ***Vi IMproved***) is a [free and open-source](https://en.wikipedia.org/wiki/Free_and_open-source), [screen-based text editor](https://en.wikipedia.org/wiki/Screen-based_text_editor) program. It is an improved clone of [Bill Joy](https://en.wikipedia.org/wiki/Bill_Joy)'s [vi](https://en.wikipedia.org/wiki/Vi). > 📖 References > > - [Vim help files](https://vimhelp.org/) > - [Vim cheatsheet](https://devhints.io/vim) > - [Great Practical Ideas for Computer Scientists vim cheat sheet](https://www.cs.cmu.edu/~15131/f17/topics/vim/vim-cheatsheet.pdf) > - [A Great Vim Cheat Sheet](https://vimsheet.com/) > - [Vim Cheat Sheet](https://vim.rtorr.com/) **Table of Contents** [TOC] ## 📚 Glossary - Operators let you operate in a range of text (defined by *motion*). These are performed in normal mode. See more: [Motions and operators](https://vimhelp.org/motion.txt.html#operator) - Text objects let you operate (with an *operator*) in or around text blocks (*objects*). ## 🧭 Navigation | Keystroke(s) | Description | Note | | --------------- | ---------------------------------- | ----------- | | `h` `j` `k` `l` | Arrow keys (⬅️ ⬇️ ⬆️ ➡️) | | | `b` / `w` | Previous/next word | | | `ge` / `e` | Previous/next end of word | | | `0` *(zero)* | Start of line | | | `^` | Start of line *(after whitespace)* | | | `$` | End of line | | | `gg` | First line | | | `G` | Last line | | | `:n` | Go to line `n` | | | `nG` | Go to line `n` | | | `zz` | Center this line in editor window | | | `zt` | Top this line in editor window | | | `zb` | Bottom this line | | | `H` | Move to top of screen | | | `M` | Move to middle of screen | | | `L` | Move to bottom of screen | | | `/pattern` | Search for pattern | | | `?pattern` | Search backward for pattern | | | `n` | Next matching search pattern | | | `N` | Previous match | | | `gd` | Go to definition | JetBrains | | `{` / `}` | Jump to previous/next paragraph | Visual mode | ## 📝 Editing | Keystroke(s) | Description | Note | | --------------- | ------------------------------------------------------------ | --------------------------------------------------- | | `a` | Append | | | `A` | Append from end of line | | | `i` | Insert | | | `o` / `O` | Next line Add blank line below/above current line | | | `J` | Join next line of text with current line | JetBrains plugin: `ideajoin` | | `s` | Delete char and insert | | | `S` | Delete line and insert | | | `C` | Delete until end of line and insert | | | `cc` | Delete whole line and insert | | | `dd` | Delete line *(Cut)* | The deleted texts will be copied in Vim’s clipboard | | `2dd` | Delete 2 linen *(Cut)* | | | `dw` | Delete to next word | | | `db` | Delete to beginning of word | | | `ciw` | Change (replace) entire word. (Delete current word that pointed by cursor) | | | `cw` / `ce` | Change (replace) to the end of the word. | | | `u` | Undo changes | | | `` | Redo changes | `` = `ctrl + r` | | `Esc` / `` | Exit insert mode | `` = `ctrl + [` | | `` | Exit insert mode (corrupt), and abort current command | `` = `ctrl + c` | | `<` / `>` | Indent right/left | Visual mode. Operators | | `=` | Autoindent | | ## 📋 Clipboard | Keystroke(s) | Description | Note | | ------------- | --------------------------------- | ------------------------------------------------------- | | `x` | Delete character *(Cut)* | The deleted character will be copied in Vim’s clipboard | | `dd` | Delete line *(Cut)* | Copy in Vim’s clipboard | | `yy` | Yank line *(Copy)* | Copy in Vim’s clipboard | | `p` | Paste from Vim’s clipboard | | | `P` | Paste before from Vim’s clipboard | | | `"*p` / `"+p` | Paste from system clipboard | | | `"*y` / `"+y` | Paste to system clipboard | | ## 👀 Mode Switching | Keystroke(s) | Description | Note | | --------------- | -------------------------------------------------------- | -------------------- | | `v` | Enter visual mode | | | `V` | Enter visual line mode | | | `` | Enter visual block mode | | | `a` | Enter insert node and append text after where cursor is | | | `i` | Enter insert node and insert text before where cursor is | | | `Esc` / `` | Exit insert mode | `` = `ctrl + [` | ## 💬 Text Objects Text objects let you operate (with an *operator*) in or around text blocks (*objects*). | `v` | `i` | `p` | | -------- | -------------------- | ----------- | | Operator | [i]nside or [a]round | Text object | | Keystroke(s) | Description | Note | | ------------ | ------------------------------------------------------- | ---- | | `vip` | Select paragraph | | | `yip` | Yank inner paragraph | | | `ciw` | Change (replace) entire word | | | `ggvG` | Select all text. (Go to top, visual mode, go to bottom) | | ## 🏷 Marks | Keystroke(s) | Description | Note | | -------------------- | ------------------------------------------------------------ | ---- | | `m{a-z}` | Set mark {a-z} at cursor position | | | `m{A-Z}` | A capital mark {A-Z} sets a global mark and will work between files | | | ``{a-zA-Z}` | Move cursor to the position where the mark was set | | | `'{a-zA-Z}` | Move cursor to the start of the line where the mark was set | | | `''` | Go back to the previous jump location | | | `:marks` | List marks | | | `:delmarks {a-zA-Z}` | Delete specific marks | | | `:delm abc` | Delete marks a, b and c | | | `:delm!` | Delete all marks but not marks A-Z | |