5

I want to work with quickfix without ever having a split window.

So I've set:

set switchbuf=newtab

as mentioned at https://stackoverflow.com/questions/6852763/vim-quickfix-list-launch-files-in-new-tab

Now:

tab copen

opens the quickfix window on a new tab.

But if I hit enter on a quickfix item, instead of creating a new tab, it first opens the location on a split in the current tab.

Only after this first split do new tabs get opened.

Is it possible to get new tabs from the first <enter>, and never see any splits?

Tested on Vim 7.4.

5
  • The <enter> cannot hold it is too late꙰ⷭⷵ Mar 23, 2016 at 19:06
  • @leftaroundabout I don't understand :-) Mar 23, 2016 at 21:36
  • @leftaroundabout reminds me of that famous Stack Overflow post about parsing HTML with regex … which itself derives from something else, not sure what.
    – muru
    Mar 24, 2016 at 6:42
  • 1
    @muru: it's originally from a famous poem. Mar 24, 2016 at 10:47
  • surely, this is a bug? Feb 20 at 13:42

5 Answers 5

9

This workaround seems to work (mind the capitalized T in the end):

autocmd FileType qf nnoremap <buffer> <Enter> <C-W><Enter><C-W>T

It will create a mapping that is local to the quickfix buffer (it also works in location lists, since they have the same filetype, i.e. qf). This mapping will first open the item under the cursor in a new window using <C-W><Enter> and then move it to an new tab using <C-W>T.

See

:help :autocmd
:help quickfix
:help CTRL-W_<Enter>
:help CTRL-W_T
2
7

This mapping does what I think you want, put it in ~/.vim/after/ftplugin/qf.vim.

nnoremap <buffer> <CR> :tabnew\|cc <C-r>=line(".")<CR><CR>
2
  • How does this compare to ingo's answer: vi.stackexchange.com/a/6999/2038 At first sight, that is more readable (I understand the ftplugin vs autocmd part :-)) Mar 23, 2016 at 21:38
  • 2
    You mentioned in your question that you don't want splits. Ingo's mapping opens the file in a new window and moves that window to a tab while my mapping doesn't create an intermediary window. Other than that, I'd say both get the job done. The choice is yours.
    – romainl
    Mar 23, 2016 at 22:42
5

The quickfix/location list is an interesting beast. I'd recommend reading into :help quickfix for some inner workings of these two features (pretty much interchangeable; list commands are prefixed with l and quickfix with q)

It sounds like the default quickfix opens won't solve your problem (opening in a new tab is not supported by default)

I'd check out QFEnter. It was built to give extra control over the quickfix menu and it looks like it should work out of the box for you.

Normal mode : Open an item under cursor in a new tab.

Visual mode : Open items in visual block in a sequence of new tabs.
Quickfix window is automatically opened in the new tab to help you open other Quickfix items.

1

I've added the following remapping to my function which opens the quicklist:

nnoremap <buffer> <Enter> :tab .cc<CR>

This plays nicely with

set switchbuf+=usetab

so that if the buffer is already open in another tab, it will use that tab rather than a new one.

0

Try also :cdo tabedit:

  • :cdo {cmd} -- Execute {cmd} for every entry in the quickfix list (like :tabdo or :bufdo
  • :tabedit {pathspec} -- Open a new tab page for {pathspec}

Since :tabedit seems to understand the quickfix line spec, :cdo will open a new tab page for every item in the quickfix list. In practice, I have an extra tab page open that I have to close, but it doesn't seem to omit any of the entries.

I use this to inspect all the jump locations returned by git grep generated by the Tim Pope fugitive plugin command Ggrep, which loads the results into the quickfix list by using git grep as grepprg, e.g.

Find all usages of send_email that are NOT in tests directories:

:Ggrep '\bsend_email\(' -- ':!**/tests/**' | cgo tabedit

You could probably achieve the same without fugitive and definitely with anything that populates the quickfix list. See also :ldo, which iterates over items in the location list, and all the :*do commands for other helpful automations.

2
  • You might also be interested in the git-jump script in git's contrib directory; git jump grep … opens vim with the results loaded in the quickfix. There's also diff, merge, and ws modes.
    – D. Ben Knoble
    Jul 6, 2022 at 14:36
  • Nice tip, @D.BenKnoble!
    – AL the X
    Jul 7, 2022 at 15:23

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.