Home > Operation and Maintenance > Linux Operation and Maintenance > Learn all aspects of Vim split-screen operation in 5 minutes

Learn all aspects of Vim split-screen operation in 5 minutes

Release: 2023-08-03 15:20:58
forward
1373 people have browsed it

#The Vim split-screen function is implemented by splitting windows, which is a great tool for improving work efficiency. Whether we want to display two files at the same time, or display two different locations of a file at the same time, or compare two files side by side, etc., these can be achieved through split screen, which is very convenient for code comparison and copy and paste.

Learn all aspects of Vim split-screen operation in 5 minutes

Split the screen horizontally to open a new file

:sp linuxmi.py
Copy after login

or

:split linuxmi.py
Copy after login

This command splits the window horizontally for two windows, and place the cursor in the upper window.

Learn all aspects of Vim split-screen operation in 5 minutes

Open a new file in vertical split screen

:vsp linux.py:vsplit linux.py
Copy after login
Learn all aspects of Vim split-screen operation in 5 minutes

:sview linux.py ->只读分屏打开文件
Copy after login

In addition, when you want to open a window to edit a new file, you can use the following command: :new

从命令行直接打开多个文件且是分屏

vim -On file1, file2 ... ->垂直分屏vim -on file1, file2 ... ->水平分屏linuxmi@linuxmi:~/www.linuxmi.com$ vim -O3 linux.py linuxmi.py linuxmi.cpp
Copy after login
Learn all aspects of Vim split-screen operation in 5 minutes
Learn all aspects of Vim split-screen operation in 5 minutes

注:-O垂直分屏,-o水平分屏,n表示分几个屏。扩展:这些书,真tm肝……

另外搜索公众号Linux就该这样学后台回复“git书籍”,获取一份惊喜礼包。

实时调整当前窗口的宽度

  • ctrl-w > //向右加宽,默认值为1

  • ctrl-w N > //向右加宽宽度N

  • ctrl-w < // 同理

横屏/竖屏分屏打开当前文件

  • ctrl w s

  • ctrl w v

Switch split screen

  • ##ctrl w h,j,k,l

  • ##ctrl w Up, down, left and right keys

  • crtl w Switch between split-screen windows. After pressing, press another w

  • crtl wTo switch between split-screen windows, press r again to swap windows

  • crtl wTo switch between split-screen windows, press After finishing, press c again to close the window

Close split screen

There are several commands to close the window:

  • ctrl W c Close the current window

  • ##ctrl w q Close the current window, if there is only one split screen and exit vim
  • :only keep the current split screen
  • :hide close the current split screen

调整分屏的大小(宽度与高度)

  • ctrl+w = 所有分屏都统一高度

  • ctrl+w + 增加高度,默认值为1

  • ctrl+w - 减少高度

  • 10 ctrl+w + 增加10行高度

  • ctrl-w N + //当前屏高度加N

使用指定当前屏的调整高度

: res[ize] N
Copy after login

示例:

:resize 30
Copy after login

移动分屏:ctrl+W H,J,K,L

将屏幕移动到最顶端:ctrl-w + K

将屏幕移动到最低端:ctrl-w + J

将屏幕移动到最左边:ctrl-w + H

Move the screen to the far right: ctrl-w L

The above is the detailed content of Learn all aspects of Vim split-screen operation in 5 minutes. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vim
source:Linux中文社区
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template