How to Split Vim Screen Horizontally and Vertically in Linux

Channel: Vim Editor Editors Linux
Abstract: followed by the - (minus) sign. Decrease Vim Workspace Height To ensure the height of the upper and lower workspaces is equal press Ctrl + wfollowed b

Vim text editor, short for Vi IMproved, is one of the most powerful and popular Linux text editors that enjoys immense patronage from the open-source community. It is an improvement of the vi editor and uses a combination of regular keyboard keys to provide vast functionality.

Vim provides colored syntax among other basic functionalities such as inserting and deleting text, copying and pasting text, and saving changes made to a file. The list of what you can do is quite long and the learning curve is steep.

In this guide, we endeavor to show you various ways that you can split the Vim editor into different workspaces in the Linux command-line.

Installing Vim in Linux

Before we proceed, ensure that Vim is installed on your system. Also, this guide is intended for users running a system with a graphical display so as to observe the split effect of the vim editor on the terminal.

To install vim, run the following commands:

$ sudo apt install vim      [On Debian, Ubuntu & Mint]
$ sudo yum install vim      [On RHEL, CentOS & Fedora]
$ sudo pacman -Sy vim       [On Arch & Manjaro]
$ sudo zypper install vim   [On OpenSUSE]

Running the vim command without any arguments displays basic information about the Vim editor including the version and basic commands such as how to get help and exit the text editor as shown below.

$ vim
Start Vim Editor Splitting Vim Screen Vertically

Suppose you have opened a file on Vim editor and you want to split it vertically. To achieve this:

  • Enter command mode by pressing the ESC button.
  • Press the keyboard combination Ctrl + w, followed by the letter ‘v’.

You will get a split-screen shown below.

Splitting VIM Screen Vertically

To navigate to the right pane, press Ctrl + w, followed by the letter ‘l’.

Navigate VIM Screens

To head back to the left pane, use the combination Ctrl + w, followed by the letter ‘h’.

Splitting Vim Screen Horizontally

To split the vim screen horizontally, or open a new workspace at the bottom of the active selection, press Ctrl + w, followed by the letter ‘s’. In the example below, the left section has been split into two workspaces.

Splitting VIM Screen Horizontally

To navigate to the bottom section hit Ctrl + w, followed by the letter ‘j’.

Navigate to Bottom VIM Screen

To head back to the upper section, press Ctrl + w, followed by the letter ‘k’.

Navigate to Upper VIM Screen Increase Width of Vim Current Workspace

To increase the width of your current selection on the Vim editor, press Ctrl + w, and shortly followed by the SHIFT + ‘>’ combination.

In the example below, I have increased the width of the left pane.

Increase Vim Workspace Width

To reduce the width of your current Vim selection, press Ctrl + w, and then SHIFT + ‘<’ combination.

In the screenshot below, you can clearly see that the left section has reduced in width.

Reduce Vim Workspace Width Increase Height of Vim Current Workspace

To increase the height of your current workspace, use the combination press Ctrl + w, followed by SHIFT + ‘+’ combination. The illustration below shows

Increase Vim Workspace Height

To decrease the height of the workspace, press Ctrl + w, followed by the - (minus) sign.

Decrease Vim Workspace Height

To ensure the height of the upper and lower workspaces is equal press Ctrl + w, followed by the = (equals) sign.

Set Equal Sizes of Vim Workspace

And that’s how you can split the Vim screen into various spaces.

Ref From: tecmint
Channels: Vim Tips

Related articles