2013-06-29 124 views
0

當我使用:!運行shell命令,如:在gVim的運行shell命令沒有呼應Vim命令

!echo hi 

它打印兩個Vimscript中的命令,它的輸出,所以我得到:

:!echo hi 
hi 

當我在命令行模式下執行時,這是可以的,但是當我通過.vim文件運行它時,我不想看到它 - 我只想查看命令的結果。

有沒有辦法可以禁用VimScript命令的回顯?

我知道我可以使用

echo system('echo hi') 

但是,這會阻止我使用它與交互的shell程序......

順便說一句,我使用Linux - 在Windows中,這是不是一個真正的因爲反正一個新的控制檯窗口中運行shell命令的問題...

編輯

這是我的小工作示例:

function! RunShellTask(cmd) 
    execute '!'.a:cmd 
    return v:shell_error 
endfunction 

call RunShellTask('echo hi') 

:source %

+1

你是如何執行'.vim'文件? – vidit

+0

@vidit查看更新至問題 –

+0

@IdanArye你在gvim嗎?我沒有看到在命令行版本中輸出的命令 – FDinoff

回答

0

運行它,你可以嘗試:redir命令:

     *:redi* *:redir* 
:redi[r][!] > {file} Redirect messages to file {file}. The messages which 
        are the output of commands are written to that file, 
        until redirection ends. The messages are also still 
        shown on the screen. When [!] is included, an 
           : 
           : 
        To stop the messages and commands from being echoed to 
        the screen, put the commands in a function and call it 
        with ":silent call Function()". 
        An alternative is to use the 'verbosefile' option, 
        this can be used in combination with ":redir". 

我沒有測試過,但你可以嘗試:redir @b,從執行shell命令一個用:silent call調用的函數,讀取輸出(從寄存器b),過濾掉vimscript命令,將其顯示在屏幕上,然後顯示:redir end

另一種方法是嘗試一些插件,提供類似的功能:

+0

謝謝,但這些都不符合我的目的。 –

+0

你的意思是插件?你用':redir'試過程序嗎? – mMontu

+0

':redir'不能幫助我,因爲VimScript命令仍然回顯到屏幕。至於插件 - 就像我所說的,我不想從Vim運行交互式shell。當我需要它時,我更喜歡[VimShell](https://github.com/Shougo/vimshell.vim),但這不是問題。 –