VisualStudio 中似乎没有对保留大小写的查找/替换的内置支持(另请参阅相应的 功能请求)。
我的意思是:搜索“BadJob”并替换为“GoodJob”将执行以下替换
'badjob' -> 'goodjob'
'BadJob' -> 'GoodJob'
'badJob' -> 'goodJob'
'BADJOB' -> 'GOODJOB'
所以我正在寻找一个宏/插件来实现保留大小写的查找/替换。 如果不存在,那么我自己编写的一个好的起点是什么(最好基于内置的查找/替换功能)。
更新:
我知道我可以进行 4 个手动替换来完成这项工作,但我正在寻找一种在 VS 中自动完成这项工作的方法(例如 Emacs 就是这样做的)。
常见场景:名为“foo”的变量和一些函数 DoFoo()、GetFoo()...以及一些包含“foo”、“Foo”等的附加注释。
现在将“foo”重命名为“bar”,通过 ONE 查找/替换生成变量“bar”、函数 DoBar()、GetBar() 等。
There seems to be no built-in support for case preserving find/replace in VisualStudio (see also a respective feature request).
What I mean is: searching for 'BadJob' and replacing with 'GoodJob' would do the following replacements
'badjob' -> 'goodjob'
'BadJob' -> 'GoodJob'
'badJob' -> 'goodJob'
'BADJOB' -> 'GOODJOB'
So I am looking for a macro/add-in which implements case preserving find/replace. And if none exists, what is a good starting point to write my own (preferably based on the built-in find/replace capabilities).
Update:
I know I can make 4 manual replacements doing the job, but I am looking for a way to do it automatically in VS (like e.g. Emacs does it).
A common scenario: a variable named 'foo' and some functions DoFoo(), GetFoo(), ... and some additional comments containing 'foo' 'Foo' etc.
Now rename 'foo' to bar' yielding variable 'bar', functions DoBar(), GetBar() etc. by ONE find/replace.
发布评论
评论(6)
目前在 Visual Studio 中不可能。
您可以为此功能投票:
https://developercommunity。 Visualstudio.com/content/idea/580810/case-preserving-search-replace.html
我通常最终会打开 Sublime Text、Copy & 。 将代码粘贴到此处,执行保留大小写的替换,然后复制并复制代码。 粘贴回 Visual Studio。
It's not possible in Visual Studio at the moment.
You can vote for this feature:
https://developercommunity.visualstudio.com/content/idea/580810/case-preserving-search-replace.html
I usually end up opening Sublime Text, Copy & Paste the code there, perform the case-preserving replacements there and Copy & Paste back to Visual Studio.
现在可以进行保留大小写的查找和替换,尽管仅适用于所有大写、所有小写或标题大小写(因此它不适用于您的特定示例)。
详细信息可以在此处找到(复制如下) :
It is now possible to do case-preserving find and replace, albeit only for all upper case, all lower case, or title case (so it won't work on your specific examples).
Details can be found here (copied below):
在 Visual Studio 2022 中引入17.8 预览版 截至 2023 年 8 月 9 日。
[
Introduced in Visual Studio 2022 17.8 preview as of August 9th, 2023.
[
执行查找/替换时打开查找选项。 检查区分大小写的选项。 您将必须手动执行口味,除非您执行以下操作: http://www.aaronlerch.com/blog/2007/03/28/visual-studio-find-and-replace-regular-expressions/,或使用类似: http://www.download3k .com/MP3-Audio-Video/Utilities-Plug-Ins/Download-Find-Replace.html
open up the find options when you do the find/replace. check the case-sensitive option. you will have to do the flavours manually unless you do something like: http://www.aaronlerch.com/blog/2007/03/28/visual-studio-find-and-replace-regular-expressions/, or use something like: http://www.download3k.com/MP3-Audio-Video/Utilities-Plug-Ins/Download-Find-Replace.html
这就是我处理(out)它的方法:
在 Notepad++ 中打开文件,然后运行一个执行大小写替换的 python 脚本(就像我们以前能够使用 Visual Studio 宏所做的那样......啊,损失)
安装 Notepad++
安装 npp python 脚本
因此创建一个新脚本:
This is how I've coped with(out) it:
Open the file in Notepad++, and run a python script that does a case-keeping replace (like we used to be able to do with Visual Studio macros ... ah, the loss)
Install Notepad++
Install npp python script
Make a new script thus:
我知道这并不能完全按照您的要求回答您的问题,但是对于重命名变量和方法名称,您可以通过右键单击标识符并使用快捷菜单上的重命名选项来避免整个问题。 这将更新对该变量或方法名称的任何引用。
注意事项:
它仅适用于当前解决方案的范围。
它仅更新托管代码中的引用。
它不会更新诸如“badcode”之类的文字字符串
它不会更新您的评论。
这是 VS2005/2008 中我最喜欢的功能之一。
I know this doesn't answer your question exactly as you asked it, but for renaming variables and method names you can avoid the whole problem by right clicking on the identifier and using the rename option on the shortcut menu. That will update any references to that variable or method name.
Caveats:
It only works in the scope of the current solution.
It only updates references in managed code.
It won't update literal strings such as "badcode"
It won't update your comments.
This is one of my favorite features in VS2005/2008.