How do I close a preview window from any other window without having to jump to it first?
Answer
<C-w>z
Explanation
Pressing <C-w>z closes the preview window from any window in the current tab page. You do not need to jump into the preview window first — the command works wherever your cursor is.
How it works
Vim's preview window is a special split opened by commands like <C-w>} (preview tag under cursor), :ptag, or :pedit. There is only ever one preview window per tab.
<C-w>z— close the preview window from any window (same as:pclose)<C-w>P— jump your cursor into the preview window (to edit or close it manually)
Without <C-w>z, you would need to <C-w>P to focus the preview window, then :q to close it — two moves instead of one.
Example
" Open the tag definition for the word under cursor in a preview window
<C-w>}
" ... read the preview, continue editing in your main window ...
" Close the preview window without leaving your current split
<C-w>z
Tips
:pcloseis the Ex command equivalent of<C-w>z.- If no preview window is open,
<C-w>zdoes nothing. - You can map it for convenience:
nnoremap <leader>pc <C-w>z.