1

I have seen a guy on YouTube who has some sort of Markdown rendering in Vim.

The * sign from a list is displayed as a .
When the cursor travels over it, the actual sign shows up.
I have checked his .vimrc on GitLab, but couldn't find anything matching.
He loads a lot of plugins there, so I think it comes from one of those.

  • Can something like this be scripted directly in the .vimrc?
  • Or where and how would I script something like this?

Here is the mentioned vimrc

Vim Markdown

4
  • 2
    Welcome to Vi and Vim! This feature is actually called "conceal" (and "signs" in Vim actually means a totally different thing.) There's a 'conceallevel' and a 'concealcursor' options that you can tweak to control the behavior of when to conceal and what to do when the cursor is near. Conceal is typically programmed through the syntax engine, so you might look for specific custom Markdown setup among this person's plug-ins to see if they're using something other than what's shipped with Vim. – filbranden Dec 21 '20 at 21:54
  • 2
    Linking to the relevant vimrc would have been helpful... – filbranden Dec 21 '20 at 21:58
  • 2
    And/or the YouTube video where you saw it. – filbranden Dec 21 '20 at 21:58
  • Here the video where I've seen it: youtu.be/2TYTrsK_ry0 And here the vimrc: gitlab.com/oldrwxrob/dotfiles/-/blob/master/common/vim/vimrc – Heiko Dec 22 '20 at 19:36
1

This is probably concealing.

The first thing you'll have to do is to identify the syntax group of the character you want to transform.

As an example, let's take this typescript code:

/**
 * This function makes the sum of its arguments.
 *
 * @param nums The list of numbers to add together
 *
 * @return The sum of the given numbers
 */
function add(...nums: number[]) {
    return nums.reduce((acc, num) => acc + num, 0);
}

And let's say I want to transform the @param and @return to ⦿ and .

First, I can Identify the syntax group using this vimscript function:

function! GetGroupName()
    if !exists("*synstack") | return | endif
    echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name" )')
endfunction

You can use it by typing :echo GetGroupName() when your cursor is on the word/character to transform.


Once you have the group , in my case typescriptDocComment, I simply need to enter:

syntax match typeScriptDocTags "@param" conceal cchar=⦿
syntax match typeScriptDocTags "@return" conceal cchar=↩

And the end result:

2
  • 2
    Alas, to make it permanent you need to use the syntax directory of the after directory – D. Ben Knoble Dec 22 '20 at 13:47
  • 2
    I can confirm it is concealing, found the plugin on GitHub. Way above my current skill level though – but thank you, it is interesting to know that concealing exists. @D.BenKnoble – Heiko Dec 27 '20 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.