mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.85k stars 711 forks source link

[REQUEST] Smart case regex modifier #4856

Open evanrelf opened 1 year ago

evanrelf commented 1 year ago

Feature

We have (?i) to start case-insensitive matching, (?I) (the default) to start case-sensitive matching, but Kakoune doesn't support Vim's smartcase behavior (case-insensitive until you add a capital letter). It would be nice if there was another modifier to enable smartcase behavior.

ripgrep also supports a --smart-case flag, which I think describes the behavior nicely:

-S, --smart-case
   Searches case insensitively if the pattern is all lowercase. Search case sensitively
   otherwise.

   A pattern is considered all lowercase if both of the following rules hold:

   First, the pattern contains at least one literal character. For example, a\w contains a
   literal (a) but just \w does not.

   Second, of the literals in the pattern, none of them are considered to be uppercase
   according to Unicode. For example, foo\pL has no uppercase literals but Foo\pL does.

   This overrides the -s/--case-sensitive and -i/--ignore-case flags.

Related issues:

Usecase

Right now I have the following mappings in my config:

map global "normal" "/" "/(?i)"
map global "normal" "?" "?(?i)"
map global "normal" "<a-/>" "<a-/>(?i)"
map global "normal" "<a-?>" "<a-?>(?i)"

I'd prefer if my search mappings were case-aware, changing behavior based on the contents of my regex, rather than needing a separate set of mappings for each behavior.

Elfahor commented 1 month ago

+1, smartcase is very convenient