escape / after \V

23 views
Skip to first unread message

Bee

unread,
Jul 29, 2012, 12:00:18 PM7/29/12
to vim_dev
escape / after \V

:help \V

Use of "\V" means that in the pattern after it only the backslash has
a special meaning. "very nomagic"

I have a function:

function! Visual2Highlight()
let @/ = '\c\V' . substitute(escape(@@,'/\'),'\n','\\n','g')
execute '3match User1 /' . @/ . '/'
endf
vnoremap <F12> y:call Visual2Highlight()<cr>

If / is NOT included in escape(@@,'/\') it does NOT work.

If I use the function on line(s) that have a / then I get an error:
Example: Visually select this whole line:

" multi-line visual to /highlight

Error detected while processing function Visual2Highlight:
line 2:
E488: Trailing characters: 3match User1 /\c\V" multi-line visual to /
highlight\n/

It looks like / still has special meaning.
What is happening?

Bill

Gary Johnson

unread,
Jul 29, 2012, 2:11:46 PM7/29/12
to vim_dev
In the 3match command, you are using / to delimit the pattern, so
any / within the pattern will have to be escaped, otherwise the
first one will terminate the pattern and the following characters
will be seen as "trailing characters".

Regards,
Gary

Tony Mechelynck

unread,
Jul 30, 2012, 3:37:07 AM7/30/12
to vim_dev
Or, you could use any character instead of / if there is one which you
know will not happen in the pattern, for instance

exec '3match User1 �' . @/ . '�'

if you know that there will be no � sign in what you just put into @/ in
the preceding :let statement.


Best regards,
Tony.
--
"I'd love to go out with you, but I'm staying home to work on my
cottage cheese sculpture."

Reply all
Reply to author
Forward
0 new messages