2017-07-03 59 views
1

後`明確的命令行我有一個調用confirm獲取用戶輸入的功能,執行一個動作,然後打印一條消息給用戶:Vimscript中: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],因爲命令行已擴展爲顯示提示和消息。

是否可以防止這種情況,以便在用戶輸入提示值後,清除命令行,執行call system,然後在命令行中打印單行顯示"Did thing!",允許用戶立即繼續工作?

回答

2

如果你告訴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 

我不知道爲什麼這個工作,但:redraw在幫助頁面被提及echo

      *: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"