How do I make vim open all files matching a pattern in different tabs?

喜欢而已 提交于 2019-11-29 16:37:07

问题


In a given working directory, if I do

:tabe **/test*.py

vim complains with E77: Too many file names. What if I want it to open every matching file in a separate tab? There must be a way to do it, but I can't find it.


回答1:


You could use the args list and argdo like so:

:args **/test*.py
:argdo tabe %

However, the syntax event is turned off by argdo (to speed up the normal use case), so the files will be loaded without syntax at first. You could follow it up with a :syntax on to force the syntax event on all loaded buffers. Compressed into one line (need to wrap argdo in execute so it doesn't absorb the following |):

:args **/test*.py | execute 'argdo tabe %' | syntax on

Alternately, you can open vim from the command line via:

vim -p **/test*.py

But that will max out at 10 tabs.




回答2:


You can use the following:

:next **/test*.py

It opens all the files.




回答3:


To map it

nmap <c-d> :args **/*.tpl<bar>execute 'argdo tabe %'<bar>syntax on<cr>

But still it displays list of files, you have to press enter few times (depending of number of files).




回答4:


This functionality can be included as a command in your .vimrc file:

"open all files in seperate tabs
command -nargs=1 OpenAll call <SID>openAll(<f-args>)
function! s:openAll(dir)
    execute 'args ' . a:dir
    silent argdo tabe %
    syntax on
endfunction

With this function running :OpenAll **/*.py from vim will quickly open all files into new tabs



来源:https://stackoverflow.com/questions/3468763/how-do-i-make-vim-open-all-files-matching-a-pattern-in-different-tabs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!