I'm writing a set of flashcards in Vim for import into other applications; the format of the flashcards is exceedingly simple - it's just a CSV with two fields, a question and an answer. For example, if I were testing my German knowledge, I might use the following text file:
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
I'm trying to find a way to obscure the text after the tab until I press a key. Previously, I'd done this by having having the delimeter be a newline followed by a tab, so a file might look like this:
hello
hallo
from all over the world
aus der ganzen Welt
... I would then grep this file for lines that didn't contain a tab, pipe the output to a file, read and answer the questions, and check my answers.
However, this method is particulary cumbersome as my flashcard database grows larger and I begin to implement simplistic spaced repetition and need to schedule my flashcard sets for particular days, possibly several months in advance.
I was curious as to whether there was a way to, in Vim, hide everything on a line after a given charachter (in this case, after the first instance of the \t escape sequence), and, on a keystroke, reveal the hidden text on that line only. This would make my spaced review far easier.
I am well aware of the existence of Anki and Mnemosyne and the likes for automating spaced-repetition, however, I'd rather avoid these applications because I've shifted to for the most part using exclusively plain text for storing information, because:
(a) the unix toolset works fantastically with recursively finding information in folders, I can just grep for lines with TODO on all my project folders to generate agendas (b) plain text is far easier to manipulate (c) the unix tools are going to be here for a far longer time than any spaced repetition software (d) plain text is very information dense; at most, a backup of my entire life's information would take a megabyte or two (e) I'd like to become more competent in the Unix environment
V
(orv
, but the highlighting is nicer withV
).The behaviour outlined above is obtained with:
Breakdown:
:match <group> <pattern>
assigns highlight group<group>
to text matching<pattern>
in the current window.Here, we assign the highlight group
Conceal
to "tab followed by anything".See
:help :match
.The
conceallevel
option tells Vim how to handle text marked as "concealable".Here, we tell Vim to hide concealable text unconditionally.
See
:help 'conceallevel'
.The
concealcursor
option tells Vim how to handle concealed text while moving around.Here, we make sure that the text stays concealed in normal mode.
See
:help 'concealcursor'
.The
tabstop
option is set to a large value to ensure that the concealed text is aligned, as I like it. This is not necessary for what you want to achieve.See
:help 'tabstop'
.