0

Is there a fast way of changing the case of the last searched pattern?

Inside Evil mode, I press # key to quickly search for keywords at point. And I want to change the case of all occurences of that keyword.

  • @phils I was looking for something even quicker. I've added a new answer. Please see that. And thanks for bumping the post, in case you did it :) – shivams Dec 10 '18 at 22:41
  • I think it was a convenient automated bump. I've added my suggestion as an answer for non-Evil users. – phils Dec 10 '18 at 23:09
2

Okay, I found the answer using Evil mode. After issuing the search using # key in Evil mode, just issue this substitution command:

:%s//\U&/g

Here, %s is for substitution, // means that it will use the last searched pattern, /\U&/ means it will upper-case (\U) the complete match (&), and g is for global, i.e. substitute all the matches.

1

For a vanilla Emacs approach, you might use:

  • C-sM-c to initiate a case-sensitive search (assuming that you have isearch-case-fold-search enabled by default).
  • C-w to search/match the word at point (or whatever you need to do to isearch the thing you're looking at/for).
  • M-% to enter the case-sensitive replacement for all matches.
0

You can try q ?: this will open a small buffer with your last searches using # (and ?) and then you can edit in-place the last command used and press Enter to execute that search

  • 1
    I think you misunderstood: I don't think the OP wanted to search again for the pattern with case chagned, but to change the case of the ocurrences of the pattern in the buffer. (Maybe... I'm not really sure what OP wants.) – Omar Jul 16 '18 at 2:38
  • Come to think of it, I also understood the same as you, @Omar, but I forgot to add "there is no such thing, but the closest is..." at the beginning. I'll try to add a command to do it automatically – Felipe Lema Jul 17 '18 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.