Why is there no 'very magic' option?

18 views
Skip to first unread message

bgold12

unread,
Sep 18, 2009, 6:54:06 PM9/18/09
to vim_use
I recently started doing searches with 'very magic' turned on using
\v. Obviously it would be really annoying to have to type the \v every
time you want to search for something, so I mapped / to /\v, but this
is still undesirable as it doesn't cover the * and # operations, and
it adds an unnecessary element to the search expression. Why is there
not a setting for 'very magic' that would preclude having to include
the \v in every search expression, for example set magic=very?

Thanks.

Tony Mechelynck

unread,
Sep 18, 2009, 11:18:07 PM9/18/09
to vim...@googlegroups.com

":set magic=very" is not possible, and I believe never will be, because
'magic' is a Boolean option, and IIUC Bram won't break compatibility for
this kind of reason.

Changing an existing option from Boolean to String or vice-versa has
unpleasant properties, as follows:

command Boolean option String option
-----------------------------------------------------------------
:set magic set to TRUE display
:set nomagic set to FALSE syntax error
:set magic! toggle syntax error
:set invmagic toggle syntax error
:set magic=very syntax error set to "very"
:let foo = &magic Number (0 or 1) String (actual value)
:let &magic = 0 set to FALSE set to "0"
:let &magic = 1 set to TRUE set to "1"
:let &magic = "very" set to FALSE set to "very"

In theory one could e.g. define a 'verymagic' option, also Boolean, with
the following properties:

'noverymagic' 'verymagic'
(default)
-----------------------------------------------------------------
'magic' (default) magic very magic
'nomagic' nomagic very nomagic

but unless you want (and feel capable) to program that yourself as an
unofficial patch to the C code, I don't think it's going to appear out
of the blue.


I think the reason 'magic' exists at all is that old Vi scripts assumed
the equivalent of 'nomagic' (see ":help 'magic'); in most cases it is
recommended to keep 'magic' on constantly because that's what "modern"
scripts assume; you may however set any _individual_ search to very
nomagic, (ordinary) nomagic, (default) magic, or very magic by means of
modifiers within the pattern. If you could, and did, set 'very magic'
constantly, I have a hunch that you would see some functions and
commands fail in mysterious ways: for instance because \( and \) in
their patterns would suddenly start searching for literal parentheses
instead of grouping subexpressions as they normally do.


Best regards,
Tony.
--
In Boston, it is illegal to hold frog-jumping contests in nightclubs.

Bram Moolenaar

unread,
Sep 19, 2009, 10:11:53 AM9/19/09
to Tony Mechelynck, vim...@googlegroups.com

Tony Mechelynck wrote:

> On 19/09/09 00:54, bgold12 wrote:
> >
> > I recently started doing searches with 'very magic' turned on using
> > \v. Obviously it would be really annoying to have to type the \v every
> > time you want to search for something, so I mapped / to /\v, but this
> > is still undesirable as it doesn't cover the * and # operations, and
> > it adds an unnecessary element to the search expression. Why is there
> > not a setting for 'very magic' that would preclude having to include
> > the \v in every search expression, for example set magic=very?
> >
> > Thanks.
>
> ":set magic=very" is not possible, and I believe never will be, because
> 'magic' is a Boolean option, and IIUC Bram won't break compatibility for
> this kind of reason.
>
> Changing an existing option from Boolean to String or vice-versa has
> unpleasant properties, as follows:

It's not only because of changing the option type, it's also because
changing this option results in changing the meaning of patterns
everywhere. It's a good way to break existing scripts.

The 'magic' option should not exist. It's only there for Vi
compatibility. See ":help 'magic'" for the note that you should always
keep this option at its default value.

--
If VIM were a woman, I'd marry her. Slim, organized, helpful
and beautiful; what's not to like? --David A. Rogers

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Spencer Collyer

unread,
Sep 20, 2009, 6:44:24 AM9/20/09
to v...@vim.org

Why would you want it set in the * and # cases?

--
<<< Eagles may soar, but weasels don't get sucked into jet engines >>>
11:43am up 23 days 17:38, 1 user, load average: 0.06, 0.11, 0.14
Registered Linux User #232457 | LFS ID 11703

Reply all
Reply to author
Forward
0 new messages