# vi / vim

**How it works**

* The Unix command vi starts up the visual editor.
* Typing vi followed by a file name will automatically open the file.
* After issuing the command, the appearance of your screen changes. Rather than seeing the shell prompt, the content of the file filename.txt appears on the screen. If filename.txt hadn't existed before you invoked the vi command, the screen will appear mostly blank.

```
vi filename.txt
```

**Modes**

* One of the fundamental concept to keep in mind when using vi is that three modes exist: command, insert, and visual.
* In command mode, everything you type on the keyboard gets interpreted as a command.
* In insert mode, most everything you type on the keyboard gets interpreted as characters and will appear in your file--letters, numbers, punctuation, line returns, etc.
* When you are in insert mode, you can switch to command mode by pressing the Esc key on your keyboard (this is often at the left and upper portion of your keyboard).
* When you are in command mode, there are many keys you can use to get into insert mode, each one gives you a slightly different way of starting to type your text. For example, if you are in command mode, you can simply type i on your keyboard to enter insert mode (i stands for insert). Then, the characters you type go into the file.

**Basic commands**

* h = move one character to the left
* l = move one character to the right
* k = move up one line
* j = move down one line
* \[ctrl] b = move back one screen
* \[ctrl] f = move forward one screen
* quit Vi without saving anything (you'll lose any changes you made when using this command) type:  :q!
* save/write the file you're working on without exiting type:  :w followed by a filename
* save/write your file and quit the vi editor in one step by typing:  :wq


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igb.mit.edu/mini-courses/introduction-to-unix-and-ki-computational-resources/basic-unix/unix-text-editors/vi-vim.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
