Learning VI and VIM editor (7): Ex Editor overview (2)

Source: Internet
Author: User
Tags rewind switches

Then the previous article, learn the ex editor.

Change the buffer name:

you can save the current edit buffer as a new file by using the ": W new_file_name" method. This allows the current editing results to be saved without modifying the original file (provided that the current file has not been saved).

To save a subset of files:

you can save a portion of a file as a new file by using the line addressing command for ex and the Write command W. For example, the ": $ w new_file_name" command saves the 20th line of the current file to the end of the file as a new file, with the file name New_file_name.

Add content to a saved file:

with the Linux redirection operator (>>) plus the Write command (w), you can add part or all of the buffer to a file. For example, the " : 340, $w >> newfile" command appends the contents of line No. 340 of the current file to the end of the file to NewFile.

To copy a file to another file:

The ": Read file_name" command copies an existing file to the file that is currently being edited, and the command can be abbreviated as ": R file_name". This command inserts the contents of the file into the next line where the current cursor is located, and you can specify the location of the insertion by entering the line number before the Read or R command.

To edit multiple files:

The EX command allows us to switch between multiple files.

open multiple files at the same time with VI: when using VI, you can give multiple filenames at the same time, and then switch between files with the ex command. For example, "VI file1 file2" can first edit file1, after editing, enter the ": N" command to edit the next file, that is, file2.

Use the parameter list: In addition to using the ": N" command to switch to the next file, ": Args" (abbreviated as ": AR") can list the files on the command line. The file name you are currently editing is enclosed in square brackets, as shown in:


The ": Rewind" (abbreviated as ": rew") command switches the current file to the first in the list of file names. VIM provides a ": Last" command to switch the current file to the final one in the list of file names.

To invoke a new file:

In addition to opening multiple files at the beginning of an edit reply, you can also open a new file at any time through the ": E command". However, before opening a new file, you must use the ": W" command to save the current file, or VI will not let you use the ": E" or ": N" command to switch files , unless you add an exclamation mark after these commands, forcing you to ignore the limitation of VI. If you simply use ": e!" command to discard the editing results of the current file, directly back to the state of the current file once saved.

VI will also remember two file names as the current file name and alternate file name. The current file name can be expressed in%, and the alternate file name is denoted by #. So the ": E #" command switches to the standby file.

In addition to file switching with the EX command, the VI editor also provides a "Ctrl + ^" command for file switching. The function of this command is the same as ": E #", which is to switch to the candidate file.

make edits between files:

The concept of a named buffer has been mentioned before, and it can be simpler to move text from one file to another by using a named buffer. When you use the ": E" command for file switching, the contents of the named buffer are not purged. you can then save the text that you want to move to a named buffer, and then use the ": E" command to switch the contents of the corresponding named buffers into a new file to complete the text movement between the files.

Another way to implement text moving between files is through the ex command ": Ya" (drag) and ":p U" (placement). These two commands, combined with the row addressing function and the named buffer, also enable text movement between files.


This chapter VI command summarizes:

: W,:read,:r,:n,:args,:ar,:rewind,:rew,:last,:e,%,#,ctrl+^,:ya,:p U.


Learning VI and VIM editor (7): Ex Editor overview (2)

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.