#With vim only
With vim only
There's a few options to make navigation between files less tedious in vanilla vim.
First, you probably want to have set switchbuf=useopen
in your vimrc (:h 'switchbuf'
) to reuse a split, instead of opening the buffer in the current split.
If you have the buffer number in 'statusline'
(i.e %n
), you can then easily switch to a split by number with :sbuffer buffnumber
.
This will also work if you give a unique pattern from the name. If you are in the split 'foo' and have two more splits 'bar' and 'baz', :sbuffer az
will switch to the 'baz' split.
You can have a mapping to make it easier: nnoremap <leader>b :sbuffer
(there's a space at the end).
Also, those mappings help switch to different splits (:h windows
):
<c-w>t
-> top left split<c-w>b
-> bottom right split<c-w>p
-> last used split
#With FZF
With FZF
Besides, could use fzf.vim plugin (requires fzf) and its :Buffers
command.
Similarly to switchbuf=useopen
, you'll want let g:fzf_buffers_jump = 1
in your vimrc to reuse an open split.
The command will show a list of buffers which you can strip down with fuzzy search, and navigate with <c-j>
and <c-k>
<Enter>
will then switch to the split if already open, or else use the current one. <c-v>
, <c-x>
or <c-t>
will open the buffer in a new vertical split, horizontal split or tab.
You could have a mapping to launch :Buffers
like nnoremap <leader>b :Buffers<cr>
.