On 2011-12-06, Tim Chase wrote:
> On 12/06/11 17:13, Gary Johnson wrote:
> >     :%s/^.*[[:backspace:]]//
> >
> >but I'm looking for a more general solution that also fixes lines
> >where the user has backspaced over a
> 
> You might try:
> 
> :%s/\(\_[^[:backspace:]]\+\)\([[:backspace:]]\+\)/\=strlen(submatch(1))==strlen(submatch(2))?'':(submatch(1)[:(strlen(submatch(1))-(strlen(submatch(2))+1))])/ge
> 
> It's a bit ugly, but seems to work pretty quickly against all the
> tests I threw at it.

Thanks.  It seems to work fine when applied to the whole file (even
though the message, "275 substitutions on 1 line", was odd), but
when applied to just one line or to a range of lines, it also
partially modifies the next line below the range.  I can't attach
the actual file, but here's a sanitized region with actual
backspaces replaced by the two-character sequence "^H".  The large
gaps between sequences of backspaces each contain 28 spaces.  Those
two longest lines may not come through e-mail correctly.


Line of stuff one
Line of stuff two
[more 19%] 
(q,g,space,enter)^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H       
                     
^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^HLine of stuff three
Line of stuff four
Line of stuff five
[more 28%] 
(q,g,space,enter)^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H       
                     
^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^HLine of stuff six
Line of stuff seven
Line of stuff eight


Applying your substitute command to only the "Line of stuff three" line results 
in the following (with actual backspaces again replaced by "^H").


Line of stuff one
Line of stuff two
Line of stuff three
Line of stuff four
Line of stuff five
                            
^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^HLine of stuff six
Line of stuff seven
Line of stuff eight


The "Line of stuff six" line begins with 28 spaces.

Regards,
Gary

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

Reply via email to