Questions tagged [replace]

Replacing is the action of searching a string for a sub-string and replacing it with a different string.

Filter by
Sorted by
Tagged with
1 vote
1 answer
63 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 ...
user avatar
  • 1,084
1 vote
2 answers
36 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 ...
user avatar
  • 11
0 votes
0 answers
28 views

How to convert greek text to unicode using matching input method?

Good evening, I have a large TeX-file with Greek inclusions in traditional babel way: \textgreek{sunj'hkh|}. I would like to convert it to unicode for further work. Emacs has greek-babel input method,...
user avatar
1 vote
1 answer
71 views

word replacements with prettify-symbols-mode

I am writing a feature that replaces words as is done in texinfo-mode, where greek syntax \alpha is replaced by the actual greek symbol α. The implementation uses prettify-symbols-mode. Have seen ...
user avatar
  • 159
1 vote
1 answer
30 views

Masking text / replacing a region with one character

I often find I want to "mask" text in a text file, such as overwriting a secret value in an example file. For example, I want to change SECRET_PASSWORD=123abc456 to SECRET_PASSWORD=XXXXXXXXX....
user avatar
0 votes
4 answers
63 views

Text representing a Python vector of numbers: how to append a comma to each numeral but the last?

The printed value of Python vector of numbers is displayed in a buffer: [0.00000024 0.00000024 0.00000024 0.00000024 0.00000024 0.00000023 0.00000024 0.00000024 0.00000024 0.00000024 0.00000023 0....
user avatar
  • 17.7k
2 votes
1 answer
82 views

How can I search and replace in one go and for the full or selected text without visiting each search hit? [duplicate]

Any advanced editor has it: Search and Replace to replace a chosen word with another, with search criteria "Match case" and "Match whole word only" in addition like in notepad++. I ...
user avatar
3 votes
4 answers
212 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 I all files that content import org.apache.log4j....
user avatar
  • 3,435
0 votes
0 answers
43 views

How to replace unicode in emacs?

I'm using spacemacs, and am wondering how you do certain commands like replace and align with respect to unicode (particularly relevant for Agda development). For instance, → has the \to shortcut in ...
user avatar
0 votes
0 answers
32 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 ...
user avatar
1 vote
1 answer
63 views

Search and replace in multiples files at once by having them all open as a buffer?

I've done this before in emacs but I can't remember how or which plugins were involved. Basically you marked a bunch of files according to a file extension, and then you got asked for a search string, ...
user avatar
0 votes
3 answers
146 views

How can I recursively find and replace in the current git repository

I am working inside a git-repo. Here I want to apply my search operation based on the root directory of the git repo that current buffer is open. Here I do: find-dired "~/my_project" ... in ...
user avatar
  • 1,084
0 votes
1 answer
56 views

How can I query replace region from top case-sensitively?

I am using following answer to search and replace a word in the entire buffer: (defun query-replace-region-or-from-top () (interactive) (progn (let ((orig-point (point))) (if (use-...
user avatar
  • 1,084
0 votes
0 answers
26 views

xml: copy line if tag found below that line and change content between tags from associated list or hash table

I am rather new to emacs and need some keywords which I can than use to search the manual/forum/google. Whenever a special tag name can be found in an xml file I would like to copy that line (tags and ...
user avatar
1 vote
1 answer
76 views

How to I replace several texts like (1), (2), (3) etc. with fixed text (1), fixed text (2), fixed text (3) in one go?

My text contains several occurrences like "(1)", "(2)", "(3)". I want to replace these with the general format like "fixed text (1)", "fixed text (2)",...
user avatar
  • 123
0 votes
1 answer
34 views

Regexp replacement features

In the replacement part of :s in evil I can add commands like \l to lowercase the next char and \L to lowercase everything that follows, but I am unable to find documentation for that anywhere. I ...
user avatar
  • 224
1 vote
1 answer
66 views

How to dynamically replace certain text, by evaluating a function on change in current buffer

I am trying to figure out how to use window-change-functions refer here for official documentation to be able to run a function to replace certain text within the current buffer at every change of the ...
user avatar
0 votes
1 answer
78 views

frame-background-mode leads `Args out of range: #<buffer doo.py>, 0, 1` error

I am using following answer to search and replace a word in the entire buffer: (defun query-replace-region-or-from-top () "If marked, query-replace for the region, else for the whole buffer (...
user avatar
  • 1,084
0 votes
1 answer
30 views

Replacing with context information

When writing latex sometimes I reuse old documents that use the siunitx package and use the \SI command. Then I often want to include the calculations via pythontex and replace (in a region) \SI with ...
user avatar
  • 967
1 vote
1 answer
48 views

How can I fix my re-replace-region function in which match data gets clobbered?

I have an ancient function I've been using for decades which performs a regexp replacement in a region: (defun re-replace-region (begin end old new) "Replace occurrences of REGEXP with TO-STRING ...
user avatar
0 votes
2 answers
144 views

Pass selected text as argument to a script and replace selected text with output from the script

I'd like to pass some selected text in a buffer to a python script. The python script will process the string and print the result to stdout. This output should replace the original string that was ...
user avatar
  • 169
3 votes
1 answer
63 views

Equivalent of query-replace-regexp for multiple regexps

How can I do the equivalent of query-replace-regexp for multiple regexps? For instance, if regexp1 is matched, it should be replaced by text1, and if regexp2 is matched, it should be replaced by text2 ...
user avatar
  • 173
1 vote
1 answer
74 views

How to select and replace the content of all specific org-headings?

I am trying to select each content-heading extracted with org-noter and then remove all erroneous newlines. This is my function. (defun sanitize-noter-import () "Sanitizes org-noter imports. ...
user avatar
0 votes
1 answer
38 views

How to modify text that's yanked?

I copy text from websites and paste/yank into emacs buffers. But this text sometimes has silent hyphens in them. The behaviour when copying and pasting text with soft hyphens in it varies across ...
user avatar
2 votes
1 answer
70 views

How to replace the first element of the `kill-ring` by a modification of it?

I am trying to modify the string that is to yanked My goal is to modify certains paths before yanking, in order to transform them in relative to path actual buffer file. Following this post, I tried ...
user avatar
1 vote
1 answer
157 views

function to search and replace multiple words - necessary to goto-line 1 every time?

This is a very rudimentary question, but I have a document in which I need to replace many different words fairly frequently, so I created a function that goes like this: (defun chikan () (...
user avatar
0 votes
1 answer
82 views

Replace expressions including variable text

I wish to create a function to put in my .emacs (but I am no Elisp expert) in order to perform a certain number of replacements within an Emacs buffer. In particular, I want to: replace any ...
user avatar
1 vote
1 answer
154 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 ...
user avatar
3 votes
3 answers
762 views

Find/replace all files in a directory? (recursively)

One task I still end up using an IDE for is project wide find-replace. The steps are as follows. Select a directory to replace in(this could default to the projects root). Select the file extensions ...
user avatar
  • 7,199
0 votes
1 answer
269 views

replace-regexp-in-string: How to prepend a string to the entire string matched?

I am adding divider lines to certain sections of the reports generated by the binary ledger [ https://www.ledger-cli.org/ ] through the function ledger-do-report in the ledger-mode Lisp library [ ...
user avatar
  • 17.7k
1 vote
0 answers
55 views

How to replace a block of text with a "query-like" approach all at once?

I want to search and replace a block of text with a "query-like" approach all at once. For example, if I have \emph{``Foo $\bar$ baz''} to be replaced by \emph{Foo $\bar$ baz} using a &...
user avatar
1 vote
1 answer
75 views

How can I get the search string from incremental regexp search to use with replace regexp

If I want to do a replace-regexp I usually start with a isearch-forward-regexp so I can get immediate visual feedback on the search string. From there I'd like to grab the search string for using in ...
user avatar
0 votes
2 answers
318 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 ...
user avatar
  • 111
0 votes
1 answer
179 views

Regex to replace subset of repeated pattern

ABC、DEF, GHI, JKL、MNO PQR、STU, VWX、YZ How do I replace all , s with 、 in the repeated pattern above? The repeated pattern can be mapped with the regex below: "^\\([A-Z]+、\\)\\(\\([A-Z]+\\), \\)+&...
user avatar
  • 655
1 vote
1 answer
42 views

Decode double-back-slashes-prefixed octal codes in 'utf-8

I have a string "\\303\\273" that I want to decode into û. It's known that (decode-coding-string "\303\273" 'utf-8) evals to û. However, I'm not able to translate "\\303\\273&...
user avatar
2 votes
2 answers
244 views

Remove multiple blank lines in a buffer, leave one

I'd like to take a buffer which looks like this: one two three four five And turn it into this one two three four five I've tried using delete-blank-line, however, it will only effect the area ...
user avatar
  • 266
1 vote
1 answer
38 views

icicles search and replace; need help to do a successfull replace

I try to use Icicles to search and replace. I understand to search with it (some details, that I need), but I'm unable to do a replace. The link below shows a recipe, that I try to follow, but it ...
user avatar
0 votes
1 answer
45 views

How to replace a letter with its numerical alphabetic position?

I have this code: \author[p]{...} \author[bc]{...} \author[p]{...} \author[l,o]{...} \author[t,q]{...} \author[at]{...} \author[z]{...} \author[ak]{...} \author[az]{...} \author[ah,bq]{...} ... I ...
user avatar
0 votes
1 answer
85 views

Programmatically find-and-replace custom sequence

I need to write a command which will apply to my buffer custom, predefined copy-and-replace sequence. What I have is: (defun custom-processor () "Formats logs to human-readable format" ((replace-...
user avatar
0 votes
1 answer
72 views

How to set a variable that matches different type of strings?

I have these strings: First Type: arXiv:1234.56789 arXiv:1234.56789v1 Second type: hep-th/123456789 hep-th.AB/12345689 hep-th/123456789v1 hep-th.AB/12345689 Belong to the second type even strings ...
user avatar
0 votes
0 answers
66 views

error in process sentinel: Invalid file-name during replacing words

I am getting following error error in process sentinel: Invalid file-name due to generated _flymake.py files, when I am following approach for the recursively find and replace in text files not ...
user avatar
  • 1,084
0 votes
2 answers
775 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 ...
user avatar
2 votes
1 answer
67 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 ...
user avatar
  • 303
2 votes
1 answer
156 views

How to add a suffix to the end of a string in a line?

Here's an example of content in a file This_is_line_1 : 1 This_is_another_line :2 This_is_3rd_line :3 Here_is_line_4 :4 So, how can using emacs to add char @ immediately to the end 1 string ...
user avatar
  • 23
0 votes
2 answers
83 views

How to replace first 100 digits with letters?

I want to replace the first 104 digits as it follows: 1 --> a ... 26 --> z 27 --> aa ... 52 --> az 53 --> ba ... 104 --> bz I have tried as it follows: (...
user avatar
0 votes
0 answers
67 views

How to replace a LaTex macro with its argument?

I want to replace a macro with its argument, that's to say, if I have \newcommand{\foo}{FOO} I want to replace every occurence of \foo with its argument FOO in a specified region. I am trying to ...
user avatar
0 votes
1 answer
92 views

need help with very complex find and replace

I have a very complex (at least to my mind) text replacement task. ideally this would be a function or macro I could run over every org header in a buffer. I want to 1. move over any TODO state to a ...
user avatar
  • 1,615
2 votes
1 answer
2k 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?
user avatar
0 votes
1 answer
852 views

Replace full-width numerals with half-width numerals

I'd like to convert numerals from half-width to full-width characters with a simple regex search and replace as follows: replace-regexp-in-string regexp rep string &optional fixedcase literal ...
user avatar
  • 655
0 votes
2 answers
112 views

Replace a block of code with another

How can I replace a block of code with another, akin to query-replace/query-replace-regexp? For example: Replacing the following block: for(A) { if(B) { s1; } else { C; } } with ...
user avatar
  • 31