---
description: The vi editor is the most popular and classic text editor in the Linux family.It works in two modes, Command and Insert. Command mode takes the user commands and the Insert mode is for editing text.
title: VI Editor with Commands in Linux/Unix Tutorial
image: https://www.guru99.com/images/vi-editor-commands-in-linux-unix.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

The vi editor is the classic, universally available text editor of Linux and Unix, working entirely through the keyboard in two modes: a command mode for actions and an insert mode for typing text.

* 📝 **What it is:** The vi editor ships with almost every Linux and Unix system and behaves the same across platforms and distributions.
* ⌨️ **Two modes:** Command mode runs actions like copy, delete, and save, while insert mode is for typing text.
* 🚀 **Launching:** Type vi followed by a filename to open an existing file or create a new one.
* ✏️ **Editing:** Single-letter commands such as i, a, dd, and x insert, append, delete lines, and remove characters.
* 💾 **Saving:** From command mode, :w saves, :wq saves and quits, and :q! quits without saving.
* 🤖 **AI assistance:** AI assistants and GitHub Copilot can explain vi commands and suggest edits while you learn.

[ Read More ](javascript:void%280%29;) 

![vi editor commands and command and insert modes in Linux and Unix](https://www.guru99.com/images/vi-editor-commands-in-linux-unix.png)

The vi editor is the text editor you will meet on almost any [Linux](https://www.guru99.com/introduction-linux.html) or Unix machine, so learning its keyboard-driven workflow is a skill that transfers everywhere. This guide explains its two modes, its editing commands, and how to save and quit a file.

## What is the vi editor?

The vi editor is the most popular and classic text editor in the Linux family. Below are some of the reasons that make it a widely used editor:

* It is available in almost all Linux distributions.
* It works the same across different platforms and distributions.
* It is user-friendly, so millions of Linux users rely on it for their editing needs.

Nowadays there are advanced versions of the vi editor available, and the most popular one is VIM, which stands for Vi Improved. Some of the others are Elvis, Nvi, Nano, and Vile. It is wise to learn vi because it is feature-rich and offers endless possibilities to edit a file.

## vi Editor Operation Modes

To work on the vi editor, you need to understand its operation modes. They can be divided into two main parts: command mode and insert mode. The screenshot below shows the vi editor open in a Linux terminal.

[](https://www.guru99.com/images/The%5Fvi%5Feditor%282%29.jpg)

### vi Command Mode

* The vi editor opens in this mode, and it only understands commands.
* In this mode you can move the cursor and cut, copy, and paste text.
* This mode also saves the changes you have made to the file.
* Commands are case-sensitive, so you should use the right letter case.

### vi Insert Mode

* This mode is for inserting text into the file.
* You can switch to insert mode from command mode by pressing ‘i’ on the keyboard.
* Once you are in insert mode, any key is taken as input for the file you are currently working on.
* To return to command mode and save the changes you have made, press the Esc key.

## How to use vi editor

To launch the vi editor, open the terminal (CLI) and type:

vi <filename_NEW> or <filename_EXISTING>

If you specify an existing file, the editor opens it for you to edit. Otherwise, it creates a new file. The screenshot below shows a new file being created and edited in vi.

[](https://www.guru99.com/images/Creating%5Fa%5Fnew%5Ffile.png)

### RELATED ARTICLES

* [File Permissions in Linux / Unix: How to Read, Write & Change ](https://www.guru99.com/file-permissions.html "File Permissions in Linux / Unix: How to Read, Write & Change")
* [Best Linux Certifications for Beginners (2026 Update) ](https://www.guru99.com/best-linux-certifications.html "Best Linux Certifications for Beginners (2026 Update)")
* [Linux Command Cheat Sheet ](https://www.guru99.com/linux-commands-cheat-sheet.html "Linux Command Cheat Sheet")
* [6 Best Free TFTP Server for Windows (Aug 2026 List) ](https://www.guru99.com/free-tftp-server.html "6 Best Free TFTP Server for Windows (Aug 2026 List)")

## VI Editing commands

The vi editing commands below let you insert, delete, and change text. Use them from command mode.

| Command | Description                                                                                     |
| ------- | ----------------------------------------------------------------------------------------------- |
| i       | Insert at cursor (goes into insert mode)                                                        |
| a       | Write after cursor (goes into insert mode)                                                      |
| A       | Write at the end of line (goes into insert mode)                                                |
| ESC     | Terminate insert mode                                                                           |
| u       | Undo last change                                                                                |
| U       | Undo all changes to the entire line                                                             |
| o       | Open a new line (goes into insert mode)                                                         |
| dd      | Delete line                                                                                     |
| 3dd     | Delete 3 lines                                                                                  |
| D       | Delete contents of line after the cursor                                                        |
| C       | Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion. |
| dw      | Delete word                                                                                     |
| 4dw     | Delete 4 words                                                                                  |
| cw      | Change word                                                                                     |
| x       | Delete character at the cursor                                                                  |
| r       | Replace character                                                                               |
| R       | Overwrite characters from cursor onward                                                         |
| s       | Substitute one character under the cursor and continue inserting                                |
| S       | Substitute entire line and begin inserting at the beginning of the line                         |
| \~      | Change case of individual character                                                             |

**Note:** You should be in command mode to execute these commands. The vi editor is case-sensitive, so make sure you type the commands in the right letter case. Pressing the wrong command can make undesirable changes to the file. You can also enter insert mode by pressing a, A, or o as required.

## Moving within a file

You need to be in command mode to move within a file. The default navigation keys are listed below, but you can also use the arrow keys on the keyboard.

| Command | Description       |
| ------- | ----------------- |
| k       | Move cursor up    |
| j       | Move cursor down  |
| h       | Move cursor left  |
| l       | Move cursor right |

## Saving and Closing the file

You should be in command mode to exit the editor and save changes to the file. The commands below cover the common ways to save and quit.

| Command  | Description                     |
| -------- | ------------------------------- |
| Shift+zz | Save the file and quit          |
| :w       | Save the file but keep it open  |
| :q!      | Quit vi and do not save changes |
| :wq      | Save the file and quit          |

The screenshot below shows a file open in the vi editor, ready to be saved and closed.

[](https://www.guru99.com/images/vi-editor.jpg)

## FAQs

🆚 What is the difference between vi and vim?

Vim stands for “Vi Improved” and is an enhanced version of vi. It adds features such as syntax highlighting, multilevel undo and redo, split windows, tabs, and word completion. The classic vi is available on nearly every Unix system, which is why its commands are worth learning.

🔍 How do I search for text in the vi editor?

In command mode, press / followed by the text and Enter to search forward, or use ? to search backward. Press n to jump to the next match and N to jump to the previous one. Searches are case-sensitive unless you change the setting.

📋 How do I copy and paste text in the vi editor?

In command mode, yy copies (yanks) the current line and p pastes it below the cursor. Use a number, such as 3yy, to copy several lines at once. Deleting with dd also places the removed text on the clipboard, so p can paste it elsewhere.

🔢 How do I display line numbers in the vi editor?

From command mode, type :set number (or :set nu) and press Enter to show line numbers along the left margin. Run :set nonumber to hide them again. Line numbers make it easier to jump to a specific line and to follow error messages.

🧰 How does the vi editor compare with nano?

Nano is a simpler editor that shows its shortcuts on screen and needs no separate modes, so beginners find it approachable. The vi editor has a steeper learning curve but is faster for experienced users and is installed on more systems by default, including minimal servers.

🔒 How do I open a file in read-only mode in vi?

Run vi -R filename, or use the view command, to open a file in read-only mode. This lets you browse and search safely without accidentally changing the contents. You can still force a write with :w! if you decide to save an edit.

🤖 How can AI assist beginners with the vi editor?

AI assistants can explain what an unfamiliar vi command does, translate a plain-English request into the right keystrokes, and troubleshoot mistakes. Machine-learning-based tools can also suggest the next edit, lowering the steep learning curve that vi is known for.

🤝 Can GitHub Copilot work inside Vim or Neovim?

Yes. [GitHub Copilot](https://github.com/features/copilot) offers an official plugin for Vim and Neovim that suggests code as you type in insert mode. It brings AI completion to the keyboard-driven workflow, though you still accept or reject each suggestion yourself.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/vi-editor-commands-in-linux-unix.png","url":"https://www.guru99.com/images/vi-editor-commands-in-linux-unix.png","width":"700","height":"250","caption":"VI Editor Commands in Linux/Unix","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/the-vi-editor.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/linux","name":"Linux"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/the-vi-editor.html","name":"VI Editor with Commands in Linux/Unix Tutorial"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/the-vi-editor.html#webpage","url":"https://www.guru99.com/the-vi-editor.html","name":"VI Editor with Commands in Linux/Unix Tutorial","dateModified":"2026-07-25T12:54:07+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/vi-editor-commands-in-linux-unix.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/the-vi-editor.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/emily","name":"Emily Carter","description":"I'm Emily Carter, a Linux Development Specialist with expertise in kernel development, system architecture, and performance tuning.","url":"https://www.guru99.com/author/emily","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/emily-carter-author-120x120.png","url":"https://www.guru99.com/images/emily-carter-author-120x120.png","caption":"Emily Carter","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Linux","headline":"VI Editor with Commands in Linux/Unix Tutorial","description":"The vi editor is the most popular and classic text editor in the Linux family.It works in two modes, Command and Insert. Command mode takes the user commands and the Insert mode is for editing text.","keywords":"linux, perl, apache, bigdata","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/emily","name":"Emily Carter"},"dateModified":"2026-07-25T12:54:07+05:30","image":{"@id":"https://www.guru99.com/images/vi-editor-commands-in-linux-unix.png"},"copyrightYear":"2026","name":"VI Editor with Commands in Linux/Unix Tutorial","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the difference between vi and vim?","acceptedAnswer":{"@type":"Answer","text":"Vim stands for \"Vi Improved\" and is an enhanced version of vi. It adds features such as syntax highlighting, multilevel undo and redo, split windows, tabs, and word completion. The classic vi is available on nearly every Unix system, which is why its commands are worth learning."}},{"@type":"Question","name":"How do I search for text in the vi editor?","acceptedAnswer":{"@type":"Answer","text":"In command mode, press / followed by the text and Enter to search forward, or use ? to search backward. Press n to jump to the next match and N to jump to the previous one. Searches are case-sensitive unless you change the setting."}},{"@type":"Question","name":"How do I copy and paste text in the vi editor?","acceptedAnswer":{"@type":"Answer","text":"In command mode, yy copies (yanks) the current line and p pastes it below the cursor. Use a number, such as 3yy, to copy several lines at once. Deleting with dd also places the removed text on the clipboard, so p can paste it elsewhere."}},{"@type":"Question","name":"How do I display line numbers in the vi editor?","acceptedAnswer":{"@type":"Answer","text":"From command mode, type :set number (or :set nu) and press Enter to show line numbers along the left margin. Run :set nonumber to hide them again. Line numbers make it easier to jump to a specific line and to follow error messages."}},{"@type":"Question","name":"How does the vi editor compare with nano?","acceptedAnswer":{"@type":"Answer","text":"Nano is a simpler editor that shows its shortcuts on screen and needs no separate modes, so beginners find it approachable. The vi editor has a steeper learning curve but is faster for experienced users and is installed on more systems by default, including minimal servers."}},{"@type":"Question","name":"How do I open a file in read-only mode in vi?","acceptedAnswer":{"@type":"Answer","text":"Run vi -R filename, or use the view command, to open a file in read-only mode. This lets you browse and search safely without accidentally changing the contents. You can still force a write with :w! if you decide to save an edit."}},{"@type":"Question","name":"How can AI assist beginners with the vi editor?","acceptedAnswer":{"@type":"Answer","text":"AI assistants can explain what an unfamiliar vi command does, translate a plain-English request into the right keystrokes, and troubleshoot mistakes. Machine-learning-based tools can also suggest the next edit, lowering the steep learning curve that vi is known for."}},{"@type":"Question","name":"Can GitHub Copilot work inside Vim or Neovim?","acceptedAnswer":{"@type":"Answer","text":"Yes. GitHub Copilot offers an official plugin for Vim and Neovim that suggests code as you type in insert mode. It brings AI completion to the keyboard-driven workflow, though you still accept or reject each suggestion yourself."}}]}],"@id":"https://www.guru99.com/the-vi-editor.html#schema-32713","isPartOf":{"@id":"https://www.guru99.com/the-vi-editor.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/the-vi-editor.html#webpage"}},{"@type":"VideoObject","embedUrl":"https://www.youtube.com/embed/pU2k776i2Zw","name":"VI Editor with Commands in Linux/Unix Tutorial","description":"The vi editor is the most popular and classic text editor in the Linux family.It works in two modes, Command and Insert. Command mode takes the user commands and the Insert mode is for editing text.","uploadDate":"2020-03-11T00:00:00+05:30","thumbnailUrl":"https://www.guru99.com/images/The_vi_editor(2).jpg","hasPart":[],"width":"560","height":"315","@id":"https://www.guru99.com/the-vi-editor.html#schema-508662","isPartOf":{"@id":"https://www.guru99.com/the-vi-editor.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"}]}
```
