vi is a screen-oriented text editor originally created for the Unix operating system. The name "vi" is derived from the shortest unambiguous abbreviation for the ex command visual, which switches the ex line editor to visual mode.
vi is included in the most popular Linux distros like Ubuntu, Linux Mint or Debian. Also you can use it in another UNIX based systems like FreeBSD, OpenBSD or MINIX.
vi editor has the following operation modes-
1. Command mode
Administrative tasks such as saving files, executing commands, moving the cursor, cutting and pasting lines or words, and finding and replacing.
2. Text mode
This mode enables you to insert text into the file.
Writing a very small C program using vi:
3. vi is in command mode by default, if you want to write something, you can’t do it.
4. Type “i”, it enables you to write your code.
5. Now you’re in the insert mode, but if you want to delete a character you can’t do it.
6. Type ESC to change to command mode
7. In command mode, Type “x”, it should delete the character under the cursor
8. You can insert a character to the left of the cursor Typeing “i”
9. You can insert a character to the right of the cursor Typeing “a”
10. Insert “>” in the text
11. Go back to the command mode and type :wq, then type return
12. Now you’re in the prompt again, see the content of your file using cat:
13. Now you should thinking that vi is very complicated, vi isn’t a complicated editor, rather it’s different because vi can only work in one mode at a time.
14. Open your file again (vi file.c) and write the following code:
printf(“vi is a great tool to write code faster ”);
15. Save your file, and if you have gcc installed you should compile and run it.
Vi common options to open a file:
Vi common commands (you must be in command mode):
Copy and Paste commands in vi Editor ( Practice! )
3. Change to the command mode (ESC)4. Move the cursor to “Ubuntu”
5. Type yy (this is the command to copy one line)
6. Type G
7. Insert a new line Typing o
8. Change to command mode (ESC)
9. Type P (this the command to paste the line)
10. Type 1G
11. Type 4yy
12. Type G
13. Type P
14. Also you can use another copy - paste commands
vi Editor Advanced commands
Working with two or more files (Practice !)
3. Write “UNIX is a good OS” and save it.
4. Go to linux-distros file using the command ‘:e #’
5. Exit from vi typing :q
If you want to know more about vi you can visit the following links:
Most Read Articles
Translate Our Site
Notice : Please be careful, after translation commands will change.
This website uses marketing and tracking technologies. Opting out of this will opt you out of all cookies, except for those needed to run the website. Note that some products may not work as well without tracking cookies.Opt Out of Cookies