Most of Linux Users and administrators used vim for their daily work while editing, creating , reading OS files, debug configuration files, working while scripts for automation etc. So in short there is widely used editor used in Linux machines. So this is very powerful and flexible editor that provide us wide range of options to work and expand our capabilities. In this post we will see How to split Vim Editor Windows

One of its feature, Which i like most is splitting of vim editor windows which allow us to view, understand and work on multiple portion of file which are not fit in same window.

Use case

This is is really very good feature which i personally used a lot while working on long line scripts like in a script sometime we need to see one of its part and accordingly need to change on another part of it which is not fit in my small screen of laptop

Let’s see how we could split vim screen in this way which makes us easy to work in many scenario.

Create Split Windows

To split vim screen, we need to use below commands, in command mode.

:sp  -- Horizontal Split

:vsp -- Vertical split

Usually we used only above commands to split vim windows, but we have some shortcuts to work for it, like mention below.

ctl+w s -- Horizontal Split

ctl+w v -- Vertical Split

So as we used ctl+w, it is super key to work on most vim split windows.

In case we like to open multiple files in from scratch, we can also used to open it through vim command as well like below command.

vim -o file1 file2 -- Open mention files in horizontally 

vim -O file1 file2 -- Open mention files in vertically 

Move within Split Windows

We can create many split windows in vim and open many different files in it to edit, So we can jump on these multiple vim windows through many key stocks like below.

ctl+w w -- Move cursor to next window

ctl+w <right/left/up and down> -- Cursor right,left, up and down between vim window split

ctl+w <l/h/k and j> -- Cursor right,left, up and down between vim window split

Resize Split Windows

Now while working with these files, we might need to resize these windows in many ways, we have some of very common ways to resize vim split windows.

ctl+w N> -- with use of greater sign we could push windows limit to right hand side 

ctl+w N< -- with use of lesser sign we could push windows limit to left hand side

Above method works fine with vertical vim split windows, but what about Horizontal vim split. How we could work with those split, for those we could like below mention.

ctl+w N+ -- With Ctl+w and plus sign will increase vim windows size, in case we use any number with plus sign that will further increase size.
 
ctl+w N- -- With ctl+w and minus sign will decrease vim windows size, in case we use any number with minus sign that will further decrease size.

We can close vim split windows with ctl+w c. But you can close last windows this way. For last windows you have to close it with vim execute quit command.