Vim 101: Preview Window

Continuing on from last week's Vim 101 on tags, another useful element to a tag-based workflow is the preview window (:help preview-window). There's only ever one preview window per tab page, and it can be used to display tag definitions without interruption.

Typing :ptag tagname will open the preview window for "tagname". If you follow through last week's tutorial using Vim's source, you could type :ptag curbuf to see the definition of EXTERN buf_T in src/globals.h. When the window opens, it won't steal focus, which makes it essential for quickly looking up function signatures without wrecking your concentration when you need to navigate back.

If you type :ptag again, Vim will display "tag 1 of 2 or more" (this will be automatically displayed when there's no other message). Typing :ptnext or :ptprevious allows you to navigate between the matching tags.

ptag demonstration

Even better, CTRL-W } will open :ptag with the tag under the cursor. Pressing CTRL-W z will close the preview window once you're done.

Command Short Alias Description
:ptag [tag] :pta Open a tag in the preview window
CTRL-W } Open a tag under the cursor
:ptnext :ptn Go to the next matching tag
:ptprevious :ptp Go to the previous matching tag
:pclose :pc Close any open preview windows
CTRL-W z Close any open preview windows

This table show an overview of the basic preview window commands.

blog comments powered by Disqus