Generally when opening more than two or three files in vim, I use a single split, navigating between the files/buffers with :n/:N. Sometimes, however, I want to open all of them in visible splits at once (:ba/:vert ba), such as to move the cursor in each to the next occurrence of a search pattern.

Afterward, I usually want to go back to the single split, but the obvious methods to reduce the split count are quitting (drops the buffers) or moving the splits around (e.g. CTRL-w L, awkward and requires double the screen real estate). Is there a better way?

  • 1
    :only Or <C-w>o might interest you.
    – D. Ben Knoble
    Oct 13 at 1:04
  • That does seem useful. It does strange things to the buffer sequence, though; if I opened vim a.py b.py c.py d.py and then ran :ba, then :only while focused on the c.py buffer, Vim considers c to be the first file, and moving with :n goes c > b > c > d. (OTOH :n, :N goes c > b > a, so it's merely strange and annoying, not a big problem). Oct 14 at 19:27
  • Depends on how you are getting to c.py: :ball might not change the current position in the arglist, so you’re still considered on the first argument. Try :args to debug that; the arglist (which :next/:prev manipulate) is not really the same as the buffer list, and “buffer sequence” isn’t really a term I’m familiar with for vim.
    – D. Ben Knoble
    Oct 14 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.