Gary Johnson wrote:
> On 2008-12-31, pansz wrote:
>   
>> pansz ??????:
>>     
>>> I see # character cannot be used in many commands, how can I escape it?
>>>
>>> For example:
>>>
>>> calling an external program with # does not work
>>>
>>> :!echo http://abc.com/index.php#foobar
>>>       
>>  >
>> Perhaps I've not make myself clear:
>>
>> when we vi ~/.bash_profile we will see lots of commands, I defined a map:
>>
>> map <C-B> 0y$:!<C-R>0<cr>
>>
>> which will execute the command in the current line.
>>
>> However, if the command in the current line contains # or % in it, 
>> things will get ruined, is there anyway to convert the output of <C-R>0 
>> into something which can be used in command line?
>>
>> For the following line:
>>
>> echo http://abc.com/index.php#foobar
>>
>> use the map to 0y$:!<C-R>0<cr> does not work, since the command will try 
>> to expand # character, and I have no way to quote <C-R>0 output before 
>> send it to command line.
>>     
>
> You can use the escape() function to escape certain characters in a 
> string.  Your mapping would then become
>
>    map <C-B> 0y$:!<C-R>=escape(@0,'#')<cr><cr>
>
> See
>
>    :help escape()
>   
The shellescape() function was designed for this situation.

Regards,
Chip Campbell


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to