3 ms·
I've been trying to find a similar plugin for vim. Does anyone happen to know one? In fact, I have never seen a vim plugin that add a "notation" at the end of
by trungdq88 6y ago
I've been trying to find a similar plugin for vim. Does anyone happen to know one?
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?
- JNRowe 6y agoI don't know of a plugin, but you can sorta do something kinda like the thing ish if you squint and cross your fingers... 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. ¹ https://vimhelp.org/popup.txt.html https://vimhelp.org/popup.txt.html ² https://vimhelp.org/syntax.txt.html#conceal https://vimhelp.org/syntax.txt.html#conceal
- lost-theory 6y agoI'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 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/619f04f89861c58e5a6415a4f83847752928252d/syntax/vimwiki.vim 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>
- lost-theory 6y agoAfter 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.