Vim-go插件有一个:GoFile函数来显示依赖于当前包的源文件。输出如下所示:
['/home/tretkow/tut/main.go', '/home/tretkow/tut/test.go']如何从列表中打开文件?
发布于 2014-11-04 11:23:15
:GoFiles只回显go#tool#Files()的输出。
从代码片段的外观来看,应该可以使用以下内容提取文件名:
:e <C-r>=go#tool#Files()[0]<CR>或者把这个列表放在一个scratch缓冲区中:
:vnew<CR>
:0put=join(go#tool#files(), '\r')<CR>
/home/tretkow/tut/main.go
/home/tretkow/tut/test.go并使用gf跳转到光标下的文件。
这里有一个更复杂的解决方案::GoFile命令允许您从:GoFiles命令中选择要通过自定义选项卡完成进行编辑的文件。
" the command
command! -nargs=1 -complete=customlist,GoFilesComplete GoFile call GoFile(<f-args>)
" the completion function
function! GoFilesComplete(ArgLead, CmdLine, CursorPos)
return filter(go#tool#Files(), 'v:val =~ a:ArgLead')
endfunction
" the :edit wrapper
function GoFile(file)
execute "edit " . a:file
endfunction用法:
:GoFile <Tab>https://stackoverflow.com/questions/26733223
复制相似问题