如何告诉 Emacs 在搜索和替换字符串中保留大小写?
我正在尝试在 Emacs 中执行正则表达式搜索和替换(使用 Mx query-replace-regexp),但通常有用的智能案例却妨碍了我。我的来源是:
One
Two
Three
我想将每一行替换为
之类的内容。不幸的是,每行开头的大写字母都被误解了,我得到的
是我不想要的大写字母。
我可以找到有关如何使搜索区分大小写以及如何在替换字符串中保持 \1
小写的示例,但没有找到有关如何保持整个替换字符串大小写不变的示例。
I'm trying to perform a regex search and replace in Emacs (using M-x query-replace-regexp
), but the usually helpful smart case is getting in the way. My source is:
One
Two
Three
And I want to replace each line with something like <item name="One"/>
instead. Unfortunately the capital at the start of each line is being misinterpreted, and I'm getting <Item>
with an uppercase that I don't want.
I can find examples about how to make the search case sensitive, and how to keep the \1
lowercase in the replacement string, but nothing about how to keep the entire replacement string case-unmodified.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将其添加到您的 .emacs:
Ch v case-replace RET:
以及手册的链接
替换命令和宽松匹配 详细说明与案例和适当变量的所有交互。
或者您可以定义一个新命令,例如:
并且,如果您在函数中对其进行编码,并且只想临时设置变量,则可以执行以下操作:
Try adding this to your .emacs:
C-h v case-replace RET:
And a link to the manual for
Replace Commands and Lax Matches details all the interactions with case and the appropriate variables.
Or you could define a new command like:
And, if you were coding this up in a function, and only wanted to set the variable temporarily, you'd do something like:
在当前的 emacs 中,您可以在选项菜单中找到该选项。如果您希望通过同一菜单保存选项。
In a current emacs, you can find the option in the Options menu. Save Options, if you wish through the same menu.