How do you tell Emacs to leave the case alone in a search and replace string?

倖福魔咒の 提交于 2019-11-30 18:01:38

Try adding this to your .emacs:

(setq case-replace nil)

C-h v case-replace RET:

Documentation: Non-nil means `query-replace' should preserve case in replacements.

And a link to the manual for Replace Commands and Case details all the interactions with case and the appropriate variables.

Or you could define a new command like:

(defun query-replace-no-case ()
   (interactive)
   (let ((case-replace nil))
       (call-interactively 'query-replace))))

And, if you were coding this up in a function, and only wanted to set the variable temporarily, you'd do something like:

(let ((case-replace nil))
   (while (search-forward ...)
       (replace-match ...)))

In a current emacs, you can find the option in the Options menu. Save Options, if you wish through the same menu.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!