Tuesday, March 12, 2013

Re: vim: want control character in substitution string

On Mar 11, 4:48 pm, Gary Johnson wrote:
>On 2013-03-11, Paul wrote:
>> After much reading, I found that I can match ^@ with \%x00 in the
>> search string, but I haven't found a way to specify control
>> characters in the substitution string. Is there a way?
>
> You can use the nr2char() function as a replacement expression,
> e.g.,
>
> :%s/\^D/\=nr2char(4)/g
>
> See
>
> :help sub-replace-expression
> :help nr2char()

This is great! I learn about nr2char as well as \= at the same time!

As Ben said, however, ^@ seems special and nr2char(0) doesn't seem to
stick a ^@ in the substitution. However, his trick of using \n in the
substitution string gets around that.

Thanks!

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: