doushun9875
2014-11-04 10:48
浏览 95

vim-go:如何打开GoFiles返回的文件

Vim-go plugin has a :GoFile function to show source files that depends on the current package. The output looks like this:

['/home/tretkow/tut/main.go', '/home/tretkow/tut/test.go']

How to open files from the list?

图片转代码服务由CSDN问答提供 功能建议

Vim-go插件具有:GoFile函数来显示依赖于当前软件包的源文件。 输出看起来像这样:

  ['/ home / tretkow / tut / main.go','/home/tretkow/tut/test.go'] 
 <  / code>  
 
 

如何从列表中打开文件?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongyun8891 2014-11-04 11:23
    最佳回答

    :GoFiles only echoes the output of go#tool#Files().

    From the look of your snippet, it should be possible to extract a filename with something like:

    :e <C-r>=go#tool#Files()[0]<CR>
    

    or put that list in a scratch buffer:

    :vnew<CR>
    :0put=join(go#tool#files(), '')<CR>
    
    /home/tretkow/tut/main.go
    /home/tretkow/tut/test.go
    

    and use gf to jump to the file under the cursor.


    Here is a more sophisticated solution: the :GoFile command lets you choose what file from the :GoFiles command to edit via custom tab-completion.

    " 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
    

    Usage:

    :GoFile <Tab>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题