Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Preserve Case - Find / Replace #9798

Closed
shaneparsons opened this issue Jul 26, 2016 · 39 comments
Closed

Feature Request: Preserve Case - Find / Replace #9798

shaneparsons opened this issue Jul 26, 2016 · 39 comments
Labels
editor-find Editor find operations feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@shaneparsons
Copy link

It'd be awesome if a preserve case feature was eventually added to the find/replace functionality!

ST3's implementation of it is a good example if you need one.

@kieferrm kieferrm added the feature-request Request for new features or functionality label Jul 26, 2016
@alexdima alexdima added the editor-find Editor find operations label Aug 2, 2016
@alexdima alexdima added this to the Backlog milestone Aug 2, 2016
@peabnuts123
Copy link

This would be life-changing

@axefrog
Copy link

axefrog commented Mar 1, 2017

Example: currently implementing an immutable red/black tree, and there is an if/else statement, with each branch containing a mirror of the other branch. To implement the second branch, I need to replace all instances of "left" with "right" and vice versa. This includes:

  • left/right (local variable)
  • Left/Right (part of a function name)
  • LEFT/RIGHT (a constant indicating branch direction)

A case-insensitive replacement operation would make this doable in one step. Instead, I have to first replace each case of left with foo (3 steps). Next I replace each case of right with left (3 more steps). Finally, I replace foo with right, for a total of 9 steps. With case insensitive replacement, it'd be 3 steps total.

@alexdima alexdima removed their assignment Mar 28, 2017
@rebornix rebornix self-assigned this Apr 28, 2017
@rebornix
Copy link
Member

rebornix commented May 6, 2017

Let's track the setting persistence in #6158

@rebornix rebornix closed this as completed May 6, 2017
@rebornix rebornix added the *duplicate Issue identified as a duplicate of another issue(s) label May 6, 2017
@ant31
Copy link

ant31 commented May 9, 2017

@rebornix I think this is not a duplicated issue.
The issue #6158 is about 'saving' the setting.
This issue (from what I read) is about keeping the case for the replaced word (default in emacs)
eg:

foo-bar
FOO-BAR
Foo-Bar
// find: foo-bar
// replace: keep-case
keep-case
KEEP-CASE
Keep-Case

@axefrog
Copy link

axefrog commented May 9, 2017

@ant31 The feature is/would be per-character, not per word, which means your example would resolve as:

// find: foo-bar
// replace: keep-case
keep-case
KEEP-CAse
Keep-case

@rebornix rebornix removed the *duplicate Issue identified as a duplicate of another issue(s) label May 9, 2017
@rebornix
Copy link
Member

rebornix commented May 9, 2017

Sorry for closing it too fast and Thank you for making it clear, it's a valid feature request.

@vilicvane
Copy link

vilicvane commented Jun 14, 2017

Just wrote a simple extension that covers some use cases. Check out https://marketplace.visualstudio.com/items?itemName=vilicvane.sensitive-replace

@alexgvozden
Copy link

alexgvozden commented Aug 25, 2017

this should work exactly like described in case when using Cmd + D , Add selection to Next Find

there are so many situations in using camel case / hungarian notation where it would be useful...

hope it gets built in ? :)
I'll take a look also how I can build it and assign Cmd + D to it

@peabnuts123
Copy link

@vilic 's extension looks almost perfect, it just needs to be across an entire project 👍

@rebornix rebornix removed their assignment Sep 5, 2017
@mrahhal
Copy link
Contributor

mrahhal commented Mar 29, 2018

While an extension can get the job done, being built into the Find/Replace window would be ideal, with an option right next to "Use Regular Expressions", that searches in the entire file.

This hasn't been active in a long while. Is this not planned anymore? This would truly be a life changer.

@sdlins
Copy link

sdlins commented May 12, 2018

It would be really appreciated! PHPStorm has this feature for at least 2 years.

Unfortunatelly, the extension (even being good) does not get the job done in my case (pun not intended) because so many times I have to search/replace over all project's files, not only on a selected text.

@todd-skelton
Copy link

Really need this. I'm having to do 3 find and replaces where a case preserve would make it only 1.

Find: foo
Replace: bar

FOO->BAR
Foo->Bar
foo->bar

@JasonWThompson
Copy link

The way Eclipse does this is through a regex replace token \C.

So I can search for foobar and replace it with \Cbazqux and it will work as expected.

@gui679
Copy link

gui679 commented Oct 24, 2018

Why the freak this is not implemented yet ?

@ant31
Copy link

ant31 commented Nov 27, 2018

not qualify as an excuse for it

As far as I know, they don't owe you an excuse to NOT implement a feature.
Plus who are 'they'? It's an opensource project with 700+ contributors! maybe it's time for you to contribute too instead of whining?

@Eccenux
Copy link

Eccenux commented Nov 28, 2018

It's not just any open source project. And not everyone can contribute. It's an important project of Microsoft connected with their effort do being nice to devs again and with their effort to spread TypeScript (among other things I guess).

But... Yet another comment with why is this not implemented is not helpful for devs. Just add +1 to the initial comment and maybe some PM from Microsoft will finally make time to do this.

@clshortfuse
Copy link

I just found out that Mac OS X has something called "Paste and Match Style" which defaults to Shift+Cmd+V. I think this can be used, if you can consider the capitalization of a word to be its "style".

@BillDenton
Copy link

Nearly 3 years. Is there any hope of this getting implemented?

@itsafire
Copy link

Today was my day to really try vscode. I'm back to emacs with its case aware search and replace. This feature is really very important for refactoring. The current implementation can do harm your code.

@alexplummer
Copy link

Today was my day to really try vscode. I'm back to emacs with its case aware search and replace. This feature is really very important for refactoring. The current implementation can do harm your code.

Seems a tad overly dramatic no? If it really is such a game changer and so vital for refactoring, why not just use the extension provided further up the page?

@leawp
Copy link

leawp commented Jul 5, 2019

@itsafire
You can do it somewhat with regex capturing groups
Search term: (benev)(a)(lence)
Replace with: ${1}o${3} (you can omit the {} but they're sometimes necessary)

obraz

it will match regardless of case so the result will be

obraz

I use it to fix typos..

But I guess It doesn't really allow this:
keep-case -> foo-bar
KEEP-CASE -> FOO-BAR

@clshortfuse
Copy link

clshortfuse commented Jul 5, 2019

@leawp Neat, but that wouldn't work if you want to the change to be relative to the case of the search.

Here o is always lowercase. Changing BENEVALENCE would yield BENEVoLENCE. I usually confront this issue when changing a camel-case word like wanting the following:

  • lastTabIndex => lastItemIndex
  • tabIndex => itemIndex

Here, replacing tab/Tab with Item versus item would be relative to the search result's capitalization.

@leawp
Copy link

leawp commented Jul 5, 2019

@clshortfuse yeah, I've realized it after reading comments, added a little explanation to mine.

@zacaj
Copy link

zacaj commented Jul 23, 2019

One of those really simple features that forces me to keep another text editor around

@rebornix
Copy link
Member

rebornix commented Jul 25, 2019

With #60311 merged, you will be able to preserve case when doing single replacement in Find Widget from tomorrow's Insiders. It's still in its early stage so currently we only support following patterns

  • all lower case
  • ALL UPPER CASE
  • Title Case

Considering we already have the infrastructure there, it would be straightforward to add more, all you need to do is

  1. Detect the pattern for the find result, add an entry in https://github.com/microsoft/vscode/blob/master/src/vs/editor/contrib/find/replacePattern.ts#L59
  2. Convert the replace term to the new pattern
  3. Write test cases in https://github.com/microsoft/vscode/blob/master/src/vs/editor/contrib/find/test/replacePattern.test.ts#L157

Added Help Wanted label and feel free to contribute more patterns for this feature. Simply follow above 3 steps.

@rebornix rebornix added the help wanted Issues identified as good community contribution opportunities label Jul 25, 2019
@TallGirlVanessa
Copy link

Amazing, I'm so excited!!!

@TallGirlVanessa
Copy link

Not working as expected; I'll have a PR done in a bit

@TallGirlVanessa
Copy link

TallGirlVanessa commented Jul 30, 2019

Insiders now works as expected :D Thanks for merging!

@uglyeoin
Copy link

Although we have preserve (sensitive) case in normal find and replace we cannot do it when using replace all across multiple files. That would be useful.

@rebornix
Copy link
Member

@uglyeoin it's being tracked in #78397

@peabnuts123
Copy link

I think this issue can be closed and new issues be created / referenced here for any related functionality that isn't in yet. Thanks to all who contributed 🙂

@rebornix
Copy link
Member

Thanks all for the patience and contribution to this feature. If you are interested in contributing more patterns to Preserve Case, you can follow #9798 (comment) and if you run into issues while playing with this feature, please file new issues in this repository.

@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-find Editor find operations feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests