Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the split screen operation method of Vim?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the split-screen operation method of Vim". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the split-screen operation method of Vim".

Basic operation of split screen function

First of all, let's open a random code file. For demonstration purposes, the longer the code, the better.

Vim test.c

Now let's divide the interface into left and right parts. First we press ctrl+w, followed by v. After doing this, the screen is split in two, as shown below:

What do we do if we want to divide into three parts? Very simply, on the basis of the above, we perform the above operation again, and the screen will be divided into three parts.

If you find this too troublesome, we can also achieve the same effect by executing the following command in the last line mode:

: vsplit

Since it's an order, there must be an acronym:

: vsp

It's ridiculously simple... Let's start from scratch. This time we will split the screen horizontally. First, let's run the following command in the last line mode:

: split

Similarly, we also have abbreviated commands:

: sp

This function can also be achieved through keyboard key combinations. For split horizon, press ctrl + w and then s. Again, all these letters are lowercase and are in the English input state.

Switch between screens

As mentioned earlier, split view is very useful in many scenarios, but if you can't switch from one split to another, then this split view is completely meaningless. Let me show you how to switch from one split to another.

Here, I set up four split views of the same file.

At the beginning, the cursor is at the first split screen. Now, if we want to switch to the right split screen, we need to press ctrl + w and then l.

Similarly, if we want to switch to the left window, we need to press ctrl + w and then h.

If you split the screen horizontally, you can only move the cursor up and down. To switch to the split screen above, press ctrl + w and then k.

Similarly, if you want to switch to the split screen below, you need to press ctrl + w and then j.

Edit under different split screens

So far, I believe you have learned how to split the screen. So after dividing the screen, how can we edit the text under these split screens? In fact, each split screen can be regarded as a complete Vim window, how we usually edit, how to edit the document.

Copy and paste operation

There is basically no difference between unsplit screen and unsplit screen, you can copy a piece of text from one split screen, and then switch to another split screen to paste. The operation is all the same, but you just need to switch between different screens.

Change the split screen size

By default, Vim splits the screen on an equal basis. What if we want to maximize / minimize a split screen?

If you want to widen the current window to the maximum size, press ctrl + w, and then press | (Note: it is not lowercase L, the and / or non-and |).

If you want to increase the height of the current window to the maximum size, you need to use ctrl + w, and then use _.

So if you want to resize all split windows, use ctrl+w and press =.

By default, when Vim splits, each split is equal in width or height. To customize the width of the split screen, you can use the following structure:

: vsp

Similarly, for split horizon, you can customize the height using a similar structure:

: sp

Open multiple different files under the same Vim window

So far, all Vim splits are copies of the same file, but in many cases, we need to open multiple different files. We can split the Vim window and open different files in different screens.

How do I open a new file in Vim? We can use the following command:

: e/filename.extension

For example, if we want to open vimrc in a completely new Vim instance, we can use the following command:

: e~/.vimrc

After opening vimrc, we want to split the screen horizontally and open a new file, using the following command:

: sp

For vertical split screens, a similar structure is used:

Vsp Thank you for your reading. The above is the content of "what is the split-screen operation method of Vim". After the study of this article, I believe you have a deeper understanding of what the split-screen operation method of Vim is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report