Commands such as :sort /[^A-Z]*/
to skip non-uppercase letters should typically work, except when 'ignorecase'
is set, which makes that pattern case-insensitive and will skip characters other than any letters, be them uppercase or lowercase. From the comments, it looks like you do have 'ignorecase'
enabled.
You might have the pattern /[^A-Z]*/
work correctly in a search to match non-uppercase letters (including lowercase ones), if in addition to 'ignorecase'
you also have 'smartcase'
enabled. Having both 'ignorecase'
and 'smartcase'
both enabled is a pretty common setup, since it's quite an useful combination. Make searches case-insensitive if you have all lowercase characters, but case-sensitive if you have any uppercase characters anywhere.
But it turns out that the :sort
command recognizes the 'ignorecase'
setting, but not the 'smartcase'
setting! That's why you might see one behavior for patterns in search, but a subtly different one in sorts.
I opened an issue on the Vim issue tracker about this and the conclusion is that this is the intended behavior (or, if not initially defined this way on purpose, will be maintained as such to prevent breaking backwards compatibility.) A recent update to Vim runtimes included an update to the documentation to call this out explicitly, initially shipped with Vim version 8.2.2026. The updated documentation simply states that "'ignorecase'
applies to the pattern, but 'smartcase'
is not used."
In your case, you can use the suggestions from D. Ben Knoble's answer, such as :sort /.\{-}\ze\u/
or :sort r /\u\+/
.
Another option is to use an explicit \C
in your pattern, to force it to be case-insensitive, regardless of the 'ignorecase'
setting:
:sort /\C[^A-Z]*/
'ignorecase'
enabled... You can check it with:set ic?
. Without it being on, the first one you used (:sort /[^A-Z]*/
) worked for me. – filbranden♦ Nov 17 '20 at 18:19ignorecase
enabled. When I didset noignorecase
and tried again, it worked. – Yuri Ghensev Nov 17 '20 at 19:36'smartcase'
together with'ignorecase'
(that's what I typically use), but I found that:sort
doesn't seem to respect it... Filed a bug about it: github.com/vim/vim/issues/7322 – filbranden♦ Nov 17 '20 at 23:41