Tuesday, August 28, 2012

Re: vim: how to substitute ^H into an delete action

On Tuesday, August 28, 2012 9:38:24 AM UTC-5, ping wrote:
> On 08/27/2012 11:15 PM, Ben Fritz wrote:
>
> > On Monday, August 27, 2012 3:38:00 PM UTC-5, ping wrote:
>
> >> I found :@" seems to have the same (similar) issue? or not, not sure...
>
> >>
>
> >> but I copied Ben's line into a register and tried :@", it doesn't work,
>
> >>
>
> >> looks I have to literally input them under Ex...
>
> >>
>
> >
>
> > Yeah...I suppose I should have mentioned that.
>
> >
>
> > I don't know of a way (aside from sending a .txt file attachment) to send actual literal CTRL-H characters, so I just typed ^ and then H. Which obviously does something very different than a real ^H character.
>
> >
>
>
>
> Ben, that part I understood,
>
> what I mentioned is, even after I correctly typed in c-h (via c-v c-h in
>
> vim), and I yank it with yy, but again :@" (execute the register ")
>
> doesn't work. I'm not sure it's my issue (mostly should be) or vim's
>
> current implementation...

Ok, yes I see that now, and I can reproduce. I tried entering this text in a new buffer (with ^H meaning a literal CTRL+H character):

g/^H/while getline('.') =~ '[^^H]^H' | s/[^^H]^H//g | endwhile

Yanking with yy or with 0y$ and running :@0 gives:

E33: No previous substitute regular expression
E476: Invalid command

To debug, I did:

:debug @0

and saw that the command actually being executed is:

g/while getline('.') =~ '[' | s/[//g | endwhile

It looks like executing :@0 is for some reason interpreting the characters as if typed. I don't know if this is intentional or not, but it's easy enough to fix by inserting literal ^V characters before the ^H characters before yanking.

I would expect this to be necessary to run a macro with @0 in normal mode, because those ^V characters will be in the macro if you record it. But I wasn't expecting it in the ex-mode command.

Especially, since :@: works on this command, and :reg : shows the contents as NOT including any ^V characters.

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

No comments: