Bohr
Bohr

Reputation: 1726

Manage "window-local" buffers in Vim

Clarification: A "window-local buffer" in this context just means a buffer once loaded into a specific window, any other buffer not ever loaded into that window is not a "window-local buffer".

I had some ruminations on ways managing buffers earlier and I think having a "window-local" buffer list would provide an extra way managing buffers. By saying that, I'm not interested in ways managing buffers already provided by Vim.

And it seems the solution is straightforward by recording "window-local" buffers manually like autocmd BufWinEnter * call add(w:buffers, expand('%')) and providing corresponding interfaces to the "window-local" buffer list w:buffers.

Do you find this useful? And any suggestion would be appreciated.

Upvotes: 3

Views: 134

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172688

The buffer list is global. You can have a window-local argument list (with :arglocal), and then use commands like :next to navigate through them.

Upvotes: 1

jahroy
jahroy

Reputation: 22692

To list all open buffers use this:

:buffers

To open buffer #5 use this:

:buffer 5

You can use the following mapping to combine the two commands:

:nnoremap <F5> :buffers<CR>:buffer<Space>

How to use this convenient mapping:

  • press F5
  • enter a buffer number
  • press <Enter>

More reading here. (search for "switching by number")

Upvotes: 1

Related Questions