[英]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.