我正在 Vim 中编写一组抽认卡以导入其他应用程序;抽认卡的格式非常简单——它只是一个包含两个字段、一个问题和一个答案的 CSV。例如,如果我要测试我的德语知识,我可能会使用以下文本文件:
hello hallo
from all over the world aus der ganzen Welt
unfortunately leider
against Denmark gegen Dänemark
Germany lost Deutschland hat verloren
the French team die französiche Mannschaft
the team won the competition die Mannschaft hat den Wettbewerb gewonnen
every game jedes Spiel
every game lasted an hour jedes Spiel hat eine Stund egedauert
almost three thousand people fast dreitausend Menschen
they saw every game sie haben jedes Spiel gesehen
the tickets were cheap die Tickets waren billig
particularly besonders
on the table auf dem Tisch
on the terrace auf der Terrasse
already schon
key Schlüssel
cutlery Besteck
no glasses keine Gläser
went ging
into the kitchen in die Küche
to fetch zu holen
You don't need a glass du brauchst kein Glas
he called Er hat angerufen
he has to work er muss arbeiten
I am cross ich bin böse
he will come er wird kommen
he will eat dessert er wird Nachtisch essen
Run Code Online (Sandbox Code Playgroud)
我试图找到一种方法来隐藏选项卡后的文本,直到我按下一个键。以前,我通过让分隔符是一个换行符后跟一个制表符来完成此操作,因此文件可能如下所示:
hello
hallo
from all over the world
aus der ganzen Welt
Run Code Online (Sandbox Code Playgroud)
... 然后,我会针对不包含选项卡的行对该文件进行 grep,将输出通过管道传输到文件,阅读并回答问题,并检查我的答案。
然而,这种方法特别麻烦,因为我的抽认卡数据库越来越大,我开始实施简单的间隔重复,需要在特定的日子里安排我的抽认卡组,可能提前几个月。
我很好奇是否有办法在 Vim 中隐藏给定字符后一行上的所有内容(在这种情况下,在 \t 转义序列的第一个实例之后),并在击键时显示隐藏的仅该行上的文本。这将使我的间隔审查更容易。
我很清楚 Anki 和 Mnemosyne 等用于自动间隔重复的存在,但是,我宁愿避免使用这些应用程序,因为我已经转向大部分使用纯文本来存储信息,因为:
(a) unix 工具集非常适合在文件夹中递归查找信息,我可以在我的所有项目文件夹中使用 TODO 搜索行以生成议程 (b) 纯文本更容易操作 (c) unix 工具将在这里的时间比任何间隔重复软件都要长得多 (d) 纯文本信息非常密集;最多,我一生信息的备份需要一两兆字节 (e) 我想在 Unix 环境中变得更有能力
V( 或v,但突出显示更好V)时,文本可见。上面概述的行为是通过以下方式获得的:
:match Conceal /\t.*/
:set conceallevel=3
:set concealcursor=nc
:set tabstop=40
Run Code Online (Sandbox Code Playgroud)
分解:
:match <group> <pattern>将高亮组分配给当前窗口中的<group>文本匹配<pattern>。
在这里,我们将突出显示组分配Conceal给“选项卡后跟任何内容”。
见:help :match。
该conceallevel选项告诉 Vim 如何处理标记为“可隐藏”的文本。
在这里,我们告诉 Vim 无条件隐藏可隐藏的文本。
见:help 'conceallevel'。
该concealcursor选项告诉 Vim 如何在移动时处理隐藏的文本。
在这里,我们确保文本在正常模式下保持隐藏。
见:help 'concealcursor'。
该tabstop选项设置为一个较大的值,以确保隐藏的文本对齐,就像我喜欢的那样。这对于您想要实现的目标来说不是必需的。
见:help 'tabstop'。