Vim:如何索引纯文本文件?
是否可以在 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 的内容,但它似乎专用于特定语言(说实话,对于我的需求来说有点矫枉过正)
Is it possible to index a plain text file (a book) in vim such as :
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
and have this resulting index :
Berlin : 1
London : 1, 2
New-York : 2, ..., 100
Paris : 1, ..., 100
and, if it is possible, what is the tagging method ?
I have read about ctags, but it seems to be dedicated to specific languages (and to say the truth, a bit overkill for my needs)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我冒昧地编写了以下函数,基于使用
:g/STRING/#
命令来获取匹配项。我将该命令的结果读入一个列表,然后对其进行处理以返回匹配行号的列表:因此,您可以对您想要的所有单词调用此函数(或编写一个脚本来执行此操作)并将输出定向到一个文件。也许不是很优雅,但非常独立。
希望这会有所帮助,而不是阻碍。
I took the liberty of writing the following function, based on using the
:g/STRING/#
command to get the matches. I read the results of this command into a list, and then process it to return a list of matching line numbers:So you could call this function on all the words you wish (or write a script to do so) and direct the output to a file. Not very elegant, perhaps, but nicely self-contained.
Hope this helps, rather than hinders.
这是由 Prince Goulash 发布的函数的修订版本。此版本采用单词列表作为输入,并返回结果的格式化和按字母顺序排列的字符串:
一种调用方法是:
拥有一长串单词应该没有问题,尽管在这种情况下您可能想要使用列表变量并获取结果当然会花费更多时间。例如:
Here is a revised version of the function posted by Prince Goulash. This version takes a list of words as input and returns a formatted and alphabetized string of the result:
One way to call it would be:
There should be no problem with having a long list of words, although in that case you would probably want to use a list variable and getting the results would of course take more time. For example:
看看 ptx,
在未修改的情况下,也许会输出类似这样的内容:
我会看看是否也可以完成其余的步骤
Have a look at ptx, perhaps
Will output something like this, when unmodified:
I'll see if I can the rest of the steps too