【问题标题】:Write ctags support for diff/patch file in vim为 vim 中的 diff/patch 文件编写 ctags 支持
【发布时间】:2017-01-13 00:09:08
【问题描述】:

我经常在我的项目中使用它,以查看变化:

git diff 5b80e3be314143f  3b34d24a55ab -- include/* src/* | vim -

所有以被更改文件开头的行都写成这样:

diff --git a/include/behaviors/mechanical/crystal_behavior.h b/include/behaviors/mechanical/crystal_behavior.h

我希望能够使用使用 ctags 的 tagbar 轻松导航文件,并获得例如文件名,此处为 crystal_behavior.h。 所以,我知道我可以在 .ctags 文件中使用类似的东西:

--langdef=diff
--langmap=diff:.diff
--regex-diff=/^diff --git .*b\/(.*)(\/(.*))+$/\.\. \2/d,file/

连同这个在我的 .vimrc 中

let g:tagbar_type_diff = {
  \ 'ctagstype' : 'diff',
  \ 'kinds'     : [
    \ 'd:Files',
    \ ],
    \ 'sort'    : 0,
\ }

我的问题是,我可以在这里输入什么--regex-diff=*,以获得有意义的文件名? (我或多或少) 是否有可能更进一步并标记每个文件中的帅哥?这是我无法得到的最棘手的部分。

谢谢

  • 额外问题:如果我直接从缓冲区读取差异,标签栏不会生成标签...而我是做 git diff ......> patch.diff,然后是 vim patch.diff,它可以工作.

【问题讨论】:

    标签: diff patch ctags


    【解决方案1】:

    Universal-ctags(https://ctags.io) 有一个内置的解析器,用于从 geany 导入的差异:

    [jet@localhost tmp]$ cat foo.diff 
    diff --git a/source.mak b/source.mak
    index 2550028..eaa9154 100644
    --- a/source.mak
    +++ b/source.mak
    @@ -44,6 +44,7 @@ PARSER_SOURCES =              \
        $(PARSER_DIR)/clojure.c         \
        $(PARSER_DIR)/css.c         \
        $(PARSER_DIR)/cobol.c           \
    +   $(PARSER_DIR)/diff.c            \
        $(PARSER_DIR)/dosbatch.c        \
        $(PARSER_DIR)/eiffel.c          \
        $(PARSER_DIR)/erlang.c          \
    [jet@localhost tmp]$ ~/var/ctags/ctags --fields=+K --sort=no -o - foo.diff 
    a/source.mak    foo.diff    /^--- a\/source.mak$/;" modifiedFile
    -44,6 +44,7 foo.diff    /^@@ -44,6 +44,7 @@ PARSER_SOURCES =                \\$/;"  hunk    modifiedFile:a/source.mak
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 2021-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多