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

How do I move my cursor into the preview window to interact with its contents?

Answer

<C-w>P

Explanation

The preview window is a special auxiliary split — usually at the top — opened by commands like :ptag, :pedit, and omni-completion to display reference information. <C-w>P (capital P) moves your cursor directly into that window so you can scroll, search, or copy its contents without closing it.

How it works

  • <C-w>P jumps focus to the preview window; fails silently if no preview window is open
  • Once inside, all normal motions and commands work as usual
  • <C-w>p or <C-w>w returns to your previous window
  • :pclose or <C-w>z closes the preview window from any window

Example

Open a file for reference, then navigate into it:

" Open ~/.vimrc in the preview window
:pedit ~/.vimrc

" Jump into the preview to scroll or yank
<C-w>P

" Return to the original buffer
<C-w>p

" Close the preview when done
:pclose

During omni-completion (<C-x><C-o>), some setups open a preview pane with documentation. Use <C-w>P to scroll that documentation without aborting completion.

Tips

  • set previewheight=12 controls the height of the preview window
  • set completeopt+=preview enables the preview during completion; set completeopt+=noinsert pairs well with it
  • The preview window always has &previewwindow set to 1 — useful in scripts that need to detect it
  • Only one preview window can exist at a time; opening a new one closes the old one

Next

How do I configure Vim's command-line tab completion to show all matches and complete to the longest common prefix?