How do I open another buffer in a split without changing the alternate-file register?
Answer
:keepalt sbuffer {bufnr}
Explanation
The alternate-file register (#) is easy to disturb when jumping around buffers, and many advanced motions depend on it (<C-^>, # expansions, quick two-file toggles). :keepalt sbuffer {bufnr} opens a target buffer in a split while preserving your current alternate-file state. This is useful in review/debug sessions where you need temporary side windows but do not want to lose your primary file toggle context.
How it works
:sbuffer {bufnr}opens an existing buffer in a new split:keepaltwraps the command so Vim does not update the alternate file{bufnr}can be any listed buffer number from:ls
Example
Imagine you are switching between app.py and test_app.py using <C-^>, and briefly need to inspect README.md.
:ls
:keepalt sbuffer 7
README.md opens in a split, but <C-^> still jumps between your original two files instead of being redirected to the temporary split target.
Tips
- Combine with
:vert sbuffer {bufnr}when you prefer side-by-side layout - Use this in custom commands/mappings where preserving
#is important for muscle memory