On 2009-10-27, Robbo wrote:
> Hello,
> if I want to insert the following command
>
> :'<,'>s/(\@<=.\{-},\|,\@<=.\{-}/^M&/g
>
> in _vimrc under and autocommand like
>
> :autocmd FileType c,cpp,h,hpp :map <C-F10> :s/(\@<=.\{-},\|,\@<=.\{-}/
> <CR>&/gc
>
> but the previous autocommand doesn't work.
>
> I don't understand if I have to escape character in generals and how
> to escaper the <CR> character.
How you insert the effect of typing Enter into a vim command depends
on the command. In this particular case, you appear to be trying to
insert a newline in front of the matched pattern. Referring to
:help sub-replace-special
you'll see that there are at least three ways to do this. The
method most often used on this list is \r.
You should also end the right side of your map with <CR> so that the
substitute is executed without you having to type Enter.
Those changes would make your autocommand:
:autocmd FileType c,cpp,h,hpp :map <C-F10>
:s/(\@<=.\{-},\|,\@<=.\{-}/\r&/gc<CR>
Note that I haven't tested it to see if those are the only issues.
You might also consider using the <buffer> option to the map command
so that this mapping affects only buffers containing C and C++ files
and not every buffer that you edit after this autocommand is
triggered. See
:help map-<buffer>
Your autocommand has another issue. You are specifying the FileType
event but the pattern includes "h" and "hpp" which are not file
types but file extensions. It will work as it is because "c" and
"cpp" are file types, but it indicates that you may be confused
about the difference between file types and extensions.
Regards,
Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---