开发者

How to make Vim quickfix list launch files in a new tab?

开发者 https://www.devze.com 2023-03-23 05:03 出处:网络
Say, I have the following mapping: map <F4> :execute "vimgrep /" .expand("<cword>") . "/j **" <Bar> cw<CR>

Say, I have the following mapping:

map <F4> :execute "vimgrep /" .expand("<cword>") . "/j **" <Bar> cw<CR>

which (recursively) greps the current directory for instances of the word under the cursor and opens these files in the开发者_如何学编程 quickfix list window.

From the quickfix window, how do I launch the file that I open into a new tab? Enter just changes my current buffer in the window to that new file.


Quickfix-window commands respect the switchbuf option when creating the buffer. The switchbuf option has the newtab specifier that instructs Vim to open a new tab page before loading the buffer to switch to. If one adds this key to the option via

:set switchbuf+=newtab

the entries in the quickfix window will be opened in separate tab pages.

There is the usetab specifier that also might be useful in this case. It prescribes Vim to switch to an existing tab page if it contains a window displaying the target buffer, instead of duplicating it in a new tab. If it is desirable, one can throw that in, too:

:set switchbuf+=usetab,newtab

The value of switchbuf also (partially) affects other buffer-switching commands, such as :bfirst, :blast, :sbuffer, :sbnext, and :sbprevious.


How about trying QFEnter plugin?
You can open each item in a new tab or a new vertical/horizontal split window without changing switchbuf option.
It also allows you to open multiple quickfix items at once with a visual selection block.


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

also works if you use:

tab copen

which would otherwise first split the window, even with set switchbuf+=newtab.

See also: https://vi.stackexchange.com/questions/6996/how-to-make-enter-open-new-tabs-for-the-quickfix-window-when-it-is-opened-with

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号