[英]what does the number 1 in the shellescape function mean in vim?
vim命令让我困惑。 我已阅读并重新阅读:help shellescape()
几次。 我仍然不明白shellescape(expand('%:p'), 1)
数字1
的shellescape(expand('%:p'), 1)
。
这是我试图理解的完整命令:
:nnoremap <F4> :exe ':silent !"c:\Program Files\Mozilla Firefox\firefox.exe"'shellescape(expand('%:p'), 1)<CR>
让我们一块一块地分解这个长命令。
:exe
是执行一些命令。 :silent !
是静默执行shell命令 "c:\\Program Files\\Mozilla Firefox\\firefox.exe"
可以调用我的firefox程序。 shellescape()
,有空白逃脱。 expand('%:p')
可以在完整表达式中获取当前文件名,即path + filename。 从帮助页面中摘录的内容是什么意思?
使用|非零arg | {special}和'shell'在尾部包含“csh”
第二次逃脱。
在s/(ha.*)(world)/\\2\\1/g
是否有一些与1或2相同的含义?
请详细举一个简单的例子。
我有两个与该主题相关的问题。
1.我可以通过哪种方式获得我的gvim中有多少种贝壳?
2.在哪种情况下我可以在shellescape()中将1
改为2
?
:nnoremap <F4> :exe ':silent !"c:\Program Files\Mozilla Firefox\firefox.exe"'shellescape(expand('%:p'), 2)<CR>
shellescape()
基本上有两种不同的用途; 一个是Vimscript system()
函数,另一个是:!
退出命令。 虽然大多数转义需求在两种用途中都是相同的(例如,处理空格,参数必须用引号括起来), 但是:!
命令需要一些额外的转义 ,因为在命令行中,Vim为%
符号赋予特殊含义(用当前文件名替换它)。 system()
不会发生这种情况。
因此,要告诉shellescape()
哪种转义模式,它有额外的{special}
参数; 如果传递1
(或任何其他评估为“true”的值),则其他字符也会被转义。
TL; DR:通过1
:!
命令, 0
或省略用于system()
的参数。
来自shellescape()
的帮助shellescape()
:
shellescape({string} [, {special}]) shellescape()
Escape {string} for use as a shell command argument.
On MS-Windows and MS-DOS, when 'shellslash' is not set, it
will enclose {string} in double quotes and double all double
quotes within {string}.
For other systems, it will enclose {string} in single quotes
and replace all "'" with "'\''".
When the {special} argument is present and it's a non-zero
Number or a non-empty String (non-zero-arg), then special
items such as "!", "%", "#" and "<cword>" will be preceded by
a backslash. This backslash will be removed again by the :!
command.
您的示例中的1
只是告诉shellescape()
使用反斜杠转义特殊字符。 如果你有(说)一个!
在expand()
返回的路径中,它将替换为\\!
。
shell
是一个选项:
'shell' 'sh' E91
'shell' 'sh' string (default $SHELL or "sh",
MS-DOS and Win32: "command.com" or
"cmd.exe", OS/2: "cmd")
global
Name of the shell to use for ! and :! commands.
- :help 'shell'
“ With a non-zero-arg {special} and 'shell' containing "csh" in the tail it's escaped a second time
”意味着如果像你的例子那样, shellescape()
被赋予special
的非零参数(你的例子有一个1
),它将检查shell
的"csh"
,如果它找到它(如果你的shell
被设置为包含csh
东西),它将双重转义它。
编辑专门回答添加到(编辑)原帖的两个问题:
您可以使用:echo &shell
获取shell
设置(在shellescape()
帮助引用中引用)。
2
是Number
且非零。 因此,您应该能够在示例中将2
替换为1
并获得相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.