Download VIM Cheat Sheet PDF to Enhance Productivity [Updated]

Posted in

Download VIM Cheat Sheet PDF to Enhance Productivity [Updated]
akhil

Akhil Bhadwal
Last updated on November 21, 2024

    Vim is a powerful code editor. It offers a galore of features. However, it is not that appealing without configuring it beforehand. Therefore, in this Vim cheat sheet, we will share some tricks to make Vim more productive, along with some of the most commonly used Vim commands and options that will ease your working with it. Vim is one of the most popular options when it comes to quickly add or reviewing code. It is one of the oldest surviving code editors used by web developers and designers. Before proceeding with the Vim cheat sheet, let’s know a little more about this popular code editor.

    What is Vim?

    Vim is among the most popular code editors . The name is a contraction for Vi improved. Vi was a screen-oriented text editor created specifically for Unix systems. It is an open-source text editor and clone program mainly for Unix. Nonetheless, Vim is also available for Android, iOS, macOS, and Windows NT. It offers both a graphical user interface and a command-line interface for facilitating coding.

    Vim Cheat Sheet PDF

    Let’s start this comprehensive Vim cheat sheet with the basic commands that you’ll be requiring.

    Basic Vim Cheat Sheet Commands and Options

    1. Clipboard

    Clipboard makes it easier to work with Vim. Following are some of the basic clipboard commands in Vim:

    • dd - Deletes the line.
    • p - Pastes after the cursor.
    • P - Pastes before the cursor.
    • x - Deletes the current character.
    • X - Deletes the previous character.
    • yy - Yanks a line.

    Note : Yank is a Vim-specific term for copy.

    2. Cursor Movement

    The following commands will help you to move the cursor directly from the keyboard in the Vim code editor:

    • b - Jumps backward to the beginning of a word.
    • e - Jumps forward to the end of a word.
    • ge - Jumps backward to the end of a word.
    • h - Moves the cursor to the left side.
    • j - Moves the cursor to the lower direction.
    • k - Moves the cursor to the upper direction.
    • l - Moves the cursor to the right side.
    • w - Jumps forward to the beginning of a word.
    • 0 - Jumps to the starting of a line.
    • $ - Jumps to the end of a line.
    • ^ - Jumps to the first non-blank character of the line.

    3. How to Exit in VIM

    These commands will help you save files and quit Vim:

    • :w - Saves the file.
    • :wq - Saves the file and quits.
    • :q - Quits but fails if anything has changed.
    • :q! - Quits and throws away changes.

    4. General

    • u - Undo
    • Ctrl+r - Redo

    5. Operators

    These are the common operators used in the Vim text editor:

    • c - Deletes from the cursor to the movement location and then starts the insert mode.
    • d - Deletes from the cursor to the movement location.
    • y - Yanks from the cursor to the movement location.
    • > - Indents one level.
    • < - Unindents one level.

    Note : Operators work in the visual mode too. Moreover, it is possible to combine operators and motions. For example, d$ deletes from the cursor to the end of the line.

    6. Search and Replace

    The following Vim commands make it easier to search and/or replace code or text in Vim:

    • /pattern - Searches for a pattern.
    • ?pattern - Searches backward for a pattern.
    • n - Repeats search in the same direction.
    • N - Repeats search in the opposite direction.
    • :%s/old/new/g - Replaces all old text with new text throughout the file.
    • :%s/old/new/gc - Replaces all old text with new text throughout the file with confirmations.

    7. Text Editing

    The following Vim commands will help you ease out the process of editing code or text:

    • a - Inserts after the cursor.
    • A - Inserts at the ending of the line.
    • c - Replaces to the end of the line.
    • cc - Replaces the line.
    • d - Deletes the marked text.
    • dd - Deletes the complete line.
    • Esc/Ctrl+[ - Exits the insert mode.
    • i - Inserts before the cursor.
    • I - Inserts at the starting of the line.
    • o - Appends a new line below the current line.
    • O - Appends a new line above the current line.

    8. Text Marking (Visual Mode)

    These are the common Vim commands for marking the text:

    • Ctrl+v - Starts the visual block mode.
    • Esc/Ctrl+[ - Exits the visual mode.
    • v - Starts the visual mode
    • V - Starts the linewise visual mode.

    Advanced Vim Cheat Sheet Commands and Options

    9. Character Search

    • f [char] - Moves forward to the given character.
    • F [char] - Moves backward to the given character.
    • t [char] - Moves forward to before the given character.
    • T [char] - Moves backward to before the given character.
    • ; - Repeats searching forward.
    • , - Repeats searching backward.

    10. Cursor Movement

    • Ctrl+d - Moves down half the page.
    • Ctrl+e - Scrolls down one line.
    • Ctrl+u - Moves up half the page.
    • Ctrl+y - Scrolls up one line.
    • gg - Goes to the top of the page.
    • G - Goes to the bottom of the page.
    • } - Goes forward by a paragraph.
    • { - Goes backward by a paragraph.
    • : [num] [enter] - Goes to a specific line in the document.

    11. File Tabs

    • :e filename - Edits a file.
    • :tabe - Creates a new tab.
    • gt - Goes to the next tab.
    • gT - Goes to the previous tab.
    • :vsp - Vertically splits windows.
    • Ctrl+ws - Splits windows horizontally.
    • Ctrl+wv - Splits windows vertically.
    • Ctrl+ww - Switches between windows.
    • Ctrl+wq - Quits a window.

    12. General

    • . - Repeats the last command.
    • % - Jumps between matching () or {}.
    • Ctrl+r+0 - Inserts the last yanked text in the insert mode.
    • gv - Selects the last selected block of text from the visual mode.

    13. Marks

    These let you jump to marked points in the code.

    • m{a-z} - Set the designated mark, a-z, at the cursor position. A capital mark, A-Z, sets a global mark that will work between files.
    • '{a-z} - Moves the cursor to the beginning of the line where the mark was set.
    • '' - Goes back to the previous jump location.

    14. Registers

    Registers in Vim are dedicated memory spaces that the code editor uses for storing text. It has ten types of registers.

    • :reg[isters] - Shows the contents of all named and numbered registers.
    • "xy - Yanks into register x.
    • "xp - Pastes the contents of register x.
    • "+y - Yanks into the system clipboard register.
    • "+p - Pastes into the system clipboard register.

    Note : Vim stores registers in ~/.viminfo. These are loaded on the next restart of Vim.

    15. Tabs

    • :qa - Closes all open tabs.
    • :wa - Saves all open tabs.
    • :wqa - Saves and quits all open tabs.

    16. Text Editing

    • J - Joins line below the current one.
    • r [char] - Replaces a single character with the specified character. It doesn’t use the insert mode.

    17. Visual Mode

    • o - Moves to the other end of the marked area.
    • O - Moves to the other corner of the block.

    Some Tips to Make Vim More Productive

    It’s important to configure Vim beforehand because it can be anything but a pleasant experience to use the popular code editor straight out of the box. This is because of the following reasons:

    • Although indenting and unindenting multiple lines are available, it is demanding.
    • File management for multiple files is difficult.
    • Integrating plugins is not smooth.
    • No autocomplete.
    • Support for the mouse is unavailable.
    • Typing: w over and over to save is infuriating.
    • You can’t use the system clipboard.

    There are many things that you can do to make working with the Vim code editor productive and easy. Obviously, not all of them might be preferred by everyone, but we are sure that there’s something helpful for everyone here. So, here are some tips to make Vim better:

    • If you are using Visual Studio Code , then install the Vim extension.
    • Switching caps lock and escape keys makes it a lot easier.
    • Use the system clipboard:
      • "+y - Copies a selection to the system clipboard.
      • "+p - Pastes a selection from the system clipboard.
      • If these commands are not working, then this means that Vim is not built with the system clipboard option. For checking the same, run the vim --version command. The clipboard exists if it says +clipboard. -clipboard signifies that there is no clipboard available and so you won’t be able to copy anything outside of the Vim code editor.
    • Use Vintageous in Sublime Text if you are not an advanced Vim user.

    Conclusion

    Vim is undoubtedly one of the best code editors that developers like to rely on when it comes to quick reviewing and editing code. We hope that you find this Vim cheat sheet useful and bookmarked it for your future reference. It will help you to get the most out of the popular code editor. Happy coding!

    Do you know some Vim tricks that can further enhance the developer experience? Do share with us via comments so that we can add the same to this Vim cheat sheet and make it better for our readers.

    Thanks already!

    People are also reading:

    Leave a Comment on this Post

    0 Comments