How do I preview a tag definition in a preview window using :ptag?
Answer
:ptag function_name
Explanation
The :ptag command opens a tag definition in a small preview window at the top of the screen, letting you read the definition without losing your place in the current buffer. This is invaluable when you need to quickly check a function signature or type definition while editing.
How it works
:ptag {name}opens the tag{name}in the preview window- The preview window stays open and does not take focus
- Use
:pcloseor<C-w>zto close the preview window :ptjump {name}works like:ptagbut shows a selector if multiple tags match:ppoppops the preview window tag stack, going back to the previous tag
Example
While editing a file that calls calculate_total:
:ptag calculate_total
A small window appears at the top showing the definition:
+-- Preview Window -------------------------+
| def calculate_total(items, tax_rate): |
| subtotal = sum(i.price for i in items) |
| return subtotal * (1 + tax_rate) |
+-------------------------------------------+
| ... your current editing buffer ... |
| |
+-------------------------------------------+
Tips
- Combine with
<C-w>}to preview the tag under the cursor without typing the name - Set
previewheightto control the preview window size::set previewheight=8 - Use
:pedit filenameto open any file in the preview window, not just tags - The preview window is special: only one can exist at a time, and it has
previewwindowset