Fork me on GitHub
#vim
<
2022-07-04
>
practicalli-johnny09:07:58

I’d like to toggle between two files/buffers using a single command / key binding For example: I am working on two files, router.clj and handler.clj with just one window open. A toggle to show the last open buffer (so would that be last -1). So each time the command is called, it will show either the router our handler ?

practicalli-johnny09:07:07

I’m still learning Neovim so dont yet know how it organises the buffer history, if its by when a buffer was originally opened or last opened (it seems to be the former) I can use the separate commands, :bnext and :bprevious, but then need to remember which buffer is previous or next 🙂. Have I missed something obvious (apart from just having two windows open)

practicalli-johnny09:07:56

Toggling between the last two active windows or tabs would also be useful

Zekeriya Koç10:07:39

there is a command b# . Personally i mapped it to <leader><tab> mostly covers the described need.

Zekeriya Koç10:07:28

nnoremap <leader><tab> :b#<CR>

Dumch10:07:20

nnoremap <silent> <space><tab> <cmd>exe v:count ? v:count . 'b' : 'b' . (bufloaded(0) ? '#' : 'n')<cr>
I use space + tab to switch between 2 files. This logic also allows to ignore buffers like Startify

nate14:07:30

Vim natively supports going switching between two files: http://vimdoc.sourceforge.net/htmldoc/editing.html%23CTRL-%5E

1
practicalli-johnny15:07:54

:b# looks the simplest thing to use to start with, mapped to <TAB> key. I occasionally use startup.nvim, but perhaps not that often that I think it would interfere, although useful to know how to manage if it does. The vimdoc nicely explains why b# works, so thanks for that too. Thanks everyone.

mjw13:07:18

I use that often enough that I’ve mapped it to <Leader><Leader>, which for me is comma comma.