Mastering Vim: Most Used Tips and Tricks for Faster Editing
Vim is powerful. But it only becomes magical when you go beyond :wq
and i
. This guide delivers practical, high-impact Vim tips and tricks used daily by pros β from navigation to editing, clipboard magic to plugins. Whether you're writing code or editing configs, these will make you faster and happier.
π§ TL;DR
Here are the most-used Vim tips and tricks to supercharge your editing:
- Use
hjkl
to navigate,w
/b
to move by words. - Yank and paste with
yy
,dd
,p
. - Visual select with
v
,V
, orCtrl+v
. - Use macros (
q
,@
) to automate actions. - Navigate files with
:e
,:bnext
,:ls
. - Split windows:
:vsp
,:sp
,Ctrl+w
combos. - Search and replace with
:%s/old/new/g
. - Save time with plugins and
.vimrc
settings.
π§ Mastering Vim: Most Used Tips and Tricks
Vim is a powerful, lightweight text editor built into every Unix-like system. Mastering it not only boosts your productivity but also helps you stay efficient on remote systems where GUI editors arenβt available.
Hereβs a breakdown of the most practical and frequently used tips, broken into categories for easier learning.
πΉοΈ Movement & Navigation
Basic motion:
h
β leftl
β rightj
β downk
β up
Word-based motion:
w
β next wordb
β previous worde
β end of word
Line & file motion:
0
β beginning of line^
β first non-blank character$
β end of linegg
β beginning of fileG
β end of file:n
β go to linen
βοΈ Copy, Paste, Delete
Yank (copy):
yy
β yank entire lineyw
β yank wordy$
β yank to end of line
Paste:
p
β after cursorP
β before cursor
Delete:
dd
β delete linedw
β delete wordd$
β delete to end of line
π¦ Visual Mode
Visual selection is powerful:
v
β character-wise selectionV
β line-wise selectionCtrl+v
β block (column) selection
Once selected, you can d
to delete, y
to yank, >
or <
to indent, and r<char>
to replace all characters.
π Search & Replace
To search:
:/pattern
To search and replace globally:
:%s/old/new/g
With confirmation:
:%s/old/new/gc
πͺ Macros (Repeat Actions)
Start recording with:
q<register> " e.g. qa
Do your edits, then stop recording with q
.
Replay with:
@<register> " e.g. @a
Repeat multiple times:
10@a
πͺ Window Splits & Buffers
Splits:
:vsp filename " vertical split
:sp filename " horizontal split
Window navigation:
Ctrl+w h/j/k/l
β move between splitsCtrl+w =
β equal size
Buffers:
:ls " list open buffers
:bn / :bp " next/previous buffer
:bd " delete buffer
:e filename " open new file
βοΈ Customization (~/.vimrc
)
Use vim ~/.vimrc
to configure settings.
Example:
set number " Show line numbers
syntax on " Enable syntax highlighting
set tabstop=4 " Tab width
set expandtab " Use spaces instead of tabs
set autoindent " Smart indentation
π Plugins (Bonus)
Use vim-plug to install plugins.
Example ~/.vimrc
snippet:
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree'
Plug 'tpope/vim-commentary'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
call plug#end()
Then open Vim and run:
:PlugInstall
π Create/Edit Files with Vim
Create a new file:
vim myfile.txt
Edit /etc/hosts
(as root):
sudo vim /etc/hosts
π§Ό Clean Exit
Save and quit:
:wq
or , save one keystroke !
:x
Quit without saving:
:q!
Save without quitting:
:w
β Final Tips
- Practice! Use Vim for daily tasks to develop muscle memory.
- Use
:help <command>
when stuck. - Always backup your
.vimrc
.
Happy Vimming !