Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Find and replace with preserve case #165

Closed
jasonkim opened this issue Mar 20, 2014 · 40 comments
Closed

Find and replace with preserve case #165

jasonkim opened this issue Mar 20, 2014 · 40 comments

Comments

@jasonkim
Copy link

When you search for abc (case insensitive) and want to replace it with xyz, it should match on Abc and replace it with Xyz. This is a feature that I found useful in sublime.

@izuzak
Copy link
Contributor

izuzak commented May 30, 2014

Adding a comment from a related issue:

This could be an option for find-and-replace. Looking at the docs for emacs it looks like this will only work in these specific cases.

Search: moo, Replace: foo

If the search result is in all caps, the replacement is all caps. MOO becomes FOO
First character's case is maintained. Moo becomes Foo

Search: moO, Replace: Foo

Will only replace direct matches of moO

Search: moo, Replace: FoO

If the search result is in all caps, the replacement is all caps. MOO becomes FOO
Everything else gets replaced with FoO

@benogle
Copy link
Contributor

benogle commented May 30, 2014

Wow that seems really complicated and hard to reason about. Especially

Search: moo, Replace: FoO

If the search result is in all caps, the replacement is all caps. MOO becomes FOO
Everything else gets replaced with FoO

@focusaurus
Copy link

👍 @benogle I don't personally need that edge case. I just want the very common case of accomplishing both user -> person and User -> Person in a single pass.

@guillaume86

This comment has been minimized.

@claaslange

This comment has been minimized.

@orospakr
Copy link

Emacs also has this behaviour, by default, and it's profoundly useful.

http://www.gnu.org/software/emacs/manual/html_node/emacs/Replacement-and-Case.html

@littlebee
Copy link

+1 very useful intelliJ feature. I miss. Here is the use case, it is not, imnsho, an "edge" case considering we frequently, for multiple languages, mix the case to indicate something is a class or a var. I want to replace 'collection' below with 'model' without doing 2 f&r:

  ###
    Collection component provides a collection context to all children
  ###
  class x.Collection extends React.Component
    displayName: "widgets.react.Collection"

    @propTypes:
      collection: React.PropTypes.oneOfType([
        React.PropTypes.instanceOf(Backbone.Collection)
        React.PropTypes.func
      ]).isRequired
      fetch: React.PropTypes.bool
      fetchOptions: React.PropTypes.object

@Rosseyn

This comment has been minimized.

@BigWillie

This comment has been minimized.

@keomaborges
Copy link

+1 - I still have to open Sublime to do this kind of replace.

@adamreisnz
Copy link

This issue was opened almost 2 years ago, it would be great to have it implemented.

I too would find it very useful, since in my Angular projects I often need to duplicate existing modules and then rename their name to something else. This affects not only the module name, but also the controller name, template name, etc. And these could all be in different cases, for example camelCase, PascalCase, or lowercase. Currently, this requires three find & replace operations to accomplish in this sample code (for picktime):

/**
 * Module definition and dependencies
 */
angular.module('Shared.PickTime.Modal', [])

/**
 * Config
 */
.config(function($modalProvider) {

  //Modal definition
  $modalProvider.modal('pickTime', {
    templateUrl: 'shared/modals/picktime.html',
    controller: 'ModalPickTimeCtrl'
  });
});

If there'd be a toggle to trigger case-aware replacement, that would save a lot of time.

Bonus points if support for snake_case or kebab-case (dasherized) strings can also be added. That would probably involve detection of what case the search term and replacement term are in (and I think both should match, e.g. won't work if you try to find "FooBar" and replace it with "bar-foo" with this option turned on -- you can use regular replace for that). Then, if doing a find & replace with the toggle turned on, all other case variants could be generated from the search term and found & replaced by the equivalently cased replacement term.

@ronnyroeller

This comment has been minimized.

@siliconjohn

This comment has been minimized.

@mliq

This comment has been minimized.

@diddierh

This comment has been minimized.

@hillam

This comment has been minimized.

2 similar comments
@notadamking

This comment has been minimized.

@friedmud

This comment has been minimized.

@bostrom
Copy link

bostrom commented Sep 29, 2016

An Atom port of Sublime's MultiEditUtils would be awesome!

@rromanw

This comment has been minimized.

@itlamb
Copy link

itlamb commented Nov 14, 2016

Please try my new package https://atom.io/packages/case-keep-replace ;)

@adamreisnz
Copy link

@itlamb Didn't work for me unfortunately. First test I tried was to replace amountowing to amountneeded with your package, but it didn't make replacements in this code:

$scope.amountOwing = user.getMoneyOwing();

After pressing replace button it just wouldn't do anything. No message, no result, no replacements :(

@itlamb
Copy link

itlamb commented Nov 14, 2016

Hey @adambuczynski, could you check if there is any massage in Developer Tools / Console? But if you enter amountowing string it will not be found - it doesn't work that way. You should enter amountOwing and amountNeeded and the package will look for amountOwing, AmountOwing, AMOUNTOWING and replace them by amountNeeded, AmountNeeded and AMOUNTNEEDED.

@adamreisnz
Copy link

@itlamb ah right sorry, my example didn't make sense.

@adamreisnz
Copy link

adamreisnz commented Nov 14, 2016

It would be nice there'd also be a way to handle dashes and underscores properly as a part of this issue, e.g. snake case and dasherized strings.

This is because usually when refactoring code one would need to refactor several different common formats of essentially the same string, e.g.:

  • someString
  • SomeString
  • some-string
  • SOME_STRING

@itlamb

This comment has been minimized.

@Ben3eeE
Copy link
Contributor

Ben3eeE commented Nov 14, 2016

@itlamb @adambuczynski Can you please move the conversation about another package to that packages repository. Thanks.

@adamreisnz
Copy link

adamreisnz commented Nov 14, 2016

@Ben3eeE my last comment was specific to this issue, sorry if this wasn't clear.

...as a part of this issue...

@exdeniz

This comment has been minimized.

3 similar comments
@henhal

This comment has been minimized.

@marcelovsantos

This comment has been minimized.

@RingOfStorms

This comment has been minimized.

@okonomiyaki3000

This comment has been minimized.

@json2d

This comment has been minimized.

@RustyDev

This comment has been minimized.

2 similar comments
@parkan

This comment has been minimized.

@jramaex

This comment has been minimized.

@lee-dohm
Copy link
Contributor

Thanks for everyone's help and suggestions. Unfortunately, upon further review this isn't something that we want to maintain long-term. We do think that it would be very useful as a community package however.

Thanks again for everyone's input.

@jagadeesh52423
Copy link

I would like to give my suggestion here. Whenever user tries to replace a word, then we just need to find whether all are in same case or different. If not different, then we can replace normally. else we can show them suggestions as set
[lets say user is trying to find "foo" and replacing with "bar"]
foo -> bar
Foo -> Bar
fOo -> bar [this is difficult if we lengths are different, so we will show them normal option]
These foo's are set of different cases in user's search.
user will chose and replace accordingly.
Ping me at jagadeesh52423@gmail.com if you need more clear picture.

@hmrm
Copy link

hmrm commented Aug 9, 2019

@lee-dohm is there a link available to aforementioned review?

darangi added a commit that referenced this issue Mar 23, 2021
Add preserve case option for buffer replace. References #165.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests