Thursday, August 30, 2012

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

really nice, all concern removed now.

so to conclude: this is the best practice so far for use in vimscripting:

.w/o warning
----
:g/[\b]/while getline('.') =~ '[^\b]\b' | s/[^\b]\b//g | endwhile
----

or
.w/ (harmless) warning
----
:while 1 | %s/[^\b]\b//g | endwhile
----

I tested both.


On 08/29/2012 10:13 AM, Ben Fritz wrote:
> On Tuesday, August 28, 2012 11:25:41 PM UTC-5, John Little wrote:
>> What's wrong with
>>
>> %s/[^\b]\b//g
>>
>> repeated till it finds nothing? Or do it once to check it out, then get vim to repeat it:
>>
>> :while 1 | %s///g | endwhile
>>
>> Regards, John
>
> Nothing wrong with that. Actually it's pretty clever to have an infinite loop ended only by the "no matches" error when you've removed them all. I was avoiding the error by using a :g and repeating a substitute on each line until there were no longer any matches with an explicit check. Your way is not as clear at first glance but almost certainly faster and more efficient. I've got to remember to take advantage of the "error-ends-X" behavior in mappings, macros, and loops more often.
>
> Using \b instead of a literal ^H also removes the problem of yanking and executing the command. I didn't know about \b (since I almost never have text with a literal backspace character). Thanks for sharing!
>

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