Master Vim: Essential Commands and Tips for Efficient Editing
This guide provides a comprehensive cheat‑sheet of Vim commands covering startup, file handling, modes, navigation, editing, searching, replacing, window management, macros, shell integration, commenting, help, and quitting, enabling users to edit text quickly and confidently.
Command History
Commands that start with : or / have a history; press the up/down arrows after typing : or / to browse previous entries.
Starting Vim
Run vim to start Vim.
Run vim filename to open or create filename.
File Commands
Open a single file: vim file Open multiple files: vim file1 file2 file3 … Open a new file in the current window: :open file Open a file in a new split window: :split file Switch to the next buffer: :bn Switch to the previous buffer: :bp List open buffers: :args Open remote files, e.g., :e ftp://192.168.10.76/abc.txt or
:e \\qadrive\test\1.txtVim Modes
Normal mode (press Esc or Ctrl+[) – shows filename at the bottom.
Insert mode (press i) – shows --INSERT--.
Visual mode – shows --VISUAL--.
Navigation Commands
%– jump to matching parenthesis.
Insert Commands
i– insert before cursor I – insert at line start a – append after cursor A – append at line end o – open a new line below O – open a new line above
Search Commands
/text– forward search; n next, N previous. ?text – backward search; n next, N previous.
Special characters need escaping:
.*[]^%/?~$ :set ignorecase– case‑insensitive search; :set noignorecase – case‑sensitive. * or # on a word searches forward or backward respectively. :set hlsearch – highlight matches; :set nohlsearch – turn off highlighting. :set incsearch – incremental search. :set wrapscan – continue search at start/end of file.
Replace Commands
ra– replace current character with
a s/old/new/– replace first occurrence in current line s/old/new/g – replace all occurrences in current line %s/old/new/ – replace first occurrence in each line %s/old/new/g – replace all occurrences in the whole file :10,20 s/^/ /g – indent lines 10‑20 with four spaces ddp – swap current line with the line below
Movement Commands
h– left j – down k – up l – right (rarely used)
Numbers can prefix motions, e.g., 20j moves down 20 lines. w – forward a word; b – backward a word; e – to end of word ^ – first non‑blank character of line 0 – beginning of line $ – end of line; 3$ – end of line three lines down gg – top of file; G – bottom of file f{x} – find next x on the line; F{x} – backward find
Jump to line: :123 or 123G Scrolling: Ctrl+e / Ctrl+y (one line), Ctrl+d / Ctrl+u (half‑screen), Ctrl+f / Ctrl+b (full screen)
Undo and Redo
u– undo; U – undo whole line; Ctrl+r – redo.
Delete Commands
x– delete character under cursor 3x – delete three characters X – delete character before cursor dd – delete current line 10d – delete 10 lines starting at cursor D – delete to end of line :1,10d – delete lines 1‑10; :11,$d – delete from line 11 to end J – join lines (removes blank line)
Copy and Paste
yy– yank (copy) current line nyy – yank n lines p – paste after cursor Shift+p – paste before cursor :1,10 co 20 – copy lines 1‑10 after line 20
Visual mode ( v or V) + y to copy selection ddp – swap current line with the line below xp – swap current character with the next one
Cut Commands
Visual mode + d to cut selection ndd – cut n lines starting at cursor :1,10d – cut lines 1‑10 :1,10 m 20 – move lines 1‑10 after line 20
Quit Commands
:wq– write and quit ZZ – write and quit :q! – quit without saving :e! – reload file, discarding changes
Window Commands
:splitor :new – open a new horizontal window :vsplit – open a vertical split Ctrl+ww – cycle to next window Ctrl+wj / Ctrl+wk – move cursor to window below/above :close – close current window (cannot close the last one) :only – keep only the current window
Recording Macros
Press q followed by a letter to start recording, press q again to stop; replay with @letter.
Executing Shell Commands
:!command– run external command :!ls – list files in current directory :!perl -c script.pl – check Perl syntax without leaving Vim :!perl script.pl – run Perl script directly :suspend or Ctrl+Z – suspend Vim, return with
fgComment Commands (for Perl files)
Prefix lines with # to comment 3,5 s/^/#/g – comment lines 3‑5 3,5 s/^#//g – uncomment lines 3‑5 1,$ s/^/#/g or :%s/^/#/g – comment entire file
Help Commands
:helpor F1 – open help :help i, :help CTRL-[, etc. – topic‑specific help
Use Ctrl+] to follow a tag, Ctrl+o to return
Other Non‑Editing Commands
.– repeat last change :set ruler? – show if ruler is set :scriptnames – list sourced script files :set list – show invisible characters
Vim Tutorial
On Unix: vimtutor On Windows: :help tutor Syntax commands: :syntax, :syntax clear, :syntax case match,
:syntax case ignoreMaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
