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
Command | Description | Example Use |
---|---|---|
w | Jump to the start of the next word | Fast word to word movement |
e | Jump to the end of the current word | Edit at the word’s end |
b | Jump to the start of the previous word | Navigate backward by words |
0 | Move to the beginning of the current line | Start editing from the line start |
^ | Move to the first non whitespace character | Ignore leading spaces |
$ | Move to the end of the line | Edit at the line end |
gg | Jump to the beginning of the file | Quick top of file navigation |
G | Jump to the end of the file | Reach the last line |
:n | Go to line n | Useful for large files |
/pattern | Search forward for pattern | Find specific keywords |
?pattern | Search backward for pattern | Locate earlier matches |
Basic Editing Commands
Command | Description | Example Use |
---|---|---|
x | Delete a single character | Quick typo removal |
d | Delete highlighted text | Used with visual or motion commands |
dd | Delete the current line | Fast line removal |
yy | Yank (copy) the current line | Duplicate lines |
p | Paste after the cursor | Insert copied text |
P | Paste before the cursor | Insert before |
ciw | Change (replace) the current word | Edit specific words |
cw | Change from the cursor to the word’s end | Partial word editing |
ci<text-object> | Change inside text object (e.g., parentheses) | Useful for nested structures |
Ctrl+v | Enter visual block mode | For columnar editing |
Quick Editing Examples
Task | Command Sequence | Description |
---|---|---|
Delete everything below | Shift+V → Shift+G → d | Deletes all lines from the current one onward |
Indent all lines below | Ctrl+v → Shift+G → Shift+I → Type spaces → Esc , Esc | Indents multiple lines |
Find and replace | : %s/foo/bar/g | Replace all instances of foo with bar |
Comment multiple lines | Shift+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 line | yy → p | Copies and pastes the current line below |
Sort lines | Highlight (Shift+V ) → :sort | Alphabetizes selected lines |
Remove blank lines | :g/^$/d | Deletes all empty lines in the file |
Change inside quotes | ci" | Replaces text inside quotation marks |
Toggle case of a word | ~ | Swaps lowercase to uppercase and vice versa |
Join multiple lines | Highlight (Shift+V ) → J | Combines lines into one |
Align equals in configs | Ctrl+v → Highlight → Shift+I → Add spaces → Esc , Esc | Aligns equals signs or other separators |
Remove trailing spaces | :%s/\s\+$//e | Cleans up unnecessary whitespace at line ends |
Text Objects and Visual Mode
Command | Description | Example Use |
---|---|---|
vi<text-object> | Select inside a text object | vi( selects inside parentheses |
va<text-object> | Select text object, including delimiters | va{ selects braces and contents |
v | Start visual mode for character selection | Highlight portions of text |
V | Start visual line mode | Select entire lines |
Ctrl+v | Start visual block mode | Columnar selection for block editing |
Registers and Paste
Command | Description | Example Use |
---|---|---|
"_d | Delete without overwriting clipboard | Safely deletes while keeping copied text |
"_x | Delete character without overwriting clipboard | For precise deletions |
Remap paste | Add 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
- Create a configuration file:
mkdir -p ~/.config/nvim touch ~/.config/nvim/init.vim
- 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!
0 Comments