Enjoying Open Source Software

Transform Mardown to Vimwiki format with sed

Vimwiki backlist function not working in Markdown

I started with a first try-out to create a Zettelkasten with Vimwiki. For this I use a Vimwiki in Markdown format.

Unfortunately, the :VWB function, which creates a list of backlinks, works only in the original Vimwiki format.

Transformation to Vimwiki format

This is my first try-out for a Zettelkasten, so I don't have many files in it. Therefor, the easiest solution seems to be to a conversion of the current Vimwiki Zettelkasten to the original Vimwiki format.

This turned out to be much simpler than it sounds :)

I do use only some simple formatting:

# Top level header
## Second level header
### Second level header

These formats has to be transformed to the original Vimwiki


= Top level header =
== Second level header =
=== Third level header ===

sed script to do the transformation

As this is not very complicated, I tried to do this with sed.

This is what does the trick:

s/\(^###\) \(.*\)/=== \2 ===/
s/\(^##\) \(.*\)/== \2 ==/
s/\(^#\) \(.*\)/= \2 =/

People with more sed-fui than I have will probably do it more efficient, but it works :)

Put this lines in a file, I called it conversion.sed and run this with some shell script to convert all the files with it to the new format, in a different directory. Also, the files have to be renamed from filename._md to

I used this as a shell script:


for file in $(ls 0??._md)
echo $file $nieuw
cat $file | sed -f conversion.sed > $nieuw

My Vimwiki Zettelkasten try-out uses base-36 encoded filenames, like 00a._md, 01n._md, and so on. So far I have about 75 files in it. That is why in the script above I use ls 0??._md.

My Vimwiki runs in a FreeBSD jail, so this used the FreeBSD versions of sed and of the shell.

Have fun!


⇽ Using Vimwiki tags Awk script to convert tsv to recutils for LaTeX ⇾