gpt4 book ai didi

vimscript : clear command line after `confirm`

转载 作者:行者123 更新时间:2023-12-05 00:40:59 24 4
gpt4 key购买 nike

我有一个函数调用 confirm 来获取用户输入,执行一个操作,然后向用户打印一条消息:

function! PerformAction()
let answer = confirm('Do thing?', "&Yes\n&No", 1)
if answer == 1
call system("do_thing")
echo "Did thing!"
endif
endfunction

我遇到的问题是,这最终会迫使用户在执行命令后多按一次 [Enter],因为命令行已扩展为显示提示和消息.

是否可以防止这种情况,让用户在提示输入值后,命令行清空,执行调用系统,然后单行显示"做了什么!” 打印在命令行中,让用户可以立即继续工作?

最佳答案

如果你告诉 vim 用 :redraw 刷新屏幕,这可以解决你的问题:

function! PerformAction()
let answer = confirm('Do thing?', "&Yes\n&No", 1)
if answer == 1
call system("do_thing")
redraw
echo "Did thing!"
endif
endfunction

我不知道为什么会这样,但是 :redrawecho 的帮助页面中提到:

                            *:echo-redraw*
A later redraw may make the message disappear again.
And since Vim mostly postpones redrawing until it's
finished with a sequence of commands this happens
quite often. To avoid that a command from before the
":echo" causes a redraw afterwards (redraws are often
postponed until you type something), force a redraw
with the |:redraw| command. Example: >
:new | redraw | echo "there is a new window"

关于vimscript : clear command line after `confirm` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44892186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com