โœ๏ธ Linux/Unix: Editors & Help Tools
Estimated reading: 3 minutes 100 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