Vim 使用 return 执行的 bash 命令的值
Vim use return value of executed bash command
我正在尝试检查 vimscript 文件中是否有一行代码。
我需要在我的 if 中使用 grep 的 return 值,但我不知道热得到它。
这当然行不通:
if $(execute '!grep -q ' . shellescape(lineToAdd) . ' ' . shellescape(g:projectPath))
echom "Already added."
return
endif
见 v:shell_error
如此 Vim documentation,
Result of the last shell command. When non-zero, the last
shell command had an error. When zero, there was no problem.
This only works when the shell returns the error code to Vim.
The value -1 is often used when the command could not be
executed. Read-only.
我正在尝试检查 vimscript 文件中是否有一行代码。 我需要在我的 if 中使用 grep 的 return 值,但我不知道热得到它。
这当然行不通:
if $(execute '!grep -q ' . shellescape(lineToAdd) . ' ' . shellescape(g:projectPath))
echom "Already added."
return
endif
见 v:shell_error
如此 Vim documentation,
Result of the last shell command. When non-zero, the last shell command had an error. When zero, there was no problem. This only works when the shell returns the error code to Vim. The value -1 is often used when the command could not be executed. Read-only.