✍️ Linux/Unix: Editors & Help Tools
Estimated reading: 3 minutes 271 views

Linux/Unix: vi/vim Editor Basics – Modes & Navigation Explained

Introduction – Why Learn vi/vim?

The vi and vim editors are powerful, terminal-based text editors that are pre-installed on nearly every Unix-like system. Whether editing config files, scripts, or code, knowing vim is an essential skill for system admins and developers.

In this guide, you’ll learn:

  • How to switch between modes in vi/vim
  • How to navigate files using keyboard shortcuts
  • Practical commands for cursor movement, file editing, and quitting

What is vi and vim?

  • vi: Original UNIX text editor.
  • vim: “Vi IMproved” – adds features like syntax highlighting, multi-level undo, plugins, and more.

Launch vim with:

vim filename

Modes in vi/vim

vim works in different modes, each with a specific purpose:

ModePurposeHow to Access
Normal ModeDefault mode – used for navigationPress Esc
Insert ModeUsed to insert or edit textPress i, a, o
Visual ModeUsed to select and manipulate textPress v or V
Command ModeUsed for saving, exiting, searchingType : in Normal

Entering Modes – Quick Keys

KeyAction
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
oOpen new line below
OOpen new line above
EscReturn to Normal mode

Navigation Shortcuts

In Normal Mode, use these keys to navigate:

KeyAction
hMove left
lMove right
jMove down
kMove up
0Move to beginning of line
^Move to first non-blank char
$Move to end of line
ggMove to start of file
GMove to end of file
:nGo to line n
Ctrl+dScroll down half page
Ctrl+uScroll up half page

Basic Workflow Example

vim test.txt
  1. Press i β†’ Enter Insert Mode
  2. Type: Hello, Linux World!
  3. Press Esc β†’ Back to Normal Mode
  4. Type :wq β†’ Save and Quit

Saving and Quitting

CommandDescription
:wSave (write)
:qQuit
:wqSave and quit
:q!Quit without saving
:xSave (if modified) + quit

Search and Replace (Command Mode)

CommandDescription
/wordSearch forward for “word”
?wordSearch backward
n / NRepeat search (next/prev)
:%s/old/new/gReplace all “old” with “new”
:%s/old/new/gcReplace with confirmation

Bonus: Visual Mode Tips

  • Press v to select by character
  • Press V to select by line
  • Use d, y, or p after selection:
    • d β†’ delete
    • y β†’ yank (copy)
    • p β†’ paste

Summary – Recap & Next Steps

Mastering vi/vim starts with understanding its modes and movement commands. With just a few keystrokes, you can navigate, edit, search, and save filesβ€”without ever leaving your terminal.

Key Takeaways:

  • Esc always returns to Normal Mode.
  • Use i, a, o to enter Insert Mode.
  • Use :wq, :q!, and /search in Command Mode.
  • Efficient text navigation makes editing lightning-fast.

FAQs

What’s the difference between vi and vim?
vim is an improved version of vi, offering syntax highlighting, undo levels, plugins, and more.

How do I copy and paste in vim?
Use yy to yank a line, p to paste below the cursor.

How can I delete a line?
Press dd in Normal Mode.

Can I open multiple files in vim?
Yes:

vim file1 file2

Use :n and :prev to switch files.

How do I enable line numbers?
In Command Mode:

:set number

Share Now :
Share

πŸ”΅ Linux/Unix: vi/vim Editor Basics (Modes, Navigation)

Or Copy Link

CONTENTS
Scroll to Top