doushun9875 2014-11-04 10:48
浏览 101
已采纳

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?

  • 写回答

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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?