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 Apr 25 at 9:57
  • Corrected and added a link to clarify. Sorry about that! – Osada Lakmal Apr 25 at 10:42
  • Ok I get it now, but my solution still stands: is :cclose the command you're looking for? – statox Apr 25 at 11:44

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?

nmap cX mAcX
nnoremap <leader>b :cclose<CR>`A

The first mapping changes the behaviour of cX to first set up an uppercase mark 'A and then call the original mapping. Note that the original cX mapping must already exist when this mapping is created, and that we use the recursive form nmap rather than the usual nnoremap in order that the original mapping will be invoked from our new one.

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? – klaus Apr 25 at 13:40
  • 1
    @klaus Not sure if you saw my edit with the new mappings? Your idea is good too, though! – Rich Apr 25 at 13:41
  • No, you just edited it after I commented. That mapping makes more sense because of automation. Good stuff! – klaus Apr 25 at 13:42
  • hmm I tried it my I just get a Mark not set error – Osada Lakmal Apr 26 at 10:03
  • Ok, this is the correct way to fix it but with one caveat that I list in my answer – Osada Lakmal Apr 26 at 10:23

@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, privacy policy and cookie policy

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