簡體   English   中英

shellescape函數中的數字1在vim中意味着什么?

[英]what does the number 1 in the shellescape function mean in vim?

vim命令讓我困惑。 我已閱讀並重新閱讀:help shellescape()幾次。 我仍然不明白shellescape(expand('%:p'), 1)數字1shellescape(expand('%:p'), 1)

這是我試圖理解的完整命令:

:nnoremap <F4> :exe ':silent  !"c:\Program Files\Mozilla Firefox\firefox.exe"'shellescape(expand('%:p'), 1)<CR>   

讓我們一塊一塊地分解這個長命令。

  • 命令是將exe命令映射到F4中。
  • :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東西),它將雙重轉義它。

編輯專門回答添加到(編輯)原帖的兩個問題:

  1. 您可以使用:echo &shell獲取shell設置(在shellescape()幫助引用中引用)。

  2. 2Number且非零。 因此,您應該能夠在示例中將2替換為1並獲得相同的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM