Vim (III)

Source: Internet
Author: User

In Vim (1) and VIM (2), the concepts of the mode in vim and some simple text editing commands are introduced, such as the movement of the optical mark, selection, copying, cutting, and pasting of the editing area. Next, I would like to introduce how to fold and expand the text with preset indentation in Vim, and how to view and edit multiple texts at the same time.
I. Collapse and expand indentation

AsProgramForCodeIndentation is certainly not familiar. At the same time, many ides now provide the ability to fold or expand a piece of code that has been indented. We can also do this in VIM: first, we need to set the folding method: Set foldmethod = indent, then move the cursor over a piece of text with indentation (for example, set by <tab> Key), press ZC to fold the indentation, and press Zo to expand the indentation. This is just a simple example of indentation folding and expansion. There are a lot of related content, which will not be described here. You can use help folding to view details.

Ii. View and edit multiple documents

Most of the time, we need to open multiple documents for editing at the same time. Vim provides three methods for such operations:

    • Open multiple documents in different windows.
    • Open multiple documents in the same window.
    • Open multiple documents in different tabs.

1. open multiple documents in different windows

Generally, when multiple documents are opened in Vim, each document appears in a separate window. You can run the following command: B n switches between different document windows. N indicates the first opened document you want to switch to. For example, the current active window is the third opened document, if you want to switch to the first open document, you only need to execute: B 1. If you still remember, VIM mentioned in the previous section will read the edited document to the cache. In fact, B Represents buffer, so this command can be interpreted as buffer number 1. You can run the command: buffers or: ls to check the number of buffers currently opened. The following example provides an intuitive explanation:

    • Open the document test1.txt first. Related commands are as follows: E test1.txt
    • Then open the document test2.txt. The related commands are as follows: E test2.txt
    • Now the activity window is test2.txt. if you want to switch to test1.txt, you only need to: B 1.

2. open multiple documents in the same window

If you want to open multiple documents in the same window, you only need to execute the command: new in the current window to split the current window into two parts, open the relevant file in the new subwindow. To switch between different subwindows, you only need to press Ctrl-W <H, J, K, L> or Ctrl-W twice in a row. A special case of opening multiple files in a window is to present a document in two subwindows in two ways: in two horizontal subwindows: SP, in two vertical subwindows: VSP. SP indicates split. Run the Q command to close a subwindow.

3. open multiple documents in different tabs

This is a feature that I like very much, because browsers are indispensable in my life and I always need to open multiple tabs (CTRL/CMD-T) in the browser ). Run the "tabnew" command in VIM to open a new tab, and then open and edit the document in the tab. You can use the GT command to switch between different tabs. You can use the tabc or Q command to turn off a tab. Another command is tabmove, which moves the tab to the specified position.

References

1. http://www.swaroopch.com/notes/Vim

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.