Fork me on GitHub

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 ?


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)


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>


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


Vim natively supports going switching between two files:


: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.


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