vim-abolish
vim-abolish copied to clipboard
Request: Enable search for all coercion cases
When searching with S /some_search_term
, vim-abolish will match:
some_search_term
SOME_SEARCH_TERM
SomeSearchTerm
but not
someSearchTerm
some-search-term
some.search.term
some search term
Some Search Term
Ideally, the search tool would support all the same formats as the coercion feature: snake_case
, MixedCase
, camelCase
, UPPER_CASE
, dash-case
, dot.case
, space case
, and Title Case
Maybe a /C
modifier to keep backwards compat?
Where I would really need this is in replacement.
When I have three lines like these
my $var_class = $meta->value('var-class') // $meta->value('/var-config/class') // $ENV{VAR_CLASS} // 'v';
my $var_first_key = $meta->value('var-first-key') // $meta->value('/var-config/first-key') // $ENV{VAR_FIRST_KEY} // '^first';
my $var_main_key = $meta->value('var-main-key') // $meta->value('/var-config/main-key') // $ENV{VAR_MAIN_KEY} // '^main';
I first have to use underscores instead of hyphens in the quoted strings, then :Subvert
a couple of times, then remember to jump to the first of those lines and say /['\/]\+\zs\w<cr>cr-n.nn.n.
... (I'm too lazy to count the actual number of times I have to hit n.
!) which is way too much work, especially the remembering. Figuring out the search pattern also took a while the first time around.
I too have noticed this when trying to Subvert both file_name
and fileName
. I found that adding this line in definition of s:create_dictionary
fixes the issue:
diff --git a/plugin/abolish.vim b/plugin/abolish.vim
index 4a97542..4a695c7 100644
--- a/plugin/abolish.vim
+++ b/plugin/abolish.vim
@@ -164,6 +164,7 @@ function! s:create_dictionary(lhs,rhs,opts)
for [lhs,rhs] in items(expanded)
if get(a:opts,'case',1)
let dictionary[s:mixedcase(lhs)] = s:mixedcase(rhs)
+ let dictionary[s:camelcase(lhs)] = s:camelcase(rhs)
let dictionary[tolower(lhs)] = tolower(rhs)
let dictionary[toupper(lhs)] = toupper(rhs)
endif
It's designed first and foremost for source code identifiers, I don't want to change everything under the sun that looks vaguely similar. But I think it would be reasonable for :S/foo-bar/baz-quux/
to also get FooBar
, etc. And lower camel case is probably fine to add.
There are some languages which allow hyphens in identifiers, among them Perl 6 which even allows apostrophes, although I probably won't ever use apostrophes!
Lower camel case has a special meaning in an application of mine where the "case" of identifiers determines if and how variables are saved to persistent storage. A bit daft but works rather conveniently.
Den tors 2 maj 2019 04:08Tim Pope [email protected] skrev:
It's designed first and foremost for source code identifiers, I don't want to change everything under the sun that looks vaguely similar. But I think it would be reasonable for :S/foo-bar/baz-quux/ to also get FooBar, etc. And lower camel case is probably fine to add.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tpope/vim-abolish/issues/66#issuecomment-488534031, or mute the thread https://github.com/notifications/unsubscribe-auth/AAI3OU7ZP6HIF6UL57GAYLLPTJEIZANCNFSM4FMDMUKQ .
This would be very useful in Golang, as it's often we want to search and replace auto-generated code (so, e.g. struct_name.StructName
-> new_struct_name.NewStructName
.
It'd be very cool for search and subvert to be able to do this (search anything that matches any case supported by coerce), even if it's behind a flag (maybe a /A
ll flag?).
This would be very useful in Golang, as it's often we want to search and replace auto-generated code (so, e.g.
struct_name.StructName
->new_struct_name.NewStructName
.
You can already do this. :S/struct_name/new_struct_name/g
.
For the rest, I think the most I would be willing to extend it to is other supported punctuation characters in 'iskeyword'
. That would enable targeting hyphens in Lisp files, for example. If you replace foo_bar
, a subtraction expression like foo-bar
should not be affected.