Master Vim Split Windows: Horizontal, Vertical, and Dynamic Resizing Commands
This guide explains how to use Vim's split window feature—including horizontal and vertical splits, opening multiple files from the command line, adjusting pane sizes, navigating between splits, and closing them—providing concrete commands and shortcuts to boost coding efficiency.
Overview
Vim's split window capability lets you view and edit multiple files or different parts of the same file simultaneously, greatly improving code comparison, copying, and overall productivity.
Horizontal Split
Open a new file in a horizontal split with: :sp linuxmi.py or :split linuxmi.py The command divides the screen into two panes stacked vertically, placing the cursor in the upper pane.
Vertical Split
Open a new file in a vertical split with: :vsp linux.py or
:vsplit linux.pyRead‑Only Split
Open a file in a read‑only split:
:sview linux.pyOpening Multiple Files with Splits from the Command Line
Use the following options when launching Vim: vim -O file1 file2 … – vertical splits vim -o file1 file2 … – horizontal splits
Example:
vim -O3 linux.py linuxmi.py linuxmi.cppAdjusting Split Size
Resize panes using ctrl‑w shortcuts: ctrl‑w = – make all panes equal height ctrl‑w + – increase height by 1 ctrl‑w - – decrease height by 1 10 ctrl‑w + – increase height by 10 lines ctrl‑w N + – increase height by N lines
Directly set height with: :resize 30 or
:res NMoving Between Splits
Navigate using: ctrl‑w h/j/k/l – move left/down/up/right ctrl‑w ←/↑/→/↓ – arrow keys ctrl‑w H/J/K/L – move the current pane to the far left/bottom/top/right
Closing Splits
Close panes with: ctrl‑w c – close current pane ctrl‑w q – close current pane; if it’s the only one, exit Vim :only – keep only the current pane :hide – hide the current pane
Summary
Because Vim is used frequently, mastering its split‑window commands simplifies working with multiple files and improves editing efficiency.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
