Introduction

This cheatsheet showcases essential VIM commands and practical examples. These commands help you navigate, edit, and manipulate code or configuration files efficiently.


Navigation Commands

CommandDescriptionExample Use
wJump to the start of the next wordFast word to word movement
eJump to the end of the current wordEdit at the word’s end
bJump to the start of the previous wordNavigate backward by words
0Move to the beginning of the current lineStart editing from the line start
^Move to the first non whitespace characterIgnore leading spaces
$Move to the end of the lineEdit at the line end
ggJump to the beginning of the fileQuick top of file navigation
GJump to the end of the fileReach the last line
:nGo to line nUseful for large files
/patternSearch forward for patternFind specific keywords
?patternSearch backward for patternLocate earlier matches

Basic Editing Commands

CommandDescriptionExample Use
xDelete a single characterQuick typo removal
dDelete highlighted textUsed with visual or motion commands
ddDelete the current lineFast line removal
yyYank (copy) the current lineDuplicate lines
pPaste after the cursorInsert copied text
PPaste before the cursorInsert before
ciwChange (replace) the current wordEdit specific words
cwChange from the cursor to the word’s endPartial word editing
ci<text-object>Change inside text object (e.g., parentheses)Useful for nested structures
Ctrl+vEnter visual block modeFor columnar editing

Quick Editing Examples

TaskCommand SequenceDescription
Delete everything belowShift+VShift+GdDeletes all lines from the current one onward
Indent all lines belowCtrl+vShift+GShift+I → Type spaces → Esc, EscIndents multiple lines
Find and replace: %s/foo/bar/gReplace all instances of foo with bar
Comment multiple linesShift+V → Select lines → :s/^/#/Adds a comment symbol to the start of each line
Uncomment multiple lines:s/^#//Removes the comment symbol from each line
Duplicate a lineyypCopies and pastes the current line below
Sort linesHighlight (Shift+V) → :sortAlphabetizes selected lines
Remove blank lines:g/^$/dDeletes all empty lines in the file
Change inside quotesci"Replaces text inside quotation marks
Toggle case of a word~Swaps lowercase to uppercase and vice versa
Join multiple linesHighlight (Shift+V) → JCombines lines into one
Align equals in configsCtrl+v → Highlight → Shift+I → Add spaces → Esc, EscAligns equals signs or other separators
Remove trailing spaces:%s/\s\+$//eCleans up unnecessary whitespace at line ends

Text Objects and Visual Mode

CommandDescriptionExample Use
vi<text-object>Select inside a text objectvi( selects inside parentheses
va<text-object>Select text object, including delimitersva{ selects braces and contents
vStart visual mode for character selectionHighlight portions of text
VStart visual line modeSelect entire lines
Ctrl+vStart visual block modeColumnar selection for block editing

Registers and Paste

CommandDescriptionExample Use
"_dDelete without overwriting clipboardSafely deletes while keeping copied text
"_xDelete character without overwriting clipboardFor precise deletions
Remap pasteAdd this to your config to avoid overwriting:nnoremap <leader>p "_dP

Setting Up NeoVim with vim-plug

Step 1: Install vim-plug

Run the following command:

curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Step 2: Configure Plugins

  1. Create a configuration file: mkdir -p ~/.config/nvim touch ~/.config/nvim/init.vim
  2. Add this to the file:
call plug#begin('~/.local/share/nvim/plugged')

Plug 'ThePrimeagen/vim-be-good'

call plug#end()

set number
set relativenumber
set tabstop=4
set shiftwidth=4
set expandtab
syntax on

3. Save and close (:wq).

    Step 3: Install Plugins

    Open NeoVim and type:

    :PlugInstall

    Step 4: Run vim-be-good

    Type:

    :VimBeGood

    What is vim-be-good?

    vim-be-good is a game designed for NeoVim users to improve their speed and accuracy with VIM commands. It provides challenges focused on motions, text objects, and editing tasks, helping you build muscle memory while having fun. Whether you’re a beginner or advanced, vim-be-good turns practicing VIM into an engaging experience that makes you faster and more efficient.


    Closing Thoughts

    With this cheatsheet, you’ll be able to navigate and edit code or configuration files in VIM at lightning speed. Use the tables as a reference, practice the examples, and explore advanced features like plugins and text objects to customize your workflow. VIM is all about efficiency—master it to make editing fun and productive!

    Categories: Programming

    0 Comments

    Leave a Reply

    Avatar placeholder

    Your email address will not be published. Required fields are marked *