Last active
February 18, 2026 05:25
-
-
Save orette/b9f990aea0f21baf08b4 to your computer and use it in GitHub Desktop.
vi Cheat Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Cursor Movment | |
| h - move left | |
| j - move down | |
| k - move up | |
| l - move right | |
| w - jump by start of words (punctuation considered words) | |
| W - jump by words (spaces separate words) | |
| e - jump to end of words (punctuation considered words) | |
| E - jump to end of words (no punctuation) | |
| b - jump backward by words (punctuation considered words) | |
| B - jump backward by words (no punctuation) | |
| 0 - (zero) start of line | |
| ^ - first non-blank character of line | |
| $ - end of line | |
| G - Go To command (prefix with number - 5G goes to line 5) | |
| Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Editing | |
| r - replace a single character (does not use insert mode) | |
| J - join line below to the current one | |
| cc - change (replace) an entire line | |
| cw - change (replace) to the end of word | |
| c$ - change (replace) to the end of line | |
| s - delete character at cursor and subsitute text | |
| S - delete line at cursor and substitute text (same as cc) | |
| xp - transpose two letters (delete and paste, technically) | |
| u - undo | |
| . - repeat last command | |
| Deleting Text | |
| <Del> or x - Delete [count] characters under and after the cursor | |
| X - Delete [count] characters before the cursor | |
| d{motion} - Delete text that {motion} moves over | |
| dd - Delete [count] lines | |
| D - Delete the characters under the cursor until the end of the line | |
| {Visual}x or {Visual}d - Delete the highlighted text (for {Visual} see Selecting Text). | |
| {Visual}CTRL-H or {Visual} - When in Select mode: Delete the highlighted text | |
| {Visual}X or {Visual}D - Delete the highlighted lines | |
| :[range]d[elete] - Delete [range] lines (default: current line) | |
| :[range]d[elete] {count} - Delete {count} lines, starting with [range] | |
| Changing (or Replacing) Text | |
| r{char} - replace the character under the cursor with {char}. | |
| R - Enter Insert mode, replacing characters rather than inserting | |
| ~ - Switch case of the character under the cursor and move the cursor to the right. If a [count] is given, do that many characters. | |
| ~{motion} - Switch case of {motion} text. | |
| {Visual}~ - Switch case of highlighted text | |
| Editing a File | |
| :e[dit] - Edit the current file. This is useful to re-edit the current file, when it has been changed outside of Vim. | |
| :e[dit]! - Edit the current file always. Discard any changes to the current buffer. This is useful if you want to start all over again. | |
| :e[dit] {file} - Edit {file}. | |
| :e[dit]! {file} - Edit {file} always. Discard any changes to the current buffer. | |
| gf - Edit the file whose name is under or after the cursor. Mnemonic: "goto file". | |
| Inserting a file | |
| :r[ead] [name] - the file [name] below the cursor. | |
| :r[ead] !{cmd} - Execute {cmd} and insert its standard output below the cursor. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Exiting | |
| :q - quit (fails if anything has changed) | |
| :q! - quit and throw away changes | |
| :cq - quit always, without writing | |
| :wq - Write the current file and exit. | |
| :wq! - Write the current file and exit always. | |
| :wq {file} - Write to {file}. Exit if not editing the last | |
| :wq! {file} - Write to {file} and exit always. | |
| :[range]wq[!] [file] - Same as above, but only write the lines in [range]. | |
| ZZ - Write current file, if modified, and exit. | |
| ZQ - Quit current file and exit (same as ":q!"). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Insert Mode - Inserting/Appending text | |
| i - start insert mode at cursor | |
| I - insert at the beginning of the line | |
| a - append after the cursor | |
| A - append at the end of the line | |
| o - open (append) blank line below current line (no need to press return) | |
| O - open blank line above current line | |
| ea - append at end of word | |
| gI - Insert text in column 1 [count] times. | |
| Esc - exit insert mode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Marking text (visual mode) | |
| v - start visual mode, mark lines, then do command (such as y-yank) | |
| V - start Linewise visual mode | |
| o - move to other end of marked area | |
| Ctrl+v - start visual block mode | |
| O - move to Other corner of block | |
| aw - mark a word | |
| ab - a () block (with braces) | |
| aB - a {} block (with brackets) | |
| ib - inner () block | |
| iB - inner {} block | |
| Esc - exit visual mode | |
| Visual commands | |
| > - shift right | |
| < - shift left | |
| y - yank (copy) marked text | |
| d - delete marked text | |
| ~ - switch case |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Cut and Paste | |
| yy - yank (copy) a line | |
| 2yy - yank 2 lines | |
| yw - yank word | |
| y$ - yank to end of line | |
| p - put (paste) the clipboard after cursor | |
| P - put (paste) before cursor | |
| dd - delete (cut) a line | |
| dw - delete (cut) the current word | |
| x - delete (cut) current character | |
| Search/Replace | |
| /pattern - search for pattern | |
| ?pattern - search backward for pattern | |
| n - repeat search in same direction | |
| N - repeat search in opposite direction | |
| :%s/old/new/g - replace all old with new throughout file | |
| :%s/old/new/gc - replace all old with new throughout file with confirmations | |
| Working with multiple files | |
| :e filename - Edit a file in a new buffer | |
| :bnext (or :bn) - go to next buffer | |
| :bprev (of :bp) - go to previous buffer | |
| :bd - delete a buffer (close a file) | |
| :sp filename - Open a file in a new buffer and split window | |
| ctrl+ws - Split windows | |
| ctrl+ww - switch between windows | |
| ctrl+wq - Quit a window | |
| ctrl+wv - Split windows vertically |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :[range]s[ubstitute]/{pattern}/{string}/[c][e][g][p][r][i][I] [count] - For each line in [range] replace a match of {pattern} with {string}. | |
| :[range]s[ubstitute] [c][e][g][r][i][I] [count] :[range]&[c][e][g][r][i][I] [count] - Repeat last :substitute with same search pattern and substitute string, but without the same flags. You may add extra flags | |
| The arguments that you can use for the substitute commands: | |
| [c] Confirm each substitution. Vim positions the cursor on the matching | |
| string. You can type: | |
| 'y' to substitute this match | |
| 'n' to skip this match | |
| to skip this match | |
| 'a' to substitute this and all remaining matches {not in Vi} | |
| 'q' to quit substituting {not in Vi} | |
| CTRL-E to scroll the screen up {not in Vi} | |
| CTRL-Y to scroll the screen down {not in Vi}. | |
| [e] When the search pattern fails, do not issue an error message and, in | |
| particular, continue in maps as if no error occurred. | |
| [g] Replace all occurrences in the line. Without this argument, | |
| replacement occurs only for the first occurrence in each line. | |
| [i] Ignore case for the pattern. | |
| [I] Don't ignore case for the pattern. | |
| [p] Print the line containing the last substitute. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment