vimtricks.wiki Concise Vim tricks, one at a time.

How do I jump to a tag definition in a new split window instead of the current buffer?

Answer

<C-w>g<C-]>

Explanation

Pressing <C-w>g<C-]> jumps to the definition of the tag under the cursor — just like <C-]> — but opens the destination in a new horizontal split window. This preserves your current view while letting you inspect the definition alongside it.

How it works

  • <C-w>g is a prefix that modifies the next command to open in a new window
  • <C-]> is the standard "jump to tag" command
  • Combined, <C-w>g<C-]> opens the tag destination in a split, leaving the original window open
  • A count prefix (e.g., 2<C-w>g<C-]>) selects the nth match when there are multiple tag definitions

Example

You are reading a function call:

result = process_data(input)
          ↑ cursor on process_data

Press <C-w>g<C-]> to open process_data's definition in a new split above while keeping your current file visible below. Use <C-]> alone only when you don't need to see both files at once.

Tips

  • Use <C-t> to jump back in the tag stack after navigating
  • For a vertical split instead, first run :vertical then use the tag jump: <C-w>v then <C-]> (or map it)
  • :ptag {name} opens a tag in the preview window (:pclose to close)
  • Works with any tags file — generated by ctags, Language Server Protocol, or :!ctags -R .

Next

How do I rename a variable across all case variants (snake_case, camelCase, MixedCase) at once?