Charles E. Campbell, Jr. 写道:
>> The shellescape() function will add single quotes to the string, which
>> makes the command unusable, for example:
>>
>> :!echo test
>>
>> should work.
>>
>> :!'echo test'
>>
>> will not run at all.
>>
>> Anyway to disable shellescape() from adding single quotes to the string?
>> Or is it possible to run the string with single quotes?
>>
> Hmm, sorry 'bout that -- in the current case, please try the
> fnameescape() function.
>
> Regards,
> Chip Campbell
Hmm, fnameescape makes no difference, it adds backslash to the command
and that will also make bash treat the whole command as a file name. for
example:
:!echo\ test
doe not work.
my mapping is now:
nnoremap <C-K> 0y$:!<C-R>=fnameescape(@0)<cr><cr>
When I want to execute commands in a bash shell file, the command line
are ready to execute and things like spaces do not need to be quoted.
My current solution is the following, I think there should be a better
way though.
function s:myescape(cmd)
let l:esccmd = shellescape(a:cmd, 1)
return strpart(l:esccmd, 1, strlen(l:esccmd)-2)
endfunction
nnoremap <C-K> 0y$:!<C-R>=<sid>myescape(@0)<cr><cr>
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---