How To Edit Using Vi In Linux

2 min read

Learning how to edit using vi in Linux is one of the most practical skills you can develop as a system administrator, developer, or anyone who works in a terminal. Here's the thing — vi is a modal text editor, meaning it behaves differently depending on whether you are typing text, issuing commands, or selecting content. Because of that, that design can feel unusual at first, but it is exactly what makes vi fast, lightweight, and available on almost every Linux system. Once you understand its modes and a small set of commands, you can open, modify, search, replace, and save files without leaving the command line.

The Core Modes of vi

Before you edit a single character, you need to understand that vi does not work like a typical graphical editor. It has several modes, and each mode gives your keyboard a different meaning And that's really what it comes down to..

  • Command mode is the default mode when vi opens. Keystrokes are interpreted as editing commands, not as text. You can move the cursor, delete lines, copy text, and prepare to enter insert mode.
  • Insert mode is where you type actual content into the file. You enter it with keys such as i, a, or o, and you leave it by pressing Esc.
  • Visual mode lets you select text character by character, line by line, or in block form. You enter it with v, V, or Ctrl+v, depending on the selection style you need.
  • Ex mode is accessed by typing : from command mode. It is used for saving, quitting, searching, replacing, and running line-oriented commands.

The most important habit to build is this: when in doubt, press Esc. Pressing Esc returns you to command mode, from which you can safely issue further commands.

Step-by-Step: How to Edit Using vi in Linux

1. Open a File

To start editing, type vi followed by the filename:

vi notes.txt

If the file does not exist, vi creates a new buffer for it. The file is not written to disk until you save. On top of that, when vi opens, you are in command mode. You cannot type text immediately, which is why beginners often press keys and see nothing appear in the file Took long enough..

2. work through Without Arrow Keys

vi supports arrow keys on most modern systems, but the traditional navigation keys are faster and more reliable:

  • h moves left.
  • j moves down.
  • k moves up.
  • l moves right.
  • 0 moves to the beginning of the line.
  • $ moves to the end of the line.
  • gg moves to the first line of the file.
  • G moves to the last line.
  • w moves forward one word.
  • b moves
Hot Off the Press

What's New Today

Kept Reading These

Also Worth Your Time

Thank you for reading about How To Edit Using Vi In Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home