You can get the advice from IT HELP DESK

SYSTEM[LINUX] vi Editor's Guide

18 Jan 2019
<head>Disk Management, Server Monitoring, System management, server monitoring, server management, system management, system monitoring, </head>

[LINUX] vi Editor's Guide

Hello ~!

This time I will try to learn about the VI editor ~

This is one of the most embarrassing things that many people have encountered with Linux OS!

How do I edit a file or document?  "  

But did you know that it is so convenient to know?

So this time, I want to learn how to use the VI editor, a text editor for Linux.

1. What is a VI Editor?

The vi editor is an abbreviation for the VIsual display editor. It is a text editor used by Linux and Unix.

It's easy to say that Windows provides features like Notepad.

But if you actually use the vi editor, you'll soon know it's not just a notepad.

With the vi editor, you can develop programs without a separate development tool, and you can edit documents quickly and easily using the many shortcuts that the vi editor supports.

So first, let's run the vi editor before we learn more about the vi editor.

To run the vi editor type vi <CR> at the Linux prompt.

Where <CR> is the symbol for entering Enter! Please refer to ~

If you type in vi and hit Enter, the vi editor will run as shown below.

[Figure 1 - VI editor execution screen]

The vi editor has two main modes.

  • Command Mode
    • The first time you run the vi editor, it will run in Command Mode.
    • You can not edit the document in this state.
    • You can use the hotkeys provided by the vi editor to move lines, copy strings, delete strings, save and exit files, and more.

  • Insert Mode
    • This is the mode you use to actually modify the string.
    • In Command Mode, you can enter Insert Mode by using specific hotkeys.

I also tried the vi editor, and I briefly see what mode it is.

Now let's see how you can actually modify the text with some commands.

2. Edit VI Editor Document Command

  1) Start VI

vi fileOpen file
vi file1 file2
Open file1 and file2 in order

  • This is the most basic way to use the vi editor.
  • The vi command is rarely used by itself, and you can modify the file by typing the name of the file you want to modify later.
  • If there is no file with the same name as the file name entered, create a new file and record the contents.

  2) Quit VI

Save to specified file
Save and quit vi
same as wq
same as wq
quit vi
Force quit vi without saving

  • If you enter a colon (:) command, it will be automatically entered at the bottom line of the vi editor, followed by the command for termination.
  • If you were editing a document through another command, you must enter the ESC key to exit edit mode and enter the vi editor exit command.

  3) Move cursor command

^   or   0
Move to the top of the line
Move to the end of the line
Move to the top line of the current viewing screen
Move to the middle line of the current viewing screen
Move to the bottom line of the current viewing screen
Move to the top line of the file
Go to the bottom line of the file
Move to nth line

  • This command is used to move the cursor before entering edit mode.
  • In previous versions of the vi editor, the h, j, k, and l keys were used to move the cursor up and down and left and right, but nowadays, you can move with the arrow keys alone.
  • If you are wondering how many lines, Use :set nu command to print the line number. 

  4) Edit mode command

Enter a character before the cursor
Type character after the cursor
Type character after the cursor
Enter characters from the end of the line where the cursor is located
Insert a blank line below the line with the cursor
Insert a blank line above the line with the cursor
Overwrite mode

  • These commands are used to switch from Command Mode to Insert Mode.
  • After inputting the command, the actual text can be edited.
  • Press the ESC key to return to Command Mode again from Insert Mode.

  5) Edit string command

Clear text behind the cursor
Clear text before the cursor
Clear current cursor line
Clear all data after one line of the cursor
Copy one line where the cursor is located
Copy 3 lines based on where the cursor is located
Insert the copied content behind the cursor
Insert the copied content before the cursor

  • These commands are commands that can be input in Command Mode.
  • In Insert Mode, press the ESC key to enter Command Mode, and you can delete or copy/paste characters using the above command.

  6) Find a string

/Words you want to find
Search for the word you want to find
Go to the next searched word
Go to the previous word found in the searched words

  • These commands are commands that can be input in Command Mode.
  • After searching for the word you want to find, you can use n/N command to move to the next or previous word.

I've read the vi editor so far. It's difficult at first, but if you continue to write it, you'll think it's as easy as this! I will continue to work hard ~ !!!

Enter all the pictures! 

#LINUX #VI #vieditor