How do I peek at a function definition without leaving my current window?
Answer
:ptag {identifier}
Explanation
:ptag {identifier} opens a small preview window showing the definition of the given tag, while keeping your cursor in the original window. This lets you inspect a function signature or variable declaration without disturbing your current position in the file — ideal when you want a quick reference without losing your context.
How it works
:ptag— like:tag, but opens the result in the preview window instead of the current window{identifier}— the tag name to look up (must exist in yourtagsfile)- The preview window is a fixed, single special window (there can only be one at a time)
- Close it with
:pcloseor<C-w>z
For cursor-based lookup (the identifier under the cursor), use the normal-mode command:
<C-w>}
This is the quickest way to trigger a preview for the word under the cursor.
Example
With cursor on getUserById in your code:
<C-w>}
Vim opens a preview window at the top showing the function definition from your tags file. Your cursor stays in the original buffer. When done:
:pclose
Tips
<C-w>P(uppercase P) — jump your cursor into the preview window so you can scroll or copy from it:pclose/<C-w>z— close the preview window from any window- Set
previewheightto control the preview window size::set previewheight=12 - Requires a
tagsfile — generate withctags -R .in your project root - In Neovim with LSP configured,
:lua vim.lsp.buf.hover()offers a similar experience without tags