I thought the following should work, but it doesn't:
/[@-\]]
Problem: the range is '@' to '\', and ']' ends the collection; the next ']'
matches itself.
(It's surprising that '\]' within '[]' not always means ']' literally!)
Ok, so the char directly after '-' ends the range?
/[@-]]
No, the collection is '[@-]' followed by ']' which matches itself. The
help says it:
| For '-' you can also make it the first or last character: "[-xyz]",
| "[^-xyz]" or "[xyz-]".
Ok, this works:
/[@-\\]]
but it matches the range '@-\' plus the char ']'.
A range where \] is the first character works:
/[w\]-a]\C
matches ] ^ _ ` a w
Is it a bug that '\' after '-' in a collection is taken literally?
--
Andy
> --
> You received this message from the "vim_dev" 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 can try ] followed [ immediately. i.e []@-?] Witch ? Stands for the character before ] in ASCII
> Strange: one can't write a collection with range [X-Y] where Y is the
> character ']'.
>
> I thought the following should work, but it doesn't:
> /[@-\]]
>
> Problem: the range is '@' to '\', and ']' ends the collection; the next ']'
> matches itself.
>
> (It's surprising that '\]' within '[]' not always means ']' literally!)
>
> Ok, so the char directly after '-' ends the range?
> /[@-]]
>
> No, the collection is '[@-]' followed by ']' which matches itself. The
> help says it:
> | For '-' you can also make it the first or last character: "[-xyz]",
> | "[^-xyz]" or "[xyz-]".
>
> Ok, this works:
> /[@-\\]]
>
> but it matches the range '@-\' plus the char ']'.
Well, that's correct, ] is right after \.
> A range where \] is the first character works:
> /[w\]-a]\C
>
> matches ] ^ _ ` a w
>
>
> Is it a bug that '\' after '-' in a collection is taken literally?
It's indeed stange.
--
hundred-and-one symptoms of being an internet addict:
238. You think faxes are old-fashioned.
/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
I disagree, and consider it a bug. :help /\] says:
- To include a literal ']', '^', '-' or '\' in the collection, put a
backslash before it: "[xyz\]]", "[\^xyz]", "[xy\-z]" and "[xyz\\]".
(Note: POSIX does not support the use of a backslash this way). For
']' you can also make it the first character (following a possible
"^"): "[]xyz]" or "[^]xyz]" {not in Vi}.
For '-' you can also make it the first or last character: "[-xyz]",
"[^-xyz]" or "[xyz-]". For '\' you can also let it be followed by
any character that's not in "^]-\bdertnoUux". "[\xyz]" matches '\',
'x', 'y' and 'z'. It's better to use "\\" though, future expansions
may use other characters after '\'.
This works:
/[[\\\]]
This does not work, even though it should do the same thing if the above help entry were implemented as stated:
/[[-\]]
Using your example, this does work, but I would not expect it to:
/[][-\]
I would expect this to not be treated as a collection at all, because the closing ] has a \ in front.
There is obviously at least a documentation bug here.