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
Wednesday, August 29, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment