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

后端 未结 2 749
长情又很酷
长情又很酷 2021-01-04 09:19

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 sourc

相关标签:
2条回答
  • 2021-01-04 09:32

    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 ...)))
    
    0 讨论(0)
  • 2021-01-04 09:39

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

    0 讨论(0)
提交回复
热议问题