vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Feature Request: Preserve Case - Find / Replace

Open shaneparsons opened this issue 10 years ago • 39 comments

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.

shaneparsons avatar Jul 26 '16 17:07 shaneparsons

This would be life-changing

peabnuts123 avatar Nov 27 '16 20:11 peabnuts123

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.

axefrog avatar Mar 01 '17 00:03 axefrog

Let's track the setting persistence in #6158

rebornix avatar May 06 '17 18:05 rebornix

@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

ant31 avatar May 09 '17 12:05 ant31

@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

axefrog avatar May 09 '17 16:05 axefrog

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

rebornix avatar May 09 '17 18:05 rebornix

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

vilicvane avatar Jun 14 '17 08:06 vilicvane

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

alexgvozden avatar Aug 25 '17 22:08 alexgvozden

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

peabnuts123 avatar Aug 27 '17 21:08 peabnuts123

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.

mrahhal avatar Mar 29 '18 12:03 mrahhal

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.

sdlins avatar May 12 '18 06:05 sdlins

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

todd-skelton avatar Jul 27 '18 17:07 todd-skelton

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.

JasonWThompson avatar Sep 20 '18 20:09 JasonWThompson

Why the freak this is not implemented yet ?

gui679 avatar Oct 24 '18 02:10 gui679

This is an extremely useful feature, I love the implementation in WebStorm.

gmosx avatar Nov 11 '18 08:11 gmosx

Why on earth is this not planned - it's a simple, self contained quality of life improvement that's been in every editor I've used in years. Easy to implement and test.

You need to flesh out your core editor before all these bells and whistles I keep seeing in release notes.

barnc avatar Nov 26 '18 04:11 barnc

@barnc That comment isn't helpful at all. VSCode is free and open source, and the team is doing an amazing job with so many improvements, and disparaging their prioritization doesn't show much gratitude toward that.

If you've looked into the code and see that it's simple, I'm sure the team would gladly look at a pull request from you.

quicksnap avatar Nov 26 '18 17:11 quicksnap

Just adding my support to this. It is just crazy that we have to open/use another tool to get things going properly with vscode? Obviously I appreciate the efforts of the developers, but it is these types of features that always get overlooked in open source projects. Which is a shame!

skn3 avatar Nov 27 '18 09:11 skn3

@quicksnap Whilst I appreciate your positive attitude, this is a 2 year old issue for a repeatedly requested feature that is simple to implement.

I don’t need to look into a code base to determine if adding a case sensitive replace to an existing find and replace function is easy or not. Furthermore, ‘why don’t you do it yourself’ does not qualify as an excuse for it not being even considered for development by the team.

barnc avatar Nov 27 '18 11:11 barnc

@barnc : Open Source is Not About You

gmosx avatar Nov 27 '18 11:11 gmosx