[ TechDocsCove ]  TechDocsCove en   ↩︎

# Mastering Vi and Vim: A Comprehensive Guide for Beginners and Intermediate Users

linux   text editing  

translations: [ es/Español ] · [ fr/Français ] · [ de/Deutsch ]


Table of contents


Vi and Vim are powerful text editors available on most Unix-like systems. This guide covers essential commands and techniques for effective use, focusing on keyboard navigation, text manipulation, and interactive modes.

Vi vs. Vim

Vi is the original text editor that is standard on Unix systems, while Vim (Vi IMproved) is an extended version of Vi that includes additional features like syntax highlighting, multi-level undo, and a more robust set of commands. Vim also supports plugins and provides better support for modern programming languages, making it a more powerful tool for developers and advanced users.

Getting Started

To open a file in Vim, use the following command in your terminal:

vim filename.txt

If the file does not exist, Vim will create it.

Modes in Vim

Vim has several modes, but the two most important are:

To switch to Insert mode, press i. To return to Normal mode, press Esc.

Basic Navigation

Moving the Cursor

Navigating text efficiently is crucial in Vi and Vim. Most cursor movements can be performed in Normal mode, which is the default mode when you open a file. Here are some essential commands for moving the cursor:

These commands allow for quick navigation without needing to use the mouse or arrow keys. To perform these movements, you should always be in Normal mode (not Insert mode). You can switch to Normal mode by pressing Esc.

Scrolling

Deleting Text

Deleting Lines

Deleting Characters

Searching and Replacing Text

Searching

Simple Replacement

To replace a single instance of a word:

To replace all instances of a word in the current line:

To replace in the entire file:

Copying and Pasting Text

Copying Text

Pasting Text

Interactive Mode

Vim can be operated interactively for commands. You can enter commands directly in Normal mode:

Additional Tips

Undo and Redo

File Navigation

Exiting Vim



Created on: Oct 30, 2024


Email shareIcon for sharing via email    Reddit shareIcon for sharing via Reddit    X shareIcon for sharing via X    Telegram shareIcon for sharing via Telegram    WhatsApp shareIcon for sharing via WhatsApp    Facebook shareIcon for sharing via Facebook    LinkedIn shareIcon for sharing via LinkedIn



Discover More within this Subject: