Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4063212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:41:49+00:00 2026-05-20T15:41:49+00:00

I just asked a related question ( setq question ) but it’s distinctly different,

  • 0

I just asked a related question (setq question) but it’s distinctly different, so I decided to branch off with this question.

In my .emacs file, I define a key binding to the replace-string command:

(define-key global-map "\C-r" 'replace-string)

replace-string does basic search and replace. Assuming the first letter of the search string is lowercase, if the case-fold-search is nil then replace-string does case-sensitive search, otherwise it does case-insensitive search.

The problem is that case-fold-search controls the “case-sensitiveness” of both “search” (like the search-forward command) and “search and replace” (like the replace-string command).

The question is how do I make JUST the replace-string command (or anything C-r is bound to) case-sensitive, leaving the search-forward case-insensitive as it is by default.

Perhaps I would need to set case-fold-search to nil just for the replace-string command, but I’m not sure how to do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:41:50+00:00Added an answer on May 20, 2026 at 3:41 pm

    Put this in your .emacs:

    (defadvice replace-string (around turn-off-case-fold-search)
      (let ((case-fold-search nil))
        ad-do-it))
    
    (ad-activate 'replace-string)
    

    This does exactly what you said, set case-fold-search to nil just for replace-string.

    In fact this is almost exactly the example in the Emacs Lisp reference manual.

    Edit on 2021-11-02: as the link above indicates, defadvice is no longer the recommended way to implement this. The new recommended implementation would be

    (defun with-case-fold-search (orig-fun &rest args)
      (let ((case-fold-search t))
        (apply orig-fun args)))
    
    (advice-add 'replace-string :around #'with-case-fold-search)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just asked this question an hour ago but with regards to IE8
I see this question asked a lot in the related questions, but my need
I just asked an SQL related question, and the first answer was: This is
A related question to one I asked earlier ... Just checking on something: Should
Just asked a question about linking Boost libraries in the make file. Thanks to
I just asked this question . Which lead me to a new question :)
I know I asked a related question earlier. I just had another thought. using
So this is related to a question I asked earlier. I am trying to
This is very similar to a question I asked the other day but my
This is very similar to a question I asked the other day but my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.