Advanced Vim Cheatsheet
Show All
Hide All
Cursor Movement
- h - move cursor left one character
- j - move cursor down one line
- k - move cursor up one line
- l - move cursor right one character
- w - jump forwards to the start of a word
- W - jump forwards to the start of a WORD (WORD break = whitespace)
- e - jump forwards to the end of a word
- E - jump forwards to the end of a WORD (WORD break = whitespace)
- b - jump backwards to the start of a word
- B - jump backwards to the start of a WORD (WORD break = whitespace)
- 0 - jump to the start of the line
- ^ - jump to the first non-blank character of the line
- $ - jump to the end of the line
- G - go to the last line of the document
- 5G - go to line 5
- gg - go to line 1
- `` - jump to previous cursor position
- g; - jump to last edit made
- fx - jump to next occurrence of character x
- Fx - jump to previous occurrence of character x
- tx - jump to character before thenext occurrence of character x
- Tx - jump to character before the previous occurrence of character x
- ; - Repeat latest f, t, F or T search.
- , - Repeat latest f, t, F or T search in other direction.
- } - Jump to next paragraph (or function/block, when editing code)
- { - Jump to previous paragraph (or function/block, when editing code)
- % - Jump to match of the current brace, bracket, parenthesis, comment
Cut and Paste
- yy - yank (copy) a line
- 2yy - yank (copy) 2 lines
- yw - yank (copy) word
- y$ - yank (copy) to end of line
- y^ - yank (copy) to start of line
- p - put (paste) the clipboard after cursor
- 3p - put (paste) the clipboard after cursor 3 times
- P - put (paste) before cursor
- dd - delete (cut) a line
- 2dd - delete (cut) 2 lines
- dw - delete (cut) word
- D - delete (cut) to the end of the line
- x - delete (cut) character
- xp - cut and paste a letter
Search and Replace
- /pattern - search for pattern
- ?pattern - search backward for pattern
- \vpattern - 'very magic' pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed)
- 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 called 'filename' in a new buffer
- :ls - list open buffers
- :b2 - go to buffer 2 in list of open buffers
- :bn - go to the next buffer
- :bp - go to the previous buffer
- :bd - delete a buffer (close a file)
- :sp filename - open a file in a new buffer and split window
- :vsp filename - open a file in a new buffer and vertically split window
- :hide - hide window
- :only - only this window stays open
- Ctrl + ww - switch windows
Exiting
- :w - write (save) the file, but don't exit
- :wq or :x or ZZ - write (save) and quit
- :q - quit (fails if there are unsaved changes)
- :q! or ZQ - quit and throw away unsaved changes
Insert Text
- i - insert before the cursor
- I - insert at the beginning of the line
- a - insert (append) after the cursor
- A - insert (append) at the end of the line
- o - append (open) a new line below the current line
- O - append (open) a new line above the current line
- Esc - exit insert mode
Editing
- r - replace a single character
- J - join line below to the current one
- cw - change (replace) to the end of the word
- cc - change (replace) entire line
- C - change (replace) to the end of the line
- ci" - change (replace) text within " quotes (also works for ', <, (, {, etc)
- s - delete character and substitute text
- u - undo
- Ctrl + r - redo
- . - repeat last command
Visual Selection
- v - start visual mode, mark lines, then do a command (like 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 ()
- aB - a block with {}
- ib - inner block with ()
- iB - inner block with {}
- Esc - exit visual mode
Editing Visual Selection
- > - shift text right
- < - shift text left
- :le 5 - text becomes indented 5 spaces
- y - yank (copy) marked text
- d - delete marked text
- ~ - switch case
Tabs
- :tabe filename - edit a file called 'filename' in a new tab
- gt or :tabn - move to the next tab
- gT or :tabp - move to the previous tab
- #gt - move to tab number #
- :tabmove # - move current tab to the #th position (indexed from 0)
- :tabc - close the current tab and all its windows
- :tabo - close all tabs except for the current one
Marks
- mx - create mark 'x'
- `x - jump to mark 'x'
- d`x - delete up to mark 'x'
- :delm x - delete mark 'x'
- :delm q-x - delete marks 'q' through 'x'
VIM Cheatsheet: A Handy Reference
This VIM cheatsheet is a concise and handy reference guide that provides a quick overview of the most frequently used commands and shortcuts in the VIM editor.
VIM is a powerful and feature-rich text editor with a vast array of commands and options. Remembering all of them can be challenging, especially for beginners or occasional users.
This VIM cheatsheet serves as a valuable resource, enabling users to:
- Efficiently learn and familiarize themselves with essential VIM commands.
- Quickly look up specific commands or shortcuts they need.
- Improve productivity by executing tasks swiftly and accurately.
- Speed up the editing process by utilizing lesser-known but powerful features.
- Customize their VIM experience by leveraging advanced commands and settings.
Whether you are a beginner or an experienced VIM user, having a cheatsheet readily available can enhance your workflow, save time, and help you make the most out of the VIM editor.
VIM Editor
VIM is a highly versatile text editor designed for efficient editing of plain text files. It stands for "Vi IMproved" and is an enhanced version of the traditional Unix text editor, vi.
VIM offers a wide range of features and capabilities, including syntax highlighting, code folding, search and replace functionality, macros, and support for various programming languages.
With its modal editing approach, VIM allows users to switch between different modes for editing, navigating, and executing commands, providing a powerful and efficient editing experience.
History of VIM Editor
- 1976: The original vi editor was created by Bill Joy as the visual mode for the ex editor in the BSD Unix operating system.
- 1988: Bram Moolenaar started developing VIM (Vi IMproved) as an extended version of the vi editor for the Amiga computer system.
- 1991: VIM was ported to various platforms, including Unix, MS-DOS, and Microsoft Windows.
- 1998: VIM 5.0 was released, introducing significant improvements such as syntax highlighting and multi-level undo.
- 2006: VIM 7.0 was released, adding features like spell-checking, file tabs, and support for scripting in languages like Python and Ruby.
- 2016: VIM 8.0 was released, bringing several enhancements, including asynchronous I/O support, a built-in terminal emulator, and better Unicode handling.
- 2020: VIM celebrated its 30th anniversary since Bram Moolenaar's initial development.
Common VIM Editor Commands
The VIM editor provides a rich set of commands for efficient text editing. Here are some commonly used commands:
Command | Description |
---|---|
i |
Switch to insert mode to start inserting text at the cursor position. |
yy |
Copy the current line into the clipboard. |
p |
Paste the contents of the clipboard below the cursor. |
dd |
Delete the current line. |
/search_term |
Search for search_term in the file. |
u |
Undo the last action. |
Ctrl + r |
Redo the previously undone action. |
:w |
Save the changes made to the file. |
:q |
Quit the editor. |
:wq |
Save the changes and exit the editor. |