Fundamentals 9 min read

Master Vim: Essential Commands, Tips, and Configuration for Efficient Coding

This guide introduces Vim’s core concepts, modes, essential commands for inserting, navigating, deleting, copying, searching, and saving files, plus advanced tips such as command output insertion, range commenting, custom shortcuts, and a simple .vimrc configuration to boost coding efficiency.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Vim: Essential Commands, Tips, and Configuration for Efficient Coding

Vim Basics and Modes

Vim is a powerful multi‑mode text editor widely used on Linux/UNIX for creating and editing files, operating without menus and relying on commands.

Command mode (default): all input is interpreted as commands.

Insert mode.

Low line mode.

Switch between modes using Esc to return to command mode.

Common Insert Commands

a

– insert after the cursor. i – insert before the cursor. o – open a new line below.

Uppercase A, I, O operate at line end, line start, and the line above respectively.

Navigation Commands

Enable line numbers: set nu; disable: set nonu. GG – go to the beginning of the last line; gg – go to the first line. nG or :n – jump to line n. $ – move to line end; 0 – move to line start. b – previous word, w – next word; h j k l – left, down, up, right. L – move to the bottom of the screen.

Deletion Commands

x

– delete the character under the cursor. nx / nX – delete n characters forward/backward. dd – delete the current line. D – delete from cursor to end of line. ndd – delete n lines starting from the current line. dG – delete from the cursor to the end of the file. :n1,n2d – delete a range of lines. u – undo the last change.

Copy and Paste

yy

– yank (copy) the current line; nyy – yank n lines. p – paste after the cursor; P – paste before. dd – cut the current line; ndd – cut n lines.

Search and Replace

:%s/old/new

– replace all occurrences in the file. :n1,n2s/old/new/g – replace in a specific line range. r – replace a single character. R – enter replace mode for the rest of the line. u – cancel the previous operation.

Save and Quit

:w!

– write (save) changes. :q! – quit without saving. :wq! or x! – save and quit. :w filename – write the buffer to a new file.

Advanced Tips

Insert the output of a shell command directly with :r !command, e.g., :r!date inserts the current date.

Comment a range of lines: :n1,n2s/^/#/g Uncomment the same range: :n1,n2s/^#//g Define custom shortcuts with :map: :map ^P I# Define an abbreviation for frequent text: :ab mymail [email protected] Persist shortcuts by adding them to .vimrc (root: /root/.vimrc, regular user: ~/.vimrc).

Simple Vim Configuration

Basic settings are stored in .vimrc. You can install a ready‑made configuration with:

curl -sLf https://gitee.com/HGtz2222/VimForCpp/raw/master/install.sh -o ./install.sh && bash ./install.sh

After installation, reload the shell with source ~/.bashrc. To uninstall, run bash ~/.VimForCpp/uninstall.sh.

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.

Configurationtext editorVimshortcutsCoding Tips
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.