[vim/vim] Add option to control whether tagstack is copied to new window (PR #17589)

23 views
Skip to first unread message

Yuri Gribov

unread,
Jun 22, 2025, 1:02:17 AM6/22/25
to vim/vim, Subscribed

This is a simple fix for an old issue #5742.

Some people find that default Vim's behavior of copying entire tag stack when splitting a window with unrelated file is confusing. This PR adds a flag (copytagstack) to give users control over this.

Please note that, not being a Vim expert, I may miss some hidden issues. I'd be happy to improve/rewrite PR as necessary.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/17589

Commit Summary

  • e7de891 adds option to control whether tagstack is copied to new window

File Changes

(6 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589@github.com>

Christian Brabandt

unread,
Jun 22, 2025, 1:07:50 PM6/22/25
to vim/vim, Subscribed

@chrisbra commented on this pull request.

I have not much of an opinion on it, other what I mentioned below. @yegappan I think you might have some opinion here?


In runtime/doc/options.txt:

> @@ -2356,6 +2356,11 @@ A jump table for the options with a short description can be found at |Q_op|.
 	NOTE: This option is reset when 'compatible' is set.
 	Also see 'preserveindent'.
 
+				*'copytagstack'* *'cptgst'* *'nocopytagstack'* *'nocptgst'*
+'copytagstack' 'cptgst'		boolean	(default: on)

Can you make this 'tagstackcopy' so it sorts with the other tags options? short form perhaps 'tscp'?


In runtime/doc/options.txt:

> @@ -2356,6 +2356,11 @@ A jump table for the options with a short description can be found at |Q_op|.
 	NOTE: This option is reset when 'compatible' is set.
 	Also see 'preserveindent'.
 
+				*'copytagstack'* *'cptgst'* *'nocopytagstack'* *'nocptgst'*
+'copytagstack' 'cptgst'		boolean	(default: on)
+				global
+	Copy tag stack when splitting window.

This description is a bit brief :) Can you please add a bit of documentation at :h tag-stack, perhaps something like the following?

In Vim, the tag stack is local to each window. When a new tab or window is opened
(e.g., via |:split| or |:tabnew|), the tag stack is copied from the original window.
This allows you to continue tag navigation seamlessly in the new window.

If you prefer not to copy the tag stack when splitting windows, set the
'tagstackcopy' option to off.

Tag navigation commands (such as :tag, :pop, and Ctrl-]) affect only the tag
stack of the current window. Each window maintains its own independent tag stack.

And then reference this part here in the option description.


In src/testdir/Make_all.mak:

> @@ -114,6 +114,7 @@ NEW_TESTS = \
 	test_compiler \
 	test_conceal \
 	test_const \
+	test_copytagstack \

Please copy the tests into test_tagjump.vim


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/review/2948249572@github.com>

Yegappan Lakshmanan

unread,
Jun 22, 2025, 2:28:31 PM6/22/25
to vim/vim, Subscribed
yegappan left a comment (vim/vim#17589)

I have not much of an opinion on it, other what I mentioned below.
@yegappan I think you might have some opinion here?

I'm used to the current behavior where the tag stack is copied to new windows
or tab pages. This allows me to jump to a tag in a new window while still
retaining the original context in the previous window - helpful for traversing
the tag stack without losing my place.

While adding yet another option to Vim always warrants consideration, I don't
see any major issues with supporting this behavior for users who prefer not to
copy the tag stack. That said, this change may introduce some usability
friction, as users would now need to be aware of which window holds a
particular tag stack in order to traverse it effectively


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2994363389@github.com>

Yuri Gribov

unread,
Jun 23, 2025, 1:36:22 AM6/23/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

I'm used to the current behavior where the tag stack is copied to new windows or tab pages. This allows me to jump to a tag in a new window while still retaining the original context in the previous window - helpful for traversing the tag stack without losing my place.

Interesting, I haven't thought about this use-case myself.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2994988250@github.com>

D. Ben Knoble

unread,
Jun 23, 2025, 3:17:57 PM6/23/25
to vim/vim, Subscribed
benknoble left a comment (vim/vim#17589)

This is a simple fix for an old issue #5742.

Some people find that default Vim's behavior of copying entire tag stack when splitting a window with unrelated file is confusing. This PR adds a flag (copytagstack) to give users control over this.

Instead of an option, could this be solved at the user-config level with an autocommand that clears the tagstack when a new window is opened?

That would avoid making Vim itself more complicated (more options: more cognitive load). Heck, I’m not sure if any plugin authors rely on this behavior.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2997675672@github.com>

Christian Brabandt

unread,
Jun 23, 2025, 3:49:57 PM6/23/25
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17589)

The request is a bit similar to #17248. I don't think there is a way to clean the tag-stack.
I wondered if we can use a custom command modifier for such a thing, like :fresh :new that would prohibit copying options or the tagstack? not sure this will work.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2997754128@github.com>

Yuri Gribov

unread,
Jun 23, 2025, 5:06:24 PM6/23/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

This is a simple fix for an old issue #5742.


Some people find that default Vim's behavior of copying entire tag stack when splitting a window with unrelated file is confusing. This PR adds a flag (copytagstack) to give users control over this.

Instead of an option, could this be solved at the user-config level with an autocommand that clears the tagstack when a new window is opened?

You mean something like

autocmd BufWinEnter * :some_new_command_to_clean_tag_stack

? I guess this would work too and command to clean tag stack seems useful in general.

Heck, I’m not sure if any plugin authors rely on this behavior.

True, I'm not sure how to check this...


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2997939474@github.com>

Yuri Gribov

unread,
Jun 23, 2025, 5:09:46 PM6/23/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

I wondered if we can use a custom command modifier for such a thing, like :fresh :new that would prohibit copying options or the tagstack?

Are there examples of such modifiers in current Vim ? Sorry, I'm not really a Vim expert.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2997946866@github.com>

D. Ben Knoble

unread,
Jun 23, 2025, 8:47:49 PM6/23/25
to vim/vim, Subscribed
benknoble left a comment (vim/vim#17589)

This is a simple fix for an old issue #5742.

Some people find that default Vim's behavior of copying entire tag stack when splitting a window with unrelated file is confusing. This PR adds a flag (copytagstack) to give users control over this.

Instead of an option, could this be solved at the user-config level with an autocommand that clears the tagstack when a new window is opened?

You mean something like

autocmd BufWinEnter * :some_new_command_to_clean_tag_stack

? I guess this would work too and command to clean tag stack seems useful in general.

Yes, although for some reason I thought there was a function API for clearing it because I remembered working with related stuff in https://github.com/benknoble/tag-tracks

Heck, I’m not sure if any plugin authors rely on this behavior.

True, I'm not sure how to check this...

Me neither at the moment.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2998402720@github.com>

D. Ben Knoble

unread,
Jun 23, 2025, 8:49:09 PM6/23/25
to vim/vim, Subscribed
benknoble left a comment (vim/vim#17589)

I wondered if we can use a custom command modifier for such a thing, like :fresh :new that would prohibit copying options or the tagstack?

Are there examples of such modifiers in current Vim ? Sorry, I'm not really a Vim expert.

Yes, if you count :botright, :vertical, :tab, :keeppatterns, :keepalt, etc.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2998404920@github.com>

D. Ben Knoble

unread,
Jun 23, 2025, 8:52:09 PM6/23/25
to vim/vim, Subscribed
benknoble left a comment (vim/vim#17589)

This is a simple fix for an old issue #5742.

Some people find that default Vim's behavior of copying entire tag stack when splitting a window with unrelated file is confusing. This PR adds a flag (copytagstack) to give users control over this.

Instead of an option, could this be solved at the user-config level with an autocommand that clears the tagstack when a new window is opened?

You mean something like

autocmd BufWinEnter * :some_new_command_to_clean_tag_stack

? I guess this would work too and command to clean tag stack seems useful in general.

Something I omitted from my first reply (below), you probably want the WinNew event based on the issue description.

Yes, although for some reason I thought there was a function API for clearing it because I remembered working with related stuff in https://github.com/benknoble/tag-tracks


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c2998409789@github.com>

h_east

unread,
Jun 26, 2025, 11:53:27 PM6/26/25
to vim/vim, Subscribed
h-east left a comment (vim/vim#17589)

Indeed, it makes sense for :split to inherit all source window information, including the tagstack, but there may be cases where you don't want to carry over the tagstack when using :new. Since the patch in this PR applies the same behavior to both :split and :new, it doesn't meet my requirements.

By the way, even with the current implementation, you can clear the tagstack only for :new by setting up the following auto-command:

:au BufWinEnter * call settagstack(0, {'items' : []})

(In my case I’d use BufWinEnter, but for you it might be BufNew)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3011525576@github.com>

Yuri Gribov

unread,
Jun 27, 2025, 1:13:47 AM6/27/25
to vim/vim, Push

@yugr pushed 2 commits.

  • 4726231 Address review comments.
  • 04830e0 Added a cleartagstack function to clear window tagstack.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/before/e7de891f27d58de9e05b33d50f6fb6bed2db582d/after/04830e04897d5e64319b9910ca06e67cd8181b54@github.com>

Yuri Gribov

unread,
Jun 27, 2025, 1:42:17 AM6/27/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

I tried to address all review comments from @chrisbra. I've also added an example cleartagstack command to clear tagstack in autocmds as suggested by @benknoble.

The final PR, I assume, will contain either option or command, not both. Using autocmd is fine with me, I'd appreciate if maintainers could comment whether this may be somehow inferior to a full-blown option.

And I still need to figure out the crash for linux (huge, gcc, uchar, testgui, true, dynamic) config.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3011743343@github.com>

Yuri Gribov

unread,
Jun 27, 2025, 1:42:57 AM6/27/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

Indeed, it makes sense for :split to inherit all source window information, including the tagstack

This may be up to some debate. E.g. if I'm in the middle of deep navigation stack for my app and decide to open a file from side project to check something, I'd personally prefer that side file to have a independent stack (e.g. to avoid accidentally returning to "inherited" stack when pressing Ctrl-T multiple times).

Since the patch in this PR applies the same behavior to both :split and :new, it doesn't meet my requirements.

I'd say split of different file should not inherit stack either. As some people can (and do, as we see) disagree I suggested to add an option, for end user to decide.

By the way, even with the current implementation, you can clear the tagstack only for :new by setting up the following auto-command:

Yup, in new patch I'm adding cleartagstack to make this a bit simpler.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3011744381@github.com>

D. Ben Knoble

unread,
Jun 27, 2025, 9:31:54 AM6/27/25
to vim/vim, Subscribed
benknoble left a comment (vim/vim#17589)

Indeed, it makes sense for :split to inherit all source window information, including the tagstack, but there may be cases where you don't want to carry over the tagstack when using :new. Since the patch in this PR applies the same behavior to both :split and :new, it doesn't meet my requirements.

By the way, even with the current implementation, you can clear the tagstack only for :new by setting up the following auto-command:

:au BufWinEnter * call settagstack(0, {'items' : []})

(In my case I’d use BufWinEnter, but for you it might be BufNew)

@h-east FWIW I suggested WinNew in a previous comment. Though I now wonder in which window the autocommand callback runs.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3013102946@github.com>

D. Ben Knoble

unread,
Jun 27, 2025, 9:34:34 AM6/27/25
to vim/vim, Subscribed
benknoble left a comment (vim/vim#17589)

It may just be that I'm on mobile, but the indentation in C files from the cleartagstack patch looks odd.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3013111032@github.com>

Yuri Gribov

unread,
Jun 27, 2025, 1:23:35 PM6/27/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

Indeed, it makes sense for :split to inherit all source window information, including the tagstack, but there may be cases where you don't want to carry over the tagstack when using :new. Since the patch in this PR applies the same behavior to both :split and :new, it doesn't meet my requirements.
By the way, even with the current implementation, you can clear the tagstack only for :new by setting up the following auto-command:

:au BufWinEnter * call settagstack(0, {'items' : []})

(In my case I’d use BufWinEnter, but for you it might be BufNew)

@h-east FWIW I suggested WinNew in a previous comment. Though I now wonder in which window the autocommand callback runs.

FYI I observe the following behaviours for different variants of autocmd ??? :call cleartagstack():

  1. WinNew:
  • :new, :sp, :sp some-other-file - new window has empty tagstack
  1. BufNew, BufWinEnter:
  • :new, :sp some-other-file - new windows has empty tagstack
  • :sp- new window has copy of tagstack
  • in some cases jumping to tag in new file resets existing tagstack (so this is probly unusable)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3013859139@github.com>

Yuri Gribov

unread,
Jun 27, 2025, 1:42:18 PM6/27/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

It may just be that I'm on mobile, but the indentation in C files from the cleartagstack patch looks odd.

Oh, sorry about that. Any file in particular? In general I tried to follow the existing code. In particular formatting of f_cleartagstack is copied from f_gettagstack. Formatting in clear_tagstack is mostly unchanged.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3013901355@github.com>

Yuri Gribov

unread,
Jun 27, 2025, 2:02:25 PM6/27/25
to vim/vim, Subscribed
yugr left a comment (vim/vim#17589)

Summary of current status:

  • this PR is experimental and implements two different approaches (notagstackcopy option and new cleartagstack command for use with autocmd)
  • autocmd-based solution does not even need a new command as pointed out by @h-east

If no one can see potential issues autocmd-based approach I guess there is no need for any changes and PR can be closed (I could also experiment with it for some time and report my findings).


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3013953071@github.com>

Christian Brabandt

unread,
Jun 27, 2025, 2:30:58 PM6/27/25
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17589)

Can you please try out the autocmd solution? It seems like it is enough and we shouldn't require any code changes here. But I'll leave this open so you can report back how well this approach works in practice.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c3014029990@github.com>

Christian Brabandt

unread,
Jun 13, 2026, 4:11:46 PM (10 hours ago) Jun 13
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17589)

this has stalled, so closing


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17589/c4699656323@github.com>

Reply all
Reply to author
Forward
0 new messages