A vim command confuses me. I have read and re-read :help shellescape()
several times. I still don't understand the meaning of the number 1
in shellescape(expand('%:p'), 1)
.
Here's the full command I'm trying to understand:
:nnoremap <F4> :exe ':silent !"c:\Program Files\Mozilla Firefox\firefox.exe"'shellescape(expand('%:p'), 1)<CR>
Let's break down this long command piece by piece.
:exe
is to execute some command.:silent !
is to execute a shell command silently"c:\Program Files\Mozilla Firefox\firefox.exe"
can call my firefox program.shellescape()
, there are blanks to be escaped. expand('%:p')
can get current file name in full expression that is path + filename.What does this excerpt from the help page mean?
With a |non-zero-arg| {special} and 'shell' containing "csh" in the tail it's
escaped a second time.
Is there some meaning such the same as 1 or 2 in s/(ha.*)(world)/\2\1/g
?
please take a simple example in detail.
And i have two questions related to the topic.
1.In which way i can get how many type of shells in my gvim?
2.In which situation can i change 1
into 2
in shellescape()?
:nnoremap <F4> :exe ':silent !"c:\Program Files\Mozilla Firefox\firefox.exe"'shellescape(expand('%:p'), 2)<CR>
There are basically two different uses for shellescape()
; one is the Vimscript system()
function, the other the :!
Ex command. While most escaping needs are identical in both uses (e.g. to deal with whitespace, arguments must be enclosed in quotes), the :!
command requires some additional escaping, because on the command-line, Vim assigns special meaning to symbols like %
(replacing it with the current file name). This does not happen for system()
.
Therefore, to tell shellescape()
which escaping mode to use, it has the additional {special}
argument; if you pass 1
(or any other value that evaluates to "true"), the additional characters are escaped, too.
TL;DR: Pass 1
for :!
commands, 0
or omit the argument for use with system()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With