Windows and Splits
A window is a viewport into a buffer. You can split the screen into multiple windows, each displaying a different buffer (or even the same buffer at a different position).
Core Idea
Windows are the visual frames. Buffers are the content. Multiple windows can show the same buffer — useful for comparing two sections of a long file.
Creating Splits
:vsplit :vs → vertical split (side by side)
:split :sp → horizontal split (top/bottom)
:vsplit filename → vertical split opening file
:split filename → horizontal split opening file
Keybindings
Ctrl+w v → vertical split
Ctrl+w s → horizontal split
Ctrl+w n → new empty vertical split
Navigating Windows
Ctrl+w h → focus window left
Ctrl+w l → focus window right
Ctrl+w j → focus window below
Ctrl+w k → focus window above
Ctrl+w w → cycle to next window
Ctrl+w p → previous (last focused) window
Vim-style Navigation Keymaps
~/.config/nvim/lua/config/keymaps.lua
-- Navigate splits like tmux panes
vim.keymap.set('n', '<C-h>', '<C-w>h', { desc = "Window left" })
vim.keymap.set('n', '<C-l>', '<C-w>l', { desc = "Window right" })
vim.keymap.set('n', '<C-j>', '<C-w>j', { desc = "Window below" })
vim.keymap.set('n', '<C-k>', '<C-w>k', { desc = "Window above" })
Resizing Windows
Ctrl+w + → increase height
Ctrl+w - → decrease height
Ctrl+w > → increase width
Ctrl+w < → decrease width
Ctrl+w = → equalize all window sizes
:resize 30 → set height to 30 lines
:vertical resize 80 → set width to 80 columns
Moving Windows
Ctrl+w H → move window to far left
Ctrl+w L → move window to far right
Ctrl+w J → move window to bottom
Ctrl+w K → move window to top
Ctrl+w r → rotate windows
Ctrl+w x → exchange current window with next
Closing Windows
Ctrl+w q → close current window (close buffer if only window)
Ctrl+w c → close current window (buffer stays in list)
Ctrl+w o → close all OTHER windows (only show current)
:only → keep only current window
Opening the Same Buffer in Two Windows
Useful for comparing two sections of a long file:
:vsplit → creates a second window of same file
Now scroll each window independently
Diff Mode
Compare two files side by side:
nvim -d file1.lua file2.lua
Or from inside Neovim:
:windo diffthis → diff all visible windows
:diffoff → turn off diff
:diffupdate → refresh diff
Navigation in diff mode:
]c → next diff change
[c → previous diff change
do → diff obtain (pull from other side)
dp → diff put (push to other side)
Window Layout Example
┌──────────────────┬──────────────────┐
│ │ file2.lua │
│ file1.lua ├──────────────────┤
│ │ terminal │
└──────────────────┴──────────────────┘
Commands to create this:
:vs file2.lua (right split)
Ctrl+w j (or open terminal in bottom-right)
:sp | terminal (horizontal split in right column)
In LazyVim
LazyVim Context
LazyVim uses the exact same window splitting commands as Vanilla Neovim. However, it provides enhanced window navigation and resizing keymaps out-of-the-box, making it much faster to manage your layout.
| Aspect | Vanilla Neovim | LazyVim |
|---|---|---|
| Navigate Windows | <C-w>h/j/k/l | <C-h>/<C-j>/<C-k>/<C-l> (Directly, no <C-w> prefix) |
| Split Window | :vsplit / :split | <leader>- (Horizontal) / <leader>| (Vertical) |
| Resize Window | <C-w>+ / <C-w>< | <C-Up> / <C-Down> / <C-Left> / <C-Right> |
| Close Window | <C-w>q or <C-w>c | <leader>wd |