top | item 25503539

(no title)

lost-theory | 5 years ago

I've looked into this a bit and the closest thing I could find is in VimWiki, where certain plaintext patterns are dynamically replaced with other text without actually changing the buffer.

See how line 11 dynamically changes in this video based on whether his cursor is on the line:

https://youtu.be/C0OwhiCp2Hk?t=223

I believe this is done using "conceal" as JNRowe says, e.g. here:

https://github.com/vimwiki/vimwiki/blob/619f04f89861c58e5a64...

I also second what JNRowe says about trying the new popup feature. I recently used this to run a script that calculates something based on where my cursor is currently at in the file, then show the result at the cursor using a popup:

    fun! CalculateFoodCalories()
      let day = GetSectionName()
      let day = substitute(day, "\[", "", "g")
      let day = substitute(day, "\]", "", "g")
      let out = split(trim(system("food --date=" . day)), "\n")
      call popup_atcursor(out, #{ title: "Today's calories", highlight: 'Statement', border: [],  padding: [1,2,1,2]})
    endfun
    nnoremap <silent> <leader>m :call CalculateFoodCalories()<CR>

discuss

order

lost-theory|5 years ago

After looking into how conceal works, it doesn't look like you can use it to "annotate" a line or dynamically change the text on the screen without actually changing the contents of the buffer. It can only be used to hide some pattern of text that's already in the buffer.

I would look into using popups, a separate pane, or something like vim-notebook.