VI commands for opening and editing multiple files

Source: Internet
Author: User
Bytes

There are two possible cases:

1. open multiple files in the same window:
VI file1 file2 file3
: N switch to the next file (n = NEXT)
: N switch to the previous file
2. open multiple files in different windows:
If you have already opened a file,
In the command input state of VI, enter the path and file name of another SP file,
In this way, you can open multiple files in a window.
Or use vi-O file1 file2 file3. .. To open multiple files at the same time in a split screen window.
You can press Ctrl + twice to press W or Ctrl + W and then press the up or down key to switch between the upper and lower windows.

Split windows to edit multiple files

* Use VI to open a file, for example, VI actinia_proenrule.sh *. Open another file in command line mode and Enter SP to split the file horizontally to continue opening the second file, to vertically split a file, you can use the VSP file name. Note: sp = Split, VSP = vsplit. the preceding statement is a simple statement supported by VI, and V is actually vertical. We can see the meaning of the command change. In addition, Vi not only supports two files, more files can be displayed and edited in a large window at the same time, and the two files simultaneously opened are the same file.

* Window Switching

You can press Ctrl + twice to press W, so that you can find it inconvenient to edit multiple VI Documents before switching between files. Now you have several contacts and have used minibufexplorer, it seems uncomfortable. It is better to use ls. : Ls to show all open documents: Switch XN to the X down document N Ctrl + 6: switch to the N buffer Ctrl + 6 or: E # return to the previous editing File

Split screen

: New XXX Ctrl + w s display Ctrl + w Q on the current document content split screen Ctrl + w Q close the split screen Ctrl + w o only display the current split screen content Ctrl + w j k up and down select split screen

I personally think the most useful command is Ctrl + W to quickly switch between the two screens on the split screen.

I haven't written the following ~ After reading this article, I think these are pretty good.

: N1, N2 Co N3: copy the content from line N1 to line N2 to line N3.

: N1, N2 M N3: Move the content from line N1 to line N2 to line N3

: N1, N2 D: Delete content from line N1 to line N2

: N1, N2 W! Command: The content from line N1 to line N2 in the file is used as the command input and executed,

If N1, N2 is not specified, the entire file is used as the command input.

The advantage of method 2 is that you can directly use the nyy and PP commands to copy and paste files in each window, which is more convenient. Summary of basic commands:: Ls or: ARGs display each file name in the editing list: N read to the next file in the editing list: N read to the previous file in the editing list: rew read to the first file in the editing list: e # Read the last edited file: BD closes the current edited file and is used in multiple file edits. Q is to close the VI window. BD is to close the current edited window, which is equivalent to a subwindow. : E file: Read another file into VI (this file may not be in the editing list). If the original file has not been archived after modification, archive it with W. : E! File forces reading another file into VI. The original file is not archived. PS (postscript): ls result list explanation, 1 ~ 8. Order of multiple files % A, current file being edited #. More articles about the last file being edited: switch between multiple files edited in VI

VI commands for opening and editing multiple files

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.