1

first time asking question here. I have been using [N]VIM a lot over last few months and really enjoying it so far. But have been struggling to get a particular editor layout setup and starting to think it may not be possible in [N]VIM.

I have been reading up on Buffers, Windows, Tabs, Tab Pages on web and SO (a few of the references I read are below) and makes sense but missing answer I was trying to achieve which is why I am starting to wonder if possible.

What I would like is to be able to split on window to have "buffer_1" and "buffer_2" visible as splits. Then be able to switch to another buffer "buffer_3" (using :bn or :tabn or whatever works). When "buffer_3" is visible I should no longer see "buffer_2" as a split. But if switch back (using :bp or :tabp or whatever works) I would like to see "buffer_1" and "buffer_2" together as splits again.

To put it another way, I would like the window or viewport to be split for a single editing pair (in a tab page?) but not have every viewport split such that switching to other files are also showing the split.

The most desired use case for this:

  • Step 1: I would like to open a source code file on left split and matching unit test file in right split (for TDD)
  • Step 2: Then be able to switch to another file to look something up (ex: definition of a function). That switched view should not need to be split. Or if it was split it should be split with its' own matching unit test file, not the ones in Step 1.
  • Step 3: Switch back to the original two files I was doing TDD and still see my original splits. Able to continue the TDD session.

Is this possible? Or am I just trying to go too far from "The VIM Way". It does seem like a decently useful workflow to be able to switch files and always have a companion split showing the related test file auto-magically.

Example references:

3
  • Actually, I am starting to think that I had an extension messing it up. I tried disabling focus.nvim and I think it is doing right thing now (with :tabn)
    – NewUser
    Nov 29, 2021 at 4:54
  • 1
    Welcome to Vim world. :) The example of one view with splits and another without is exactly the kind of use case that tab pages were designed for. What I'm not understanding from your question is what issues you might be having with using tab pages for this. (I posted this before I saw your preceding comment.)
    – B Layer
    Nov 29, 2021 at 4:56
  • Yeah, sorry. It looks like the plugin was messing it up. Alas, I think it am learning the hard way the advice I have seen a few times online to be cautious of using too many plugins which may cause weird behavior.
    – NewUser
    Nov 29, 2021 at 5:46

1 Answer 1

1

For those who find this in the future ... VIM supports this workflow beautifully (better than any other editor I am aware of, including VS Code).

I had a plugin "focus.nvim" installed which broke this functionality :(

If anyone in future has this same issue, then please check out your plugins and be cautious what plugins you install in future which may cause unexpected behavior changes in your editor.

Edit: To explain the workflow:

  1. Open source code file you are interested in doing TDD session with (:e service.ts)
  2. Promote that buffer to have a dedicated tab (:tab sp). Now you will have a brand new tab with the one file and is isolated from any other tabs you had open (ex: folds are independent)
  3. Open the companion file in a split in that tab (:vsplit service.spec.ts)
  4. Do your TDD work in that tab. Profit. Switch to other tabs (gt) whenever you want to (ex: if you do multiple TDD file pairs at same time which is common).
  5. Switch back (gT) and have confidence your layout didn't get messed up. No risk to see a different buffer in top/bottom than you were looking at before.
1
  • Please edit this answer to explain how vim supports the workflow (e.g., "open two tabs and use gt").
    – D. Ben Knoble
    Nov 29, 2021 at 18:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.