Learn VI and VIM editor (1): VI text Editor

Source: Internet
Author: User
Tags save file line editor

There are many editors in Unix systems that can be divided into two types: the line editor and the full screen editor. The line editor can display only one line of the file at a time, such as the Ed and ex editors, and the full-screen editor displays a portion of the file on the screen.

The VI (read as Vee-eye) editor is a standard text editor for the Unix_like operating system. VI is the abbreviation of Visual editor , the VI editor is a full-screen editor, can be modified on the spot when reading a file, and immediately see the modified results. For beginners, the VI editor is very difficult, but once you are familiar with the VI editor, you may never want to re-use other "simple" editors. When you learn VI editor, you should learn to hand over the editing work to the computer. Because this is the work of the computer.

There are two modes of the VI Editor: Command mode and insert mode. In command mode, everything you enter will be interpreted by the VI editor as the input command. In insert mode, everything you enter is inserted into the file you are editing as input text . In the VI Editor, commands have the following characteristics:

* commands are case-sensitive, that is, size-sensitive;

* commands are not displayed on the screen when the command is entered;

* You do not need to enter the ENTER key after entering the command.

There is also a set of commands that appear at the bottom of the screen, preceded by a special symbol such as a colon (:) to start all the ex commands. the bottom editor used by the VI editor is the ex line editor , and VI is just its visual mode. So you can use the EX editor commands in the VI editor.

Since it is a text editor, the first thing you need to learn is how to open and close files. You can use the VI editor to edit any text, it is necessary to note that VI will need to edit the contents of the file to be copied into the buffer in memory, so we modify only the memory of the file in the copy, only the contents of the buffer file to be stored in order to update the file's editing results to the file on disk. the file content of the storage buffer is what we usually call "write file" or "Save File".

Open file: vi [filename]

If you do not specify filename, then VI will open an unnamed buffer, and when we write the contents of the buffer to the file, we need to specify the filename. If filename is already present, it is an existing file, and if filename does not exist, it is equivalent to creating a new file (you will need to save the created buffer to actually produce a file named filename), and when you open a new file, The bottom status bar of the VI editor will have the corresponding message:


Problems when opening a file:

* You think you should edit an existing file, but the VI editor displays "[New file]". This question can be sure that the file name you entered is wrong.

* appears as shown in [ReadOnly], "Permission denied" and other messages. This is because you do not have write access to the file or use the VI Editor's view mode (VI-R)

* Input: Q command left, but the following warning appears:

This is because you modified the file (most likely you do not know where to modify), because the file has changed, the VI editor will let you choose whether to save the edits to leave, so you can use the ZZ command to save the results and then exit, or use: q! Do not save edits and leave.

Save and leave the file:

ZZ Command: Save the editing results and leave the VI editor. You can also use the EX command to save the results of your edits: the W command saves (writes) only the results of the edits and does not leave the editor. : Wq command saves edit result leave VI editor (: Wq same as ZZ command)

End without saving editing results:

: e! Command: This command eliminates all editing results and goes directly back to the file contents of the most recent storage, meaning "start over". : q! The command also ignores the current edits directly and goes back to the file contents of the last save and leaves the VI editor. Why are there exclamation points behind both commands, because: the E and: Q command will let the current editing effect disappear, and VI editor generally will not let you abandon the editing results, so add exclamation point, you can make VI disregard this ban , directly to the current editing results abandoned, Returns the contents of the file when it was last saved.

Issues that occur when you save a file:

* Written for half a day, found no write permission. You can use: w filename to write the current result to a new file (because a new file is created in the directory at this time, so you need to write the file to a directory that has write permissions for you)

* Try to write the file, but found that the file system is full. This workaround consists of a number of files that can be written to the file system with the remaining space and can be entered directly on the other side:!sh back to the shell environment to remove some large files from the current file system. in the ex command, you can use the exclamation mark followed by the Unix command to execute the corresponding UNIX command directly. as shown, enter:!PWD Displays the current directory:


After the command is entered, the VI editor is temporarily exited, showing the result of the command execution:

You can return to the VI editor when you press the ENTER key.


This chapter VI editor commands summarize:

Zz,:w,: Q,: Wq,: q!,: e!.



Learn VI and VIM editor (1): VI text Editor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.