(customize-set-variable case-fold-search nil)
Or bind that variable (option) in your own command that is otherwise just a wrapper around query-replace
. This has the advantage that it doesn't change the variable value for general use, outside of query-replacing.
See also variable case-replace
, which controls case for the replacement text.
See also C-h f query-replace
, where it says, for example:
Matching is independent of case if
case-fold-search
is non-nil and FROM-STRING has no uppercase letters. Replacement transfers the case pattern of the old text to the new text, ifcase-replace
andcase-fold-search
are non-nil and FROM-STRING has no uppercase
See also the comments below, and Emacs bug #20687, wherewhich show how you can patch perform-replace
to let you toggle case folding during query-replace
.
Note too that the existing code for perform-replace
binds case-fold-search
in this way (note the variables on which it depends):
(case-fold-search (if (and case-fold-search search-upper-case)
(isearch-no-upper-case-p from-string regexp-flag)
case-fold-search))