Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 15, 2021 11:53 am GMT

Markdown Preview in Vim

When we edit a markdown file in vim, we are not able to preview the markdown file simultaneously. I have also faced this situation, so I decided why not make one.

To be able to preview a markdown, first, we need a markdown parser.
I got to know about Glow, which renders markdown on the Command Line Interface(CLI).

To install glow, you can follow the instructions given in the Github repo of Glow.

After installing Glow I added a few lines to my vimrc

Vim Function

This function finds the path of the current file and adds it in the .lastpreview.log file. After that bel vert terminal command is executed, which opens up the terminal buffer in vim, side by side.

nmap <F4> : call PreviewerMarkdown()<CR>clear<CR>glo $(cat ~/.lastpreview.log)<CR>

Also, I made this custom mapping in vimrc. I bound my F4 key to the PreviewerMarkdown(). After PreviewerMarkdown is executed the clear command runs which clears the terminal buffer, and after this glo command runs, which is basically an alias I made for glow -s dark | less. The glo command opens the file path present in the lastpreview.log file with a pager (here less) and a suitable color scheme, and boom our markdown preview is now ready to be used.

There is room for adding more functionality to the PreviewerMarkdown(), but for this post, I chose to keep only the core functionality.


Original Link: https://dev.to/hrk2023/markdown-preview-in-vim-44bl

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To