I know there is :copen command which opens quickfix window but it doesn't immediately switch to it(till it open). How can I wait for it to be sure my next commands in script would be executed in quickfix?

  • 3
    I'm not seeing this problem. You shouldn't have to wait for anything--the next commands in your script should be executed in the quickfix window. Perhaps you could include an example of something that isn't working as you expect it to. I tried a experiment with the following three lines in a script: copen, set modifiable, put='abcde'. I then opened vim, sourced that script file, and observed the expected result that the quickfix window contained the line abcde.
    – garyjohn
    Dec 26, 2017 at 19:28

1 Answer 1


This is the function that I use to ensure the Preview window is open and has focus. I like this window to be in the first tab, if you don't want that then your logic will vary accordingly.

I have a function that is mapped to hotkeys that fire off builds of different flavors; this function is called right before I execute :make with my desired options.

function! EnsurePreviewWindow()
    if ! &previewwindow          " don't do this in the preview window
        silent! wincmd P         " jump to preview window
        if ! &previewwindow      " if we still aren't there...
            setlocal switchbuf=useopen
            execute "copen" (&lines / 3)
            set previewwindow
        silent! wincmd p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.