This is pretty simple to do. It’s also very usable if you just want to compare 2 files or different sections on the same file. Here’s what you do while in vi or vim.
Split screen horizontally
The above code will split vi horizontally like the screenshot below. You can also supply an optional filename. If you do, it’ll open new file on the second window.
Split screen vertically
Unsurprisingly, the above code will split vi vertically like the screenshot below. Just like :split command above, :vsplit will also take optional filename that if supplied will open the named file on the new screen instead.
Navigating between screens
Navigating between split-ed screens is pretty easy in vi. Just type ctrl-w ctrl-w (that is twice ctrl-w) to jump between screens. You can also use ctrl-w then arrow key to move to different screens. This is useful if you split screens into more than 2 like below.
To unsplit / close split-ed screens
This section is suggested by Vic Kovacs, thank you. To unsplit or close a split-ed screens, simply navigate to the screen that you’d like to unsplit / close, then simply type :q to quit editing that screen.
To resize split-ed screens
This section is suggested by Andaluz, thank you. To resize the split-ed screens,
- For horizontal split, navigate to the screen that you wish to resize, then type ctrl-w then + or – to increase or decrease horizontal size by 1. You can also type the number before hitting ctr-w + / – to resize by the specified number. For example, 10 ctrl-w +, will increase the window size by 10.
- For vertical split, navigate to the scren that you with to resize, then type ctrl-w then > or < to increase or decrease vertical size by 1. SImilarly, you can also type the number to resize by other than 1.
There you have it. And as always, I welcome comments / questions / critics that will help me and other readers understand better.