How to use windows, tabs and buffers in vim

In Vim, buffers, windows, and tabs are essential concepts that help users efficiently manage and navigate multiple files and views within the editor

Together, buffers, windows, and tabs in Vim offer a powerful and flexible environment for editing and navigating files. Users can switch between buffers, resize and rearrange windows, and create new tabs to suit their workflow. These features enable efficient multitasking and enhance productivity when working with multiple files or different sections of code.

Buffers represent the opened files or text contents in Vim. Each file being edited is stored in a separate buffer, which allows users to switch between different files quickly. Buffers can be created, modified, saved, and closed, providing flexibility and control over the editing process.

Windows, on the other hand, refer to the split views within the Vim editor. Users can split the Vim window horizontally or vertically, creating multiple windows to display different buffers simultaneously. Each window can contain a separate buffer, allowing users to view and edit multiple files side by side.

Tabs in Vim provide a way to organize and manage multiple windows. Tabs allow users to group related windows together, providing a clean and organized workspace. Each tab can have its set of windows, with different buffers open in each window.

vim windows tabs buffers

I started using buffers in vim to edit multiple files. This is fine for working with a handful of files. But once you need to circle among more than five files, it is difficult to keep track of them. That is why I switched to using windows and tabs. With them you can move around multiple files very quickly, because you can see them directly on the screen. However, I still keep some buffers related key mappings just for the shake of completion.

These are the key mappings that I use in vim for handling windows, tabs and buffers. You can set them up by just copying them into your .vimrc file:

WINDOWS

" Vertical split
nnoremap <leader>+     :vs<CR>
" Horizontal split
nnoremap <leader>-     :split<CR>
" Move to window above
nnoremap <leader>k     <C-w>k
" Move to window below
nnoremap <leader>j      <C-w>j
" Move to left window
nnoremap <leader>h      <C-w>h
" Move to right window
nnoremap <leader>l     <C-w>l
" Decrease current window height
nnoremap <leader><Up>    :resize +10<CR>
" Increase current window height
nnoremap <leader><Down>  :resize -10<CR>
" Decrease current window width
nnoremap <leader><Left>  :vertical resize +10<CR>
" Increase current window width
nnoremap <leader><Right> :vertical resize -10<CR>

TABS

" Open new tab
nnoremap <leader>t     :tabnew<CR>
" Close tab
nnoremap <leader>w     :tabclose<CR>
" Switch to previous tab
nnoremap <leader>p     :tabprevious<CR>
" Switch to next tab
nnoremap <leader>n     :tabnext<CR>

BUFFERS

" List open buffers
nnoremap <leader>b :buffers<CR>
" Go to previous buffer
nnoremap <leader>< :bprevious<CR>
" Go to next buffer
nnoremap <leader>> :bnext<CR>
" Delete current buffer
nnoremap <leader>d :bdelete<CR>

Popular posts from this blog

How to setup NeoVim configuration file

WebAssembly (Wasm): Fixing the Flaws of Applets

How to query Outlook from PowerShell