Transform Your Coding Workflow: Master Vim’s 26-Key Power on Linux
This guide walks you through Vim’s fundamentals on Linux, covering its purpose, core modes, essential commands for navigation, editing, and file management, as well as practical configuration tips to turn the editor into a powerful, customized development environment.
Vim: Rebuilding Your Code Universe with 26 Keyboard Keys
In the world of code, efficiency is a perpetual pursuit. Vim, the “efficiency king” of Linux, offers a highly configurable, modal text editor that runs on most Unix-like systems and Windows.
What is Vim?
Vim (Vi IMproved) is an enhanced version of the classic Vi editor. It follows a modal editing philosophy, providing Normal, Insert, Visual, and Command-line modes to perform text editing efficiently.
Why Choose Vim?
Extreme efficiency : Almost all operations are keyboard‑driven, keeping hands on the keyboard.
Highly customizable : Rich configuration options and a vast plugin ecosystem.
Cross‑platform : Consistent experience on Linux, macOS, and Windows.
Steep learning curve, great payoff : Mastery yields productivity gains unmatched by other editors.
Core Modes
Normal Mode
The default mode where cursor movement and editing commands are issued.
Insert Mode
Enter Insert mode with a, i or o to start inserting text.
Command-line Mode
Press : to execute commands such as :w (save) and :q (quit).
Basic Operations
Opening Vim
Syntax : vim filename – opens the file in Vim.
Mode Switching
Normal → Insert: press a, i or o. Insert → Normal: press Esc. Normal → Command-line: press Shift+; (i.e., :). Command-line → Normal: press Esc.
Exiting Vim
Two methods:
In Normal mode, type ZZ to save and quit.
In Command-line mode, :wq saves and quits, :q! quits without saving.
Command‑Mode Commands
Cursor Movement
Basic movement : h left, j down, k up, l right.
Specific positions : G end of file, $ end of line, ^ start of line, w next word, b previous word, gg start of file.
Screen movement : Ctrl+b page up, Ctrl+f page down, Ctrl+u half‑page up, Ctrl+d half‑page down.
Deleting Text
Character: x, #x, X, #X.
Line: dd, #dd.
Copying and Pasting
Copy characters: yw, #yw.
Copy lines: yy, #yy.
Paste: p.
Cut line: dd (also copies to buffer).
Replacing
Replace a character: r.
Replace mode: R (until Esc).
Toggle case: ~.
Undo and Redo
Undo: u.
Redo: Ctrl+r.
Changing Text
Change word: cw, #cw.
Jump to Line
Show line number: Ctrl+g.
Go to line N:
N G.
Command‑line Mode Commands
Save file: :w.
Quit: :q or :q! (force).
Save and quit: :wq.
Force actions: prepend ! (e.g., :!q).
Toggle line numbers: :set nu and :set nonu.
Multi‑file view: vs filename, switch with Ctrl+w w.
Vim Configuration
Configuration is stored in the .vimrc file in the home directory. Example common settings:
syntax on
set nu
set tabstop=4
set cursorline
...For C++ development, the “VimForCpp” script can set up a ready‑made IDE‑like environment with a single command:
curl -sLf https://gitee.com/HGtz2222/VimForCpp/raw/master/install.sh -o ./install.sh && bash ./install.shNote: avoid running the script as root; it currently supports only CentOS 7 x86_64.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
