Vim : how to index a plain text file?

标签 vim ctags

是否可以在 vim 中索引纯文本文件(一本书),例如:

1. This line contains the words : London, Berlin, Paris
2. In this line, I write about : New-York, London, Berlin
...
100. And, to conclude, my last comments about : New-York, Paris

并有这个结果索引:
Berlin : 1
London : 1, 2
New-York : 2, ..., 100
Paris : 1, ..., 100

并且,如果可能的话,标记方法是什么?
我已经读过关于 ctags 的文章,但它似乎是专门针对特定语言的(说实话,对于我的需求来说有点矫枉过正)

最佳答案

我冒昧地编写了以下函数,基于使用 :g/STRING/#命令来获取匹配项。我将这个命令的结果读入一个列表,然后对其进行处理以返回匹配行号的列表:

function! IndexByWord( this_word )
    redir => result
    sil! exe ':g/' . a:this_word . '/#'
    redir END
    let tmp_list = split(strtrans(result),"\\^\@ *")
    let res_list = []
    call map(tmp_list, 'add(res_list,matchstr(v:val,"^[0-9]*"))')
    let res = a:this_word . ' : ' . string(res_list)
    let res = substitute(res, "[\\[\\]\\']", "", "g")
    echo res
endfunction

所以你可以在所有你想要的词上调用这个函数(或编写一个脚本来这样做)并将输出定向到一个文件。也许不是很优雅,但很好地独立。

希望这会有所帮助,而不是阻碍。

关于 Vim : how to index a plain text file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5869997/

相关文章:

java - 在 Windows 上将 Ctags 与 Gvim 结合使用

eclipse - Vim 中的源代码面包屑

c - 在 C 中创建新 block 时缩进新行

ruby - 从 vim 运行 ruby​​ 代码

vim - 在 vim 状态行中显示当前函数

vim - 通过 ssh 使用 Macvim

vim - ctags 不解析某些 clib header

vim - 如何用 vim 在不同的行打开多个文件?

VIM 选择整行

vim - 每当我在插入模式下输入冒号时,它都会将我的文本移动到行首