vim后台运行程序

 

:SILENT大法

一般Vim执行外部命令后会提示你请按ENTER或其他命令继续刷新窗口,如果你想避免刷新就可以用:silent命令,而且:silent命令还可以去掉执行外部程序时的“Hit any key to close this window…” 

:silent {command}

需要注意的是执行:silent后如果需要的话可以按CTRL-L或:redraw手动刷新窗口,如果同时执行多个命令需要在每个命令前都写上:silent,如:silent !command1 :silent !command2 …。

用:silent修改之前的Vim Markdown转换:

" Markdown to HTML on Windows 
nmap <leader>md :w<cr>:silent !markdown.py "%">"%.html"<cr>:silent !"%.html"<cr>

:!START(VIM异步执行命令)这个只能在windows执行?

尽管前面的:silent大法已经可以不用频繁的按键了,但是还是会有控制台命令提示窗口弹出。有没有什么办法可以不留一点痕迹呢,这就是Vim的异步命令执行。

在Vim下用!:command会同步方式运行外部程序从而阻塞Vim窗口,等待程序运行完成才按任意键返回,而如果用异步方式的话就不会出现这种情况。Vim异步运行命令是:

:!start {command}

如果是在Windows控制台中运行的命令,需要额外加cmd /c :

:!start cmd /c "command1 param"&& command2 

用:start修改之前的Vim Markdown转换:

" Markdown to HTML on Windows
nmap <leader>md :w<cr>:silent !start cmd /c "markdown.py %>%.html" && %.html<cr>

参考

Execute external programs asynchronously under Windows

Avoiding the “Hit ENTER to continue” prompts

posted @ 2013-04-13 23:50  mipscpu  阅读(2198)  评论(0编辑  收藏  举报