Vi and vim Editor (7): ex editor Overview (2), vimex

Source: Internet
Author: User
Tags rewind

Vi and vim Editor (7): ex editor Overview (2), vimex

Next, I wrote an article to learn about the ex editor.

Change the buffer Name:

You can use ": w new_file_name" to save the current editing buffer as a new file. In this way, the current editing result can be saved without modifying the original file (provided that the current file has not been saved ).

Save some files:

You can save a part of the file as a new file by using the line addressing command and writing command w of ex. For example, run the ": 20, $ w new_file_name" command to save the 20th line of the current file to the end of the file as a new file named new_file_name.

Add content to saved files:

You can add part or all of the buffer content to a file by adding the write command (w) to the redirection operator (>) in Linux. For example, the ": 340, $ w> newfile" command will append the content of the current file 340th line to the end of the file to newfile.

Copy one file to another:

Run the ": read file_name" command to copy an existing file to the file being edited. This command can also be abbreviated as ": r file_name ". This command inserts the file content into the next row where the current cursor is located. You can specify the insert position by entering the row number before the read or r command.

Edit multiple files:

The ex command allows us to switch between multiple files.

Use vi to open multiple files at the same time:When using vi, you can give multiple file names at the same time, and then use the ex command to switch between files. For example, "vi file1 file2", you can edit file1 first, and then enter the ": n" command to edit the next file, that is, file2.

List of parameters used:In addition to the ": n" command to switch to the next file, ": args" (abbreviated as ": ar") can list the files on the command line. The file name being edited is enclosed in square brackets, as shown in:


The ": rewind" (abbreviated as ": rew") command switches the current file to the first in the file name list. Vim provides the ": last" command to switch the current file to the last one in the file name list.

Call a new file:

In addition to opening multiple files at the beginning of the edit session, you can also open new files at any time using the ": e command. However, before opening a new file, you must use the ": w" command to save the current file. Otherwise, vi will not allow you to use the ": e" or ": n" command to switch files, unless an exclamation mark is added after these commands, the vi restrictions are forcibly ignored. If you simply use ": e! "Command can discard the editing result of the current file and directly return to the status when the current file was last saved.

Vi remembers two file names at the same time as the current file name and Alternate file name. The current file name can be represented by %, and the alternate file name is represented. Therefore, the ": e #" command can be switched to the alternate file.

In addition to using the ex command to switch files, the vi editor also provides the "ctrl + ^" command to switch files. Similar to ": e #", this command is used to switch to candidate files.

Edit files:

We have already talked about the concept of named buffer. Using Named buffer, we can move text from one file to another. When you use the ": e" command to switch files, the content in the named buffer is not cleared. Therefore, you can save the text to be moved to a named buffer, and then use the ": e" command to switch the file, then place the content of the corresponding named buffer in the new file, you can move text between files.

Another way to move text between files is through the ex command ": ya" (drag) and ": pu" (placement ). These two commands, combined with the line addressing function and the naming buffer, can also achieve text movement between files.


Summary of the vi commands in this chapter:

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


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.