2

I love the quickfix feature in vim. It also works flawlessly in most cases. But when I work with LaTeX documents, it leads to funny behavior. I don't think it's relevant, but I have the LaTeX suite installed, and makeprg is set to makeprg=xelatex -interaction=nonstopmode.

Assume I have a LaTeX document open. When I now run :make in vim, the document is compiled and a quickfix window is opened. I do not necessarily intend to fix those warnings. Being lazy, I leave the quickfix window open, do some changes, and compile again. What now happens to the quickfix window for a LaTeX document is different from my experience when working with other languages. Instead of updating the quickfix window, it opens another one, taking up more and more pixels from my working area.

A screenshot can be seen here. My actual work area are the five lines at the top.

quickfix-hell

I can close the first quickfix window with :cclose, but then I have to move to the other windows and close them one by one. Or I can close vim and open it again. None of these workflows is particularly sensible or efficient.

Can I close all quickfix windows with one command? Can I prevent additional quickfix windows to be opened? Or can I sanitize my settings in such a way, that it won't open more than one quickfix window?

  • 1
    there is only one quickfix window in the screenshot.. are you referring to something else? – Mass Jan 4 at 15:30
  • @Mass I guess the other windows are not quickfix windows, then. My question would then be, why do they get opened, what are these windows? – pfnuesel Jan 4 at 15:33
  • 1
    If you append a bang after :make, it should prevent Vim from jumping to the first error, which may be what happens every time a new window is opened after a compilation. I'm not sure it will help, but :make! could be worth a try. Otherwise, you can close all windows except the focused one with :only, which can be shortened with :on (or press C-w o in normal mode). – user938271 Jan 4 at 16:00
  • @user938271 I was using :make! all along, since jumping to the error rarely works for me in involved LaTeX documents. :only is a good solution, I didn't know about this command before! If there are no explanations why the other windows are opened in the first place, I would consider :only as a solution (provided you elevate the comment to a reply). – pfnuesel Jan 4 at 18:11
2

I have written a code that is pretty similar to the :only command. But it closes also unsaved buffers. It keeps the only the active window in the current tab.

function! CloseAllWindowsButCurrent()
  let tabnr= tabpagenr()
  let tabinfo=gettabinfo(tabnr)
  let windows=tabinfo[0]['windows']

  for winid in windows
    let curwin=winnr() "could change
    let winnr=win_id2win(winid)
    if winnr!=curwin
           execute ':'.winnr.'q!'
    endif
  endfor
endfunction

I have mapped <leader>c to call this.

nnoremap <leader>c :call CloseAllBuffersButCurrent()<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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