Vim Cheat Sheet: Essential Commands for Efficient Editing

vim cheat sheet

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Vim (Vi IMproved) is a highly powerful text editor used in Unix-based systems. It is an advanced version of Vi editor, thus offers features like syntax highlighting, multi-level undo, and extensive plug-in support. 

However, the tool comes with too many commands, which is why a Vim Cheat Sheet is your best friend to navigate through the mess!

Vim Modes Overview: 

ModeDescriptionActivation
Normal ModeDefault mode for navigation and text manipulationPress Esc
Insert ModeAllows direct text input, similar to a standard text editorPress i, a, o, etc.
Visual ModeEnables text selection for copying, deleting, or modifyingPress v (character mode), V (line mode), Ctrl + v(block mode)
Command ModeUsed for executing commands like saving, quitting, and searchingPress : followed by a command
Replace ModeOverwrites text instead of insertingPress R

Basic Commands

Vim Cheat Sheet - Basic Commands
  • vim filename → Open a file in Vim
  • :q → Quit Vim
  • :q! → Quit without saving
  • :w → Save the file
  • :wq or ZZ → Save and quit
  • :help command → Get help for a specific command

Navigation in Vim

To navigate within a file by characters, words, tokens, or lines. You need specific commands to move the cursor. 

Moving By The Screens

Vim Cheat Sheet - Moving by the screens
  • Ctrl + b – move back one full screen
  • Ctrl + f – move forward one full screen
  • Ctrl + d – move forward 1/2 a screen
  • Ctrl + u – move back 1/2 a screen
  • Ctrl + e – move screen down one line (without moving the cursor)
  • Ctrl + y – move screen up one line (without moving the cursor)
  • Ctrl + o – move backward through the jump history
  • Ctrl + i – move forward through the jump history
  • H – move to the top of the screen (H=high)
  • M – move to the middle of the screen (M=middle)
  • L – move to the bottom of the screen (L=low)

Related Article: Install Vim on Ubuntu in 5 Minutes!

Moving Within A Line

Vim Cheat Sheet - Move within the lines
  • h → Move left
  • l → Move right
  • 0 → Move to the beginning of the line
  • ^ → Move to the first non-blank character
  • $ → Move to the end of the line

Moving Between Words

Vim Cheat Sheet - Moving between words
  • w → Move forward one word
  • b → Move backward one word
  • e → Move to the end of the current/next word

Moving Across The File

Vim Cheat Sheet - Moving across the files
  • gg → Move to the beginning of the file                
  • G → Move to the end of the file
  • :n → Move to line n (e.g., :10 goes to line 10)
  • Ctrl + d → Move half a page down
  • Ctrl + u → Move half a page up

Editing and Manipulating Text

Editing Text

Vim Cheat Sheet - Editing Text
  • r – replace a single character (and return to command mode)
  • cc – replace an entire line (deletes the line and moves into insert mode)
  • C / c$ – replace from the cursor to the end of a line
  • cw – replace from the cursor to the end of a word
  • s – delete a character (and move into insert mode)
  • J – merge the line below to the current one with a space in between them
  • gJ – merge the line below to the current one with no space in between them
  • u – undo
  • Ctrl + r – redo
  • . – repeat last command

Inserting & Replacing Text 

Vim Cheat Sheet - Inserting & Replacing Text
  • i → Insert before the cursor
  • a → Insert after the cursor
  • o → Open a new line below
  • O → Open a new line above
  • r<char> → Replace a single character
  • R → Enter replace mode (overwrite text)

Deleting & Replacing Text 

Vim Cheat Sheet - Deleting & Replacing Text
  • x → Delete the character under the cursor
  • dd → Delete the current line
  • D → Delete from the cursor to the end of the line
  • dw → Delete a word
  • d$ → Delete from the cursor to the end of the line
  • dG → Delete from the cursor to the end of the file

Copy & Pasting Text 

Vim Cheat Sheet - Copy & Pasting Text
  • yy → Copy (yank) the current line
  • y$ → Copy from the cursor to the end of the line
  • yw → Copy a word
  • p → Paste after the cursor
  • P → Paste before the cursor

Search and Replace

Searching 

Vim Cheat Sheet - Searching
  • /word → Search for “word” forward
  • ?word → Search for “word” backward
  • n → Repeat last search in the same direction
  • N → Repeat last search in the opposite direction

Replacing 

Vim Cheat Sheet - Replacing
  • :%s/old/new/g → Replace all occurrences of “old” with “new” in the file
  • :%s/old/new/gc → Replace with confirmation

Working with Multiple Files

Vim Cheat Sheet - Working With Multiple Files
  • :e filename → Open another file
  • :n → Switch to the next file
  • :prev → Switch to the previous file
  • :split filename → Split window horizontally and open a file
  • :vsplit filename → Split window vertically and open a file
  • Ctrl + w → Switch between split windows

Advanced Features

Vim Cheat Sheet - Advanced Features
  • :set number → Show line numbers
  • :set nonumber → Hide line numbers
  • :syntax on → Enable syntax highlighting
  • :syntax off → Disable syntax highlighting 
  • :set ignorecase → Set case-insensitive search
  • :set noignorecase → Set case-sensitive search
  • :set autoindent → Enable auto-indentation
  • :set noautoindent → Disable auto-indentation

Conclusion – Vim Cheat Sheet

Vim is an incredibly powerful text editor that can greatly enhance your productivity once you master its commands. By using shortcuts for navigation, editing, and file management, you can edit text efficiently without relying on a mouse. Whether you’re a beginner or an advanced user, keeping this Vim cheat sheet handy will help you streamline your workflow. Happy coding!

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

1. What is the difference between Vim and Vi?

Vim (Vi Improved) is an enhanced version of Vi, offering additional features like syntax highlighting, multi-level undo, and plugin support.

2. What is Vim used for?

Vim is a powerful text editor used for programming, scripting, and general text editing, offering efficiency through keyboard shortcuts.

3. How do I exit Vim?

Use :q to quit, :q! to quit without saving, and :wq or ZZ to save and exit.

Marium Fahim
Hi! I am Marium, and I am a full-time content marketer fueled by an iced coffee. I mainly write about tech, and I absolutely love doing opinion-based pieces. Hit me up at [email protected].
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!