Fundamentals 9 min read

Master Vim: Essential Commands, Modes, and Tips for Efficient Editing

This guide introduces Vim, a powerful and highly customizable text editor, covering its history, key features, command-line options, and the three primary editing modes with practical examples and shortcuts for effective use.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Vim: Essential Commands, Modes, and Tips for Efficient Editing

Vim is a powerful, highly customizable text editor derived from Vi, widely regarded as the best Vi-like editor and a strong competitor to Emacs.

In 2000 Vim won the Slashdot Beanie award for Best Open‑Source Text Editor, reaffirming its prominence alongside Emacs.

Basic Usage

vim [options] [file ...]          # edit specified files
vim -                            # read from standard input
vim -t tag                       # edit the file where the tag is defined
vim -q [errorfile]               # edit the first file with an error

Command‑Line Options

--          only file names follow
-v          Vi mode (like "vi")
-e          Ex mode (like "ex")
-E          Improved Ex mode
-s          Silent (batch) mode, works only with "ex"
-d          Diff mode (vimdiff)
-y          Easy mode (evim)
-R          Read‑only mode (view)
-Z          Restricted mode (rvim)
-m          Modifiable off (no write)
-M          Text not modifiable
-b          Binary mode
-l          Lisp mode
-C          Compatible with traditional Vi
-N          Not compatible with traditional Vi
-V[N][fname]  Verbose level N, log to fname
-D          Debug mode
-n          No swap file, use memory only
-r          List swap files and exit (or recover)
-A          Arabic mode
-H          Hebrew mode
-F          Farsi mode
-T          Set terminal type
-u          Use alternative .vimrc
-noplugin   Do not load plugin scripts
-P[N]       Open N tab pages (default: one per file)
-o[N]       Open N windows (default: one per file)
-O[N]       Same as -o but vertical split
+cmd        Execute commands before loading any vimrc
-c          Execute after loading first file
-S          Source a session file after first file
-s          Read normal‑mode commands from a file
-w          Append all typed commands to a file
-W          Write all typed commands to a file
-x          Edit encrypted file
--startuptime Write startup timing messages to file
-i          Use alternative .viminfo file
-h, --help  Show help and exit
--version   Show version and exit

Editor Modes

Vim modes diagram
Vim modes diagram

Command mode – Press ESC at any time to return to this mode. In this mode, characters typed are interpreted as Vim commands; valid commands trigger actions, while invalid ones cause a beep.

Insert (text input) mode – Entered via commands like i, a, o, c, r, or s. Typed characters are inserted into the file. Press ESC to return to command mode.

Ex (command‑line) mode – Press : in command mode to enter the bottom line where you can execute file‑wide commands such as saving, quitting, or running shell commands. After execution, Vim returns to command mode.

Common Commands

Entering Insert Mode

i   Insert before cursor
I   Insert at beginning of line
a   Append after cursor
A   Append at end of line
o   Open new line below and insert
O   Open new line above and insert

Navigation in Command Mode

h   Move left
j   Move down
k   Move up
l   Move right
M   Move to middle of screen
L   Move to bottom line of screen
G   Go to end of file
gg  Go to start of file
w   Jump forward a word
b   Jump backward a word
Ctrl‑d   Scroll half‑page down
Ctrl‑u   Scroll half‑page up

Deletion

x   Delete character under cursor
X   Delete character before cursor
dd  Delete current line
D   Delete from cursor to end of line
dw  Delete word from cursor

Undo/Redo

u   Undo last change
Ctrl‑r   Redo undone change

Repeat

.   Repeat last change
>>  Shift line right
<<  Shift line left

Copy & Paste

yy          Yank (copy) current line
nyy         Yank n lines
p           Paste after cursor

Search & Replace

/pattern    Search forward for pattern
n           Next occurrence
N           Previous occurrence
:%s/abc/123/g   Replace all "abc" with "123" in the whole file
1,10s/abc/123/g Replace "abc" with "123" from line 1 to 10
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

command-linetext editorVimkeyboard shortcutsprogramming tools
MaGe Linux Operations
Written by

MaGe 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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.