Vim使用已执行bash命令的返回值
我试图检查vimscript中的文件中是否有一行代码。 我需要在if中使用grep的返回值,但我不知道如何获取它 这当然行不通:Vim使用已执行bash命令的返回值,bash,vim,return,execute,Bash,Vim,Return,Execute,我试图检查vimscript中的文件中是否有一行代码。 我需要在if中使用grep的返回值,但我不知道如何获取它 这当然行不通: if $(execute '!grep -q ' . shellescape(lineToAdd) . ' ' . shellescape(g:projectPath)) echom "Already added." return endif 如图所示,请参见v:shell\u error 最后一个shell命令的结果。当非零时,最后一个 shell
if $(execute '!grep -q ' . shellescape(lineToAdd) . ' ' . shellescape(g:projectPath))
echom "Already added."
return
endif
如图所示,请参见
v:shell\u error
最后一个shell命令的结果。当非零时,最后一个
shell命令出错。当零时,没有问题。
这仅在shell将错误代码返回给Vim时起作用。
值-1通常在命令无法执行时使用
执行。只读