I use gutentags and gutentags-plus for generating and managing tag files. When I use the key combinations setup by them ( cX usually ), it opens the relevant lines in a quickfix window and I can use :cnext etc for navigation. But how do I close them quickfix window and go back to the file I was editing after I have gone through the lines found in cscope?

PS: Actually I am using global instead of cscope but I guess on VIM side it should not matter.

  • 3
    I'm not sure what your PS means. However I think you're looking for :cclose :h :cclose?
    – statox
    Commented Apr 25, 2019 at 9:57
  • Corrected and added a link to clarify. Sorry about that! Commented Apr 25, 2019 at 10:42
  • Ok I get it now, but my solution still stands: is :cclose the command you're looking for?
    – statox
    Commented Apr 25, 2019 at 11:44
  • When in the quickfix window, <C-w>c (c like "close") will do, when in the 'main' window, <C-w>o (o like "only [this window]" or "[close] other [window]"). Assuming only two windows are open.
    – Rolf
    Commented Jun 3, 2021 at 7:40

2 Answers 2


To close the quickfix window, you use :cclose, as @statox mentioned in the comments.

This won't affect which code buffer you're viewing, though. Vim doesn't distinguish between the buffer you were looking at originally and the buffers you navigated to via the quickfix, so to go back you are going to have to use Vim's regular buffer switching commands. If you know the name or number of the original buffer, :b is probably quickest.

If not, you could try mashing Ctrl-O to jump backwards through the jumplist till you reach the right buffer, or you might want to set up some mappings* (or a plugin) for faster buffer navigation.

If you want something automated, how about adding something like following to your .vimrc?

nnoremap <silent> <leader>gs mA:GscopeFind s <C-R><C-W><cr>
nnoremap <leader>b :cclose<CR>`A

The first mapping adapts your current search mapping to first set an uppercase mark A and then continue with its original behaviour.

The second creates a new mapping that closes the quickfix and then returns to the marked position.

* Make sure you read as far down as the EDIT, because it's after that that the juicy details are included.

  • Or faster solution would be to create a new tab with the current buffer so that he can just close the tabpage with the quickfix window altogether and go back to the newly created tagpage. But he has to remember to do <C-w>T every time. Or maybe an autocmd trigger with QuickFixCmdPost etc. to open the quickfix window after creating a new tab? That could also work, right?
    – 3N4N
    Commented Apr 25, 2019 at 13:40
  • 1
    @klaus Not sure if you saw my edit with the new mappings? Your idea is good too, though!
    – Rich
    Commented Apr 25, 2019 at 13:41
  • No, you just edited it after I commented. That mapping makes more sense because of automation. Good stuff!
    – 3N4N
    Commented Apr 25, 2019 at 13:42
  • 1
    Hmmm, I don't see how :nmap cX mAcX will work, since the cX in it can only call the same mapping again. (In other words, infinite recursion.) If defined after the original cX mapping, it will just overwrite it. Perhaps that part of the answer needs an update...?
    – filbranden
    Commented Jun 22, 2020 at 15:07
  • 1
    @filbranden What's particularly weird about this one, is not so much the recursive mapping--which could just be a brainfart--but the fact that I wrote an entire explanatory paragraph afterwards that was just utter rubbish!
    – Rich
    Commented Jun 22, 2020 at 15:59

@klaus makes the correct suggestion to set a mark. However I needed to set it before the quick fix window appeared not while traversing the list. I am using gutentags_plus plugin to make cscope work with guten-tags plugin. So I just redefined Gscopefind command mappings from

noremap <silent> <leader>gs :GscopeFind s <C-R><C-W><cr>


noremap <silent> <leader>gs mA :GscopeFind s <C-R><C-W><cr>

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.