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

:s/../../ and CTRL chars in strings

Expand Messages
  • Zdenek Sekera
    I have a string: let string= ^@0^D^I^I^I^I «^V» ^V( ^@^@if ( «^V» All chars preceeded by a caret ^ are in fact CTRL-.. chars just as « and » are
    Message 1 of 1 , Nov 29 4:55 AM
      I have a string:

      let string='^@0^D^I^I^I^I" «^V»"^V( ^@^@if ( «^V»'

      All chars preceeded by a caret '^' are in fact CTRL-.. chars
      just as « and » are <M-+> and <M-;>

      This is used in a script, the 'string' comes formed from 'somewhere'.

      Now I need to do a string substitution

      exe "silent! s/something/".string."/"

      The replacement works but the resulting line doesn't display
      correctly, I get:

      ^@0^D " «^V»( ^@^@if ( «^V»

      Basically only tabs (^I) get expanded, the other CTRL chars cause
      troubles. They are still CTRL in that line above, not two chars
      e.g. '^' and 'D'. If I mark beginning (ma) and end (mb) of 'something'
      and do the replacement this way:

      exec "norm `ad`bxi".string."\<ESC>\<CR>"

      everything works as expected.

      Why cannot I use the :s for the same, or rather, what am I
      doing wrong (what should I do with all those control chars
      in my string before calling :s to make it work?

      The 'h substitute' talks very evasively about CTRL-V:

      Note: In previous versions CTRL-V was handled in a special way. Since
      this is
      not Vi compatible, this was removed. Use a backslash instead.

      But that's all I could find nothing about other CTRL-...
      I didn't try to replace all CTRL-V in my string by a '\' because
      I'd have to write a routine for it (I will if I have to), I can't use
      'substitute()' -> catch 22 !)

      So what can/should I do? I'd really like to use :s/../../ syntax
      rather than marks syntax I indicated above).

      Any help?


    Your message has been successfully submitted and would be delivered to recipients shortly.