Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:20:07+00:00 2026-06-01T15:20:07+00:00

I did search, and got a cloeset answer form How can I automatically close

  • 0

I did search, and got a cloeset answer form How can I automatically close preview window after I move cursor to another window in Vim?. However I found it doesn’t work with taglist plugin properly.

Here’s the code taken from the above link:

autocmd WinLeave * pc

autocmd WinLeave * call ClosePreviewWindow()
function ClosePreviewWindow()
    if &pvw
        pclose
    endif
endfunction

I’m using a vim plugin called autopreview. Gennerally it will call ptag command to open a preview window and jump back to the buffer window. Here’s the problem, when it jumps from buffer window to preview window and back, it will trigger WinLeave event twice, then the preview window will be closed immediately after opened. So it never showed up. I tried to replace WinLeave with TabLeave/BufLeave, other problems occurred. So I came here for help.

UPDATE:
Maybe I should use tabclose/qa command?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:20:09+00:00Added an answer on June 1, 2026 at 3:20 pm

    Have you tried using the WinEnter event instead of WinLeave? In the handler you’d check to see if you’re entering the preview window and if so do nothing, otherwise check to see if the preview window is open and close it if necessary (like your code above).

    Edit

    Based on your description, in order to make this work you’ll need to check to see if the previous window was the preview window. This snippet will tell you that:

    if getwinvar(winnr("#"), "&pvw") == 1
        " do stuff, e.g. pclose
    endif
    

    What that says is, “get me the option value pvw (which happens to be window-local) for the previous window”, where winnr("#") gives the window number of the previous window.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did a quick search and got this link From StackOverflow I get this
This might be a duplicate question, however I did search and I got so
I got an unaligned memory accesses not supported error and did a Google search
I did search the forum and did not find a similar question. I'm looking
Please note that this is not homework and i did search before starting this
just to put it out there -I really did search and try to find
I did a search before asking so please don't tell me to do that.
First of all, I did a search on this and was able to find
While I was doing some reading on system calls, I did a search for
I did a quick search on how to check whether Internet is available or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.