Vi and vim Editor (1): vi Text Editor

Source: Internet
Author: User
Tags line editor

Vi and vim Editor (1): vi Text Editor

There are many editors in UNIX systems, which can be divided into two types: Row editor and full-screen editor. The row editor can only display one row of a file on the screen at a time, such as the ed and ex editors. The full-screen editor can display part 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 short for visual editor. The vi editor is a full-screen editor. You can modify the file while reading the file and immediately see the modified result. For beginners, the vi editor is still very difficult, but once you are familiar with the vi editor, you may not want to re-use other "simple" editors. When learning the vi editor, you should learn to hand over the editing work to the computer. This is the work of computers.

The vi editor has two modes: Command mode and insert mode. In command mode, everything entered is interpreted as the input command by the vi editor. In the insert mode, all input data is inserted into the editing file as input text. In the vi Editor, commands have the following features:

* The command is case-sensitive, that is, size-sensitive;

* When you enter a command, the command is not displayed on the screen;

* Enter is not required after the command is entered.

At the same time, a group of commands are displayed at the bottom of the screen, and there are special symbols before these commands, such as the colon (:) used to start all the ex commands. The bottom-layer editor used by the vi editor is the ex-line editor, and vi is only its visual mode. Therefore, you can use the ex editor command in the vi editor.

Since it is a text editor, you must first learn how to open and close files. You can use the vi editor to edit any text. Note that vi copies the file content to be edited to the buffer in the memory. Therefore, we only modify the copy of files in the memory, only by storing the file content in the buffer zone can the file editing result be updated to the file on the disk. The file content of the storage buffer is what we usually call "Writing Files" or "saving files ".

Open the file: vi [filename]

If filename is not specified, vi will open an unnamed buffer. When we write the content in the buffer to a file, we need to specify filename. If filename already exists, edit an existing file. If filename does not exist, this is equivalent to creating a new file (a file named filename is generated only when the created buffer is saved). When a new file is opened, the status bar at the bottom of the vi editor has a message ,:


Problems encountered when opening the file:

* You Should edit an existing File, but the vi editor displays "[New File]". The problem is that the file name you entered is incorrect.

* Messages such as [readonly] and "Permission denied" are displayed. This is because you do not have the write permission for the file or use the vi editor view mode (vi-R)

* When the q command is entered, the following warning is displayed: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20141013/2014101309165279.png" alt = "\">

This is because you have modified the file (You may not know where to modify it). Because the file has changed, the vi editor will definitely allow you to choose whether to save the editing result before leaving, therefore, you can use the ZZ command to save the Modification result and exit, or use q! Do not save the editing result and leave.

Save and exit files:

ZZ command: Save the editing result and leave the vi editor. You can also use the ex command to save the editing result. The w command only saves (writes) the editing result without leaving the editor. : The wq command saves the editing result and leaves the vi Editor (: wq is the same as the ZZ command)

End Without saving the editing result:

: E! Command: This command can delete all the editing results and directly return to the file content during the last storage, that is, it can be "started from scratch ". : Q! The command directly ignores the current editing result, returns to the file content during the last storage, and leaves the vi editor. Why are there exclamation points behind these two commands, because the e and q commands will make the current editing effect disappear, and the vi editor generally won't let you discard the editing result, therefore, after adding an exclamation point, you can make vi ignore this ban and directly discard the current editing result to return to the file content in the last storage.

Problems Occurred When saving the file:

* After writing for half a day, no write permission is found. You can use w filename to write the current result to a new file (because a new file is created in the directory, therefore, you need to write the file to a directory with write permission for you)

* Try to write the file, but find that the file system is full. There are many ways to solve this problem. On the one hand, you can write the file to a file system with the remaining space, and on the other hand, you can directly enter :! Sh returns to the shell environment to delete some large files in the current file system. In the ex command, you can use the exclamation point followed by the UNIX Command to directly execute the corresponding UNIX Command. As shown in, enter :! Pwd displays the current directory:


After the command is entered, the vi editor is temporarily exited and the command execution result is displayed:

Press enter to return to the vi editor.

Summary of the vi editor commands in this chapter:

ZZ,: w,: q,: wq,: q !, : E! .


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.