Questions tagged [query-replace]

query-replace is a built-in Emacs command for interactively replacing one string with another in a buffer. query-replace-regexp does the same thing, but with support for matching regular expressions. Use this tag for both commands.

Filter by
Sorted by
Tagged with
0 votes
0 answers
27 views

set-keymap-parent function and let binding of involved keymaps

I have this content in the buffer: \begin{environment} foo Some other text here \end{environment} \begin{environment} foo Some other text here \end{environment} \begin{environment} foo Some other ...
Gabriele's user avatar
  • 1,554
0 votes
1 answer
77 views

query-replace: ignore events not binded in query-replace-map

I have this function: (defun my-replacements () (interactive) (query-replace "foo" "bar" nil (point-min) (point-max)) (query-replace "baz" "quz" nil (...
Gabriele's user avatar
  • 1,554
1 vote
2 answers
36 views

Temporary Inhibition of Mouse Events in Windows During Menu Opening

I'm facing an issue (Unwanted Focus Shift when Clicking Menu Functions in Emacs Mode Line) regarding mouse event handling in buffer windows during menus opening. To address this, I'm attempting to ...
Gabriele's user avatar
  • 1,554
0 votes
1 answer
20 views

How can I get `query-replace` to respect `superword-mode`?

I'm trying to use query-replace with a prefix argument in superword mode. So for example, C-u M-% token RET token_drawer RET should not replace token where it appears in token_width. But query-...
Norman Ramsey's user avatar
0 votes
1 answer
24 views

query-replace, add a "skip to next" in lambda function

I have this function: (defun fix-mult-punct-before-footnote () "Scope: FOOTNOTE Description: Fixes repeated/multiple punctuation before the \\footnote macro." (interactive) ;; "..\...
Gabriele's user avatar
  • 1,554
0 votes
1 answer
61 views

query-replace bug?

When I run query-replace* commands if I type ? I get this explanation of the function's options: Type Space or ‘y’ to replace one match, Delete or ‘n’ to skip to next, RET or ‘q’ to exit, Period to ...
Gabriele's user avatar
  • 1,554
0 votes
0 answers
20 views

How to enter query-replace-regexp with key binding C-M-%, if emacs session is not stand-alone but in mate-terminal running Bash?

Title says it all. The problem: When you start emacs within a terminal running a shell, Meta and Ctrl key act in strange ways: In some regards they work, in others, however, not as it used to be ...
starquake's user avatar
2 votes
2 answers
109 views

How to count number of replacements made by `query-replace`?

I am writing a piece of lisp code employing the function query-replace. After this function runs, I'd like to know how many replacements were effectively done. At first this seems easy because the ...
Ruy's user avatar
  • 839
0 votes
1 answer
108 views

How can I recursively find and replace text in case sensetive?

I am using combination of following solutions in order to find-and-replace matched text in all Python files: Using Emacs to recursively find and replace in text files not already open How can I ...
alper's user avatar
  • 1,370
0 votes
2 answers
65 views

Build a "with-query-replace-description" macro

In the company where I work we use Emacs as the default editor for the LaTeX copy-editing tasks and we share some Emacs scripts to automate/guide some operations. Actually I need to perform some query-...
Gabriele's user avatar
  • 1,554
1 vote
1 answer
192 views

How can I replace all in symbol manner?

I am using following solution (How do I add a keybinding to use during an interactive isearch, `C-s ...`) to move over symbols in the buffer, which iterates over the matching symbols: (define-key ...
alper's user avatar
  • 1,370
1 vote
2 answers
151 views

Read-only mode gets in the way when query-replacing text in multiple files

I am searching and replacing text within all marked files in a Dired buffer, as per this post: https://emacs.stackexchange.com/a/9497/37866 I am successful until the point where it finds the first ...
marsh's user avatar
  • 11
0 votes
1 answer
61 views

Find and recursively delete (with query) consecutive duplicate words not necessarily in the same line and/or same case

I would like to scan through a (latex) document and recursively delete -- WITH QUERY -- all consecutive, repeated words that need not be on the same line and/or the same case. Here is a simple ...
underflow's user avatar
  • 111
5 votes
5 answers
655 views

More simple approach to replace some text in many files?

Linux Mint 20.2 Emacs 27.1 Task: I has folder with MyProject with 5 subfolders. Total count of files in all this folders are about 500 files. I need all files that content import org.apache.log4j....
a_subscriber's user avatar
  • 4,074
0 votes
0 answers
93 views

Why doesn't project-query-replace-regexp work well

It seems promising to have a built-in function that performs this action: find and replace all matching text recursively, within your project. The problem is that it doesn't seem consistent. I am ...
mcp's user avatar
  • 546
1 vote
1 answer
67 views

(Spacemacs) pressing SPC to replace a match during query-replace does not work

(Spacemacs) M-% starts query-replace, and when a match is found, ? shows help, which indicates: Type Space or ‘y’ to replace one match, Delete or ‘n’ to skip to next, However, pressing Space simply ...
taranaki's user avatar
  • 113
2 votes
1 answer
62 views

How to perform query-replace excluding LaTeX math?

I have this test code: foo \begin{equation} foo \end{equation} foo $foo$ foo I want to replace "foo" with "bar" everywhere but LaTeX math, so I have written these functions: ...
Onner Irotsab's user avatar
0 votes
1 answer
49 views

Automatically save files after multi-file search/replace

How can I get GNU Emacs to automatically save all the files I've changed after doing a multi-file search/replace with query-replace-regexp? Right now I have to switch back to the buffer for every ...
cjg's user avatar
  • 1
1 vote
0 answers
51 views

Multiple replacements when query-replacing

I have a piece of code like this: def convert(tir_expr: tir.expr.PrimExpr) -> expr.Expr: if isinstance(tir_expr, tir.expr.Add): return convert_Add(tir_expr) elif isinstance(tir_expr,...
Yuxiang Wei's user avatar
1 vote
2 answers
403 views

How to make query-replace automatically fill what I want to replace with marked text?

I want to select some text somewhere in a buffer, call query-replace and then type (or paste from kill-ring) only the second argument, TO-STRING, (and make the selected text count as FROM-STRING). I ...
achempion's user avatar
  • 115
0 votes
0 answers
52 views

query-replace within LaTeX/Math

The answer below was taken from https://stackoverflow.com/a/44913296. This is the most upvoted answer there. Unfortunately, after running the code (for example by replacing q with \theta) one ...
Name's user avatar
  • 7,859
1 vote
1 answer
239 views

remove "-" (soft hyphen) between words

When I try to paste a text from a web page inside Emacs I get this "-" between words. Here is one example: Is there a way to get rid of this (don't know the term..) ? Aus Sicht vie­ler ...
Enrico Pirani's user avatar
2 votes
2 answers
777 views

How do I search/replace with case sensitive search?

In emacs I'm using M-% to replace occurrences of b_abcd (of which there are only a few) with B_abcd (of which there are very many). Currently Emacs asks if it's OK to replace at each B_abcd, which ...
HarryH's user avatar
  • 131
0 votes
2 answers
128 views

How can I paste a defvar into the minibuffer?

I've written a regular expression to transform Markdown links into Org Mode links and I've stored it into a variable. (defvar markdown-link-to-org-regexp "s/\[\(.+\)\](\(.+\))/[[\2][\1]]") ...
tonicebrian's user avatar
0 votes
1 answer
113 views

How to query-replace with exact match with the exact given word in case-sensetive manner?

I have HELLOWORLD string inside my file. My setup: (defun my-find-orgfiles () (interactive) (setq toggle-case-fold-search 0) ; Turn Off Smart Case Sensitivity (find-name-dired "~/folder&...
alper's user avatar
  • 1,370
4 votes
1 answer
57 views

How to access Query-replace history in replace format (for eg: "ABC → XYZ")

I have enabled query replace save history as below. When I am in query-replace mode, I see previous search-replace patterns of the current session in the form "ABC -> XYZ". But the search-replace ...
emacsbeginner's user avatar
1 vote
3 answers
2k views

Replace string in rectangular region?

When you select a region normally, you can do a replace-string on only that region. It would be very useful to select a rectangular region (via C-x SPC), and be able to replace-string on only that ...
gilbereth's user avatar
2 votes
1 answer
69 views

Query replace regexp with a distant match?

I have a single transcript file for a set of course lectures I am watching. After doing some formatting on the file. I have it broken up into sets of lessons where the main heading is the lesson title ...
dylanjm's user avatar
  • 323
0 votes
2 answers
128 views

query-replace{-regexp} fails in linux in a non-X terminal when I am in anything other than text mode

I am running emacs 26.1 under linux. It has been working fine for over a year. Recently, I upgraded a lot of packages on my machine, but I did not upgrade nor alter emacs in any way. Now, query-...
HippoMan's user avatar
  • 596
3 votes
1 answer
281 views

Can Dired query replace use regular expression to rename a group of files?

So I have long list of files that I'm trying to use regex to rename but, it looks like it does not take standard regular expressions. I’m sure I’m just doing this incorrectly. After entering dired ...
Troy Wilson's user avatar
3 votes
2 answers
3k views

Search/replace and replace within a block of selected text of buffer in spacemacs

As stated in the title, I want to search and edit (including replace) certain strings in a selected part of a buffer, not the entire buffer!!!, how can I do it? Are there any built-in keystrokes?
Jason Goal's user avatar
3 votes
3 answers
404 views

How to count regexp in a string and use that number in replacement?

In my LaTeX code I want to replace these strings: \left.\left.\left. \left.\left. \left. with: \left.\left.\left. \mycommand{3} \left.\left. \mycommand{2} \left. \mycommand{1} where the argument ...
Gabriele's user avatar
  • 1,554
1 vote
2 answers
178 views

How to perform query-replace inside mathematical expressions in latex

Inspired by this answer, I have written the following function to perform a query-replace inside a math environment, but it does not work. Edit. If you execute the function, the query-search tries to ...
Name's user avatar
  • 7,859
8 votes
1 answer
1k views

How to apply arithmetic operators to query-replace-regex

I am attempting to replace all "begin" and "dur" attribute values in my SVG code with one-tenth of (or ten times) their current values, in order to speed up/slow down animation for testing/debugging ...
Peter Chaplin's user avatar
3 votes
1 answer
137 views

How can I identify all changes to match-data?

I have a sporadic error when running query-replace: Args out of range: #<buffer lib.rs>, 0, 1 There are similar questions: Match data clobbered by buffer modification hooks (RegEx-)Replace: ...
Shepmaster's user avatar
1 vote
1 answer
123 views

Make query-replace skip certain matches

Lets say I have these strings: "foo", "fooo" and "fo". And this line of code: (query-replace-regexp "\\<fo+\\>" "foo" nil (point-min) (point-max)) I'd like to skip the query-replacement for ...
Gabriele's user avatar
  • 1,554
2 votes
1 answer
107 views

How to replace a digit by a letter?

I want to replace some digits by letters such that 1 ---> a 2 ---> b ... In emacs I have tried the following replacement: M-x query-replace-regexp RET \([0-9]+\) RET \,(string (+ ?a \#1)) RET ...
Onner Irotsab's user avatar
2 votes
1 answer
155 views

Add multiple predicates to isearch-filter-predicate

I wrote a set of predicates to filter matches in my ìsearch-* and query-replace* routines. I also wrote a macro to bind the isearch-filter-predicate variable to multiple predicates: (defmacro with-...
Gabriele's user avatar
  • 1,554
0 votes
1 answer
69 views

texmathp in isearch-filter-predicate breaks query-replace's match highlighting

I tried to use texmathp with iserch-filter-predicate to let query-replace function skipping maths in my LaTeX code. I wrote this code: (defun skip-math (beg end) "Return nil if some text BEG to ...
Gabriele's user avatar
  • 1,554
1 vote
1 answer
54 views

How query-replace-regexp for all text exact before specific text?

emacs 26.1, windows 10 I have some text. I need to replace all text before WARN I use: query-replace-regexp: .*WARN query replace regexp: RET But I need to delete all text BEFORE WARN. How I can ...
a_subscriber's user avatar
  • 4,074
5 votes
1 answer
187 views

replacing regular expressions with querying on and functions on match

EDIT: gave more context for my first approach. My goal is to search my notes for strings of the form "4/1/2014" to org-mode timestamps "<2014-04-01 Wed>" (that particular day-of-week may be ...
Yan X Zhang's user avatar
3 votes
2 answers
144 views

Make region(s) invisible (not evaluated) to query-replacy and similar commands

Is there a way to make some regions of the buffer invisible (I mean not evaluated by) to query-replace and similar commands? Let me better explain with an example. Let's take a piece of LaTeX code .....
Gabriele's user avatar
  • 1,554
6 votes
3 answers
1k views

Regexp replace to match a string, but not match a superstring

Let's say I want to replace the string "Vector" by "VectorBase", but there are existing instances of "VectorBase". So I would like to omit "VectorBase". What is an elegant way to achieve this? An ...
hrkrshnn's user avatar
  • 439
5 votes
1 answer
229 views

(RegEx-)Replace: Sporadic Match data clobbered by buffer modification hooks

I know this was asked in other contexts already, but I couldn't find anything related to C++ development with my hooks that could help me. I am working a lot with replace and query-replace and query-...
AltruisticDelay's user avatar
1 vote
1 answer
236 views

Advanced search and replace

I have a file, with a lot of instances of ... fclose(f1); fclose(f2); fclose(f3); ... I'd like to replace these with ... if(fclose(f1)!=0) return 1; if(fclose(f2)!=0) return 1; if(fclose(f3)!=0) ...
Mikkel bruun's user avatar
2 votes
0 answers
371 views

fix buffer invalid UTF-8 encoding characters by query/replace

When I copy text from web pages, there are some special characters like ', - etc (not UTF-8 encoding). As you can see in the following screenshot: I checked out some similar questions in this site: [...
stardiviner's user avatar
  • 1,928
1 vote
1 answer
97 views

Query replace a copied string by another copied one

Use case: I want to: copy a (long, not handy to manually type) newstring, replace all occurrences of another (long, not handy to manually type) string by newstring. Current process (not handy): ...
Denis Bitouzé's user avatar
6 votes
1 answer
202 views

Query replace with different replacements

Suppose we start with the following Adam ate an apple. Adam ate an apple. Adam ate an apple. Adam ate an apple. Adam ate an apple. I want to replace Adam with Bob, Chris, and David. So I want ...
Quarky Quanta's user avatar
5 votes
2 answers
309 views

Text substitution only in specific column of org table

I came across this problem today: I had a table with many entries and wanted to perform a text substitution (normal text substitution was sufficient as I hardly ever need regex text substitutions) in ...
UTF-8's user avatar
  • 915
2 votes
1 answer
99 views

What mode does the command `query-replace' activate?

I'm editing my keybinds mode-by-mode, and I've now come to the query-replace-map. I want to define my keybinds in a mode-hook to keep my files logically consistent, but I cannot determine which mode ...
John DeBord's user avatar