In fact, I have never seen a vim plugin that add a "notation" at the end of each line like this one. Is it something very difficult in vim?
In fact, I have never seen a vim plugin that add a "notation" at the end of each line like this one. Is it something very difficult in vim?
You can perform actual in-place calculations by using the expression register. So for example:
= 2 + 2
<insert mode cursor here>
Then something like `<C-r>=eval(getline('1h')[2:])` will end up with: = 2 + 2
4
If you regularly did so writing a more robust mapping would probably useful.And using regular :global you could perform similar operations across a file with `:g/^= / <expression replacement>`
I think the real solution would be just to use evil-mode in emacs when you wish to use things like literate-calc-mode. I do that for org-mode because it is just so much more powerful than the basic vim plugin for org-mode files.
> Is it something very difficult in vim?
Since 8.2 was released you can use popupwin¹ to emulate something similar. I'd probably give it a go if you wrote it :P
It is a real shame you can't use a funcref(or even multiple characters) for conceal replacement, or you could simply add a conceal² for => to show the result. Such functionality would also be nice for inlining computed types in various languages too.
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>I would look into using popups, a separate pane, or something like vim-notebook.