1

I am currently trying to write my first plugin. So this is my first attempt at vimscript. I want to display the output of a shell command in a popup window.

This can easily achieved with:

command Cat call CatCurFile()

function! CatCurFile()
    let buf = term_start(['cat', @%], #{hidden: 1})
    let winid = popup_create(buf, #{minwidth: 120, minheight: 70})
endfunction

The popup window is built up from top to bottom, which is not pretty. I would like the have the whole terminal buffer pre-rendered somehow, so that it instantly displays everything.

cat is just an example here. The actual application is a bit slower unfortunately.

I have tried

command Cat call CatCurFile()

function! CatCurFile()
    let buf = term_start(['cat', @%], #{hidden: 1})
    let winid = popup_create(buf, #{hidden: 1, minwidth: 120, minheight: 70})
    popup_show(winid)
endfunction

but the popup is not showing. Instead an error saying menu not found is displayed. Is the id not passed right?

5
  • You have to write :call popup_show(winid) to call a function (unless you're using vim9script) (the colon is optional in scripts). Also see the "term_finish": "open" option on term_start()
    – D. Ben Knoble
    Mar 9 at 14:03
  • Works, but it is not built up faster. Guess I can sleep in between although that is ugly
    – neolith
    Mar 9 at 15:40
  • Nothing vim can do will make the external command finish faster… I’m not sure exactly what the issue is? With term_finish as open, the window doesn’t even open until the command is finished, so all the output is there.
    – D. Ben Knoble
    Mar 9 at 16:39
  • I am trying to make a vim plugin for glow, since the github.com/ellisonleao/glow.nvim does not have Vim support. The nvim version loads instantly and my version is pretty slow. Maybe there is a better way than using the terminal as popup
    – neolith
    Mar 9 at 17:04
  • Really weird, I just added a border and now it loads faster...
    – neolith
    Mar 9 at 17:08

0

Your Answer

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

Browse other questions tagged or ask your own question.