Loading ...
Sorry, an error occurred while loading the content.
 

Re: Strange behaviour in %s/.../\=.../

Expand Messages
  • Jürgen Krämer
    Hi, ... it does work in this case where nr2char() only returns one character, but in the more general case with a function returning a longer string the only
    Message 1 of 5 , Feb 26, 2006
      Hi,

      Gerald Lai schrieb:
      >
      > On Fri, 24 Feb 2006, J?rgen Kr?mer wrote:
      >
      > > originally I had a file with names of the ASCII control codes, each in
      > > one line, and I wanted to make a table with the decimal and hexadecimal
      > > values and the common control+letter description. For this I used the
      > > following command (all in one line)
      > >
      > > :%s/^/\=StringOfChar(' ', (line('.') <= 10)) . (line('.') - 1) . ' | $' . toupper(Hex(line('.') - 1)) . ' | ^' . nr2char(64 + line('.') - 1) . ' |'/
      > >
      > > which failed when it came to writing '^\'.
      >
      >
      > Would adding an extra backslash after ^ (but before the single-quote)
      > help? It should be quite safe to escape every sequence. Something like:
      >
      > :s/^/\='<\\>'
      >
      > works for me to produce <\>

      it does work in this case where nr2char() only returns one character,
      but in the more general case with a function returning a longer string
      the only way is to wrap the function with a call to escape(..., '\').
      And I find this quite cumbersome -- and a little bit illogical, because
      a backslash normally only has a special meaning inside VIM if you enter
      it directly, not when it is returned by 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)
    Your message has been successfully submitted and would be delivered to recipients shortly.