Fundamentals 12 min read

Master Vim: Essential Modes, Commands, and Tips for Linux Users

This guide introduces Linux Vim’s built‑in help, explains its five core modes, demonstrates common editing commands such as cursor movement, insertion, deletion, searching, copying, and replacement, and covers the swap‑file protection mechanism with practical examples and command‑line snippets.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Vim: Essential Modes, Commands, and Tips for Linux Users

Introduction

The article provides a concise tutorial on using the Vim editor in Linux, starting with how to access Vim’s built‑in help ( :help) and then diving into its modal editing model.

Vim Modes

Vim operates with several distinct modes, each affecting how keystrokes are interpreted:

Normal mode : the default editing mode; most commands are entered here. Press Esc to return from any other mode.

Command mode : entered by typing :, /, or ? in Normal mode; commands are executed after pressing Enter.

Insert mode : for inserting text, entered with i, a, o, O, etc.

Visual mode : for selecting text blocks; v selects characters, V selects whole lines, Ctrl‑V selects rectangular blocks.

Select mode : similar to typical Windows editors; rarely used on Linux and omitted from further discussion.

Insert‑mode shortcuts

i

– insert at cursor I – insert at line start o – open a new line below O – open a new line above a – append after cursor A – append at line end

Basic Editing Operations

1. Cursor movement

In Normal mode, use the following keys: h – left j – down k – up l – right

Arrow keys work as well but are slower for touch‑typists.

2. Deleting text

x

– delete the character under the cursor dd – delete the current line u – undo the last change Ctrl‑R – redo an undone change U – undo all changes on the current line

3. Other editing commands

o

/ O – open a new line below/above and switch to Insert mode

4. Exiting Vim

ZZ

– save and quit :q! – quit without saving :e! – reload the file, discarding changes :wq or :wq! – write (save) and quit

5. Jumping to specific lines

G

– go to the last line (or {num}G to go to line {num}) gg – go to the first line (same as 1G)

6. Simple searching

/pattern

– search forward for

pattern
?pattern

– search backward n – repeat the search in the same direction; N – opposite direction :set ignorecase / :set noignorecase – toggle case‑insensitive search :set hlsearch / :set nohlsearch – enable/disable result highlighting

7. Copy and paste

y

– yank (copy) into a register; e.g., yw copies a word, yy copies a whole line, 3yy copies three lines. p – paste after the cursor (or P before).

8. Substituting text

:s/old/new/

– replace first occurrence of old on the current line :s/old/new/g – replace all occurrences on the current line :%s/old/new/g – replace all occurrences in the entire file

Vim’s Swap‑File Protection

If Vim is terminated abruptly, a swap file ( .filename.swp) is left behind. On the next start Vim warns with E325: swap file exists and offers options: (O) – open read‑only (E) – edit anyway (R) – recover changes (D) – delete the swap file (Q) – quit (A) – abort

Recover with :recover or vim -r filename, then delete the swap file to avoid future warnings.

Permissions Note

Vim requires appropriate read/write permissions on the target file; lacking them will prevent editing or saving.

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 editorVimfundamentalsmodal editingswap file
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.