问题描述
我正在用 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
我试图找到一种方法来隐藏选项卡后的文本,直到我按下某个键。以前,我通过将分隔符设为换行符后跟一个制表符来完成此操作,因此文件可能如下所示:
hello
hallo
from all over the world
aus der ganzen Welt
...然后我会针对不包含选项卡的行对该文件进行 grep,将输出通过管道传输到文件,阅读并回答问题,并检查我的答案。
然而,这种方法特别麻烦,因为我的抽认卡数据库越来越大,我开始实施简单化的 spaced repetition,并且需要在特定日期(可能提前几个月)安排我的抽认卡组。
我很好奇是否有办法在 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
细分:
-
:match <group> <pattern>
将高亮组<group>
分配给当前窗口中匹配<pattern>
的文本。在这里,我们将高亮组
Conceal
分配给“tab 后跟任何内容”。见
:help :match
。 -
conceallevel
选项告诉 Vim 如何处理标记为“可隐藏”的文本。在这里,我们告诉 Vim 无条件隐藏可隐藏的文本。
见
:help 'conceallevel'
。 -
concealcursor
选项告诉 Vim 如何在移动时处理隐藏的文本。在这里,我们确保文本在正常模式下保持隐藏。
见
:help 'concealcursor'
。 -
tabstop
选项设置为一个较大的值,以确保隐藏的文本对齐,就像我喜欢的那样。对于您想要实现的目标,这不是必需的。见
:help 'tabstop'
。