Hi, Dasn wrote: > On Sat, 13 Mar 2010 01:18:54 +0800, Christian Brabandt wrote: > >> Hi Tom! >> >> On Fr, 12 Mär 2010, Tom Link wrote: >> >>> The backslash also has a special meaning in the substitution (eg if >>> you want to insert \n). This should work: >>> >>> %s/.\+/\=escape(submatch(0), '\') >> >> That was what I thought I have to do. So I have to remeber to always >> escape it. >> >> I still consider it a bug. If I want backslashes to be expanded, I'll >> use printf and I think submatch(0) should return the match as it was >> found. >> >> The thing is, I often use submatch(0) when I don't want to alter the >> text. And until now, I wasn't aware of the fact, that submatch changes >> it. >> > > I don't think it's submatch(0) which changes the backslashes; it's > sub-replace-expression that does the job, and was documented, see: > :h sub-replace-special > > From what I've understood, the submatch(0) returns exactly what it > matches, however the backslashes got removed via being evaluated in the > sub-replace-expressions. For example, without using submatch(), if you try: > :%s/.\+/\='\a\b\c\d\e'/ > you would got 'abcde' without backslashes either.
I've been bitten by this, too, and I definitely think the behaviour of \= is wrong. It should not tinker with the expression it has been given at all. Interpreting the backslashes has to be done before the expression is passed over to \=. If there are backslashes inside double quotes, let the parser handle them. String literals with single quotes or strings returned from function should be left alone. If one really wants to insert some character that needs backslash-escaping he can always use double quote -- either in the literal part of the replacement string or when returning the result from a function. Regards, Jürgen -- Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us. (Calvin) -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
