LunarVim: Improve Markdown Editing with Marksman

chris@machine
4 min readMay 8, 2023

--

Marksman is a language server specifically tailored for Markdown, providing features such as syntax highlighting, completion, diagnostics, refactoring and more. It also supports wiki-link-style references that enable Zettelkasten-like, note taking. We’ll go over how to install and configure marksman for LunarVim in this article but most of the things you learn in this article will apply to Neovim and other text editors as well.

Install Marksman

Before we get started let’s install the marksman language server. We can do that will the following command:

:MasonInstall marksman

next we’ll add some config to our config.lua file to enable the the language server:

require("lvim.lsp.manager").setup("marksman")

and that’s it, marksman should be installed and we’re ready to take a look at some of the features.

Completion

Before we get started, to follow along with examples you can clone this repo:

git clone https://github.com/ChristianChiarulli/marksman-example.git

cd marksman-example

In our example repo the files are laid out like this:

We’ll start with the 01-domesticated-cats.md file. In this file try typing [[ , this will open a completion menu containing the titles in the files show above.

After making a selection you can further refine your link to subheaders contained in the file:

Hover Preview

You can place your cursor directly over one of the links and press shift+k to reveal a preview of the link.

shift+k for hover

Goto Definition

If you’d like to go to the definition of the link. You can press gd over top of the link.

after pressing gd

Find References

To find out where a particular header is being referenced you can press gr on top of the header:

gr for references

Diagnostics

Marksman provides diagnostics for links to detect broken references and duplicate/ambiguous headings.

Rename Link

If you are referencing a header across multiple files it’s probably a good idea to rename the header with space l r . This will use Marksmans rename functionality to update the header and all references.

Using dressing.nvim for the popup

Generate Table of Contents

Marksman comes with a code action for generating a table of contents for a file. To invoke the code action you can press space l a .

Ignore Files

You may have notice the file 04-ignore-me.md will not show up when completing links. This is because it has been added to the .ignore file in the root of the repository. This is helpful when you have files that you don’t want to include, in your completion results.

Conclusion

In conclusion, Marksman is a pretty cool language server designed to enhance Markdown editing in LunarVim, Neovim, and other text editors. With its ability to provide syntax highlighting, completion, diagnostics, refactoring, and wiki-link-style references, it streamlines your Markdown editing experience and facilitates efficient note-taking.

--

--