Sunday, December 15, 2013

Re: Regular expression and VIm

On 14.12.13 18:55, Jerry Rocteur wrote:
> This is probably the best article that I've found and used to get my
> reg exps working within Vim.
>
> http://vimregex.com/

The first example under "4.5 Grouping and Backreferences" at
that site:

:s:\(\w\+\)\(\s\+\)\(\w\+\):\3\2\1:

is neat in its effect¹, but it's all b\ac\ks\la\sh\es!

Why oh why oh why would anyone not use its human readable form:

:s:\v(\w+)(\s+)(\w+):\3\2\1:

where we can easily read the meaning at a single glance, now that the
redundant backslash snowstorm is removed.

¹ Both forms swap the first two words on a line:

one two three # becomes

two one three

Could it be a disservice to new converts to teach them an obsolete regex
dialect when it is such an obfuscated way to do things, and Vim offers a
so much more legible alternative, which is a modern posix standard form?

Erik

--
Habit is habit, and not to be flung out of the window by any man, but
coaxed down-stairs a step at a time.
- Mark Twain, "Pudd'nhead Wilson's Calendar

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment