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
10 views

Switch a TeX \macro and a script on a region of text

How can I search and replace in a region of a (TeX)buffer all occurences of \macro{foo}_{bar} to \macro{foo_{bar}}, foo and bar not being "constants" ?
  • 187
2 votes
1 answer
22 views

How can I construct a bash-safe filename from a string?

I want to generate very simple filenames from complex strings during a org-capture. For instance the string "Une idée nouvelle pour calculer $\\int_0^{\\infty} e^{-t^2} \\dd t$" Should be ...
1 vote
1 answer
58 views

Elisp function to transform word at point

How to write an elisp function that transforms the word at point? Specifically, in the C++ code I am refactoring I have to replace tons of raw pointers into smart pointers. Say, for class Foo, I would ...
  • 145
1 vote
1 answer
37 views

How to copy and modify a single line from a buffer?

I want to write a function that copies the current line from a buffer, but transforms it before in certain way. Specifically, I need to generate file names depending from lines of code. For example, ...
0 votes
1 answer
31 views

How to replace the region text with the text of a string, without deleting and reinserting parts that are the same

In a few functions I've written logic that does the following: (defun replace-in-region (str beg end) "Replace the region between BEG & END with STR." (save-excursion (goto-char ...
  • 7,623
1 vote
1 answer
38 views

(error "End after end of buffer") while replacing strings in a region inside buffer

I need to prepare org files like this * firsth things ... * compress files #+begin_src shell tar cfzv {migration-date}/{client-id}from{start-date}to{finish-date}.tar.gz 1/{soc-id}/{client-id}/ #+...
  • 729
-4 votes
1 answer
37 views

Matching ple in middle of word and replacing with letter p

The following function replaces character sequences for the cases of prefixes and suffixes. I would also like to handle the case of matches that occur medially within a word (e.g. insert p' for ...
  • 385
0 votes
2 answers
41 views

Replacing words using multiple rules

This function is supposed to replace matches with a shortened version using multiple rules rather than just a single one. For the word counter, coun gets replaced by k, resulting in the shortened ...
  • 385
0 votes
0 answers
17 views

Scheme to write shortened words according to certain rules

I want to modify words according no certain rules. Here is a small example with three rules a) Insert k for words with initial cog, col, com, con, cor, coun, cum. (insert (replace-regexp-in-string &...
  • 385
0 votes
1 answer
34 views

Omit the beginning of words

I want to omit the beginning of words starting with some (i.e. something is changed to thing) using the expression (insert (replace-regexp-in-string "\\<\\some\\" "" word)) But ...
  • 385
-1 votes
1 answer
26 views

Regex replacement on final endings of words [closed]

I would like to replace the final ly, ily, ley of words with the letter l. So that I get the following changes to words nearly changed to nearl family changed to faml valley changed to vall
  • 385
0 votes
1 answer
21 views

Inserting letter for words with initial letter sequence

I would like to introduce the letter k for words with initial cog, col, com, con, cor, coun, and cum using an elisp command defined in my init file. That is "cognize" changed to "knize&...
  • 385
0 votes
1 answer
78 views

Don't replace " in LaTeX Mode

In LaTeX mode, when I type \" (to produce a Umlaut like ö, ä or ü in the resulting PDF) emacs replaces it by ''\` (two single quotation marks, a backslash, and a backtick) which does not work for ...
  • 123
0 votes
1 answer
31 views

Is it possible to mimic sed's "change line" feature?

I'd like to write an elisp function that allows me to replace any line in my buffer matching a regex pattern <PATTERN> with text <TEXT>. In other words, if line N matches <PATTERN>, ...
0 votes
3 answers
83 views

Can environments be easily wrapped with AUCTeX?

I want to quickly wrap certain environments my cursor is within with text. In my specific situation, I want to wrap the frame environment with the text \makeatletter \gdef\beamer@currentmode{beamer} \...
1 vote
1 answer
136 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 ...
  • 1,152
1 vote
2 answers
41 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 ...
  • 11
0 votes
0 answers
30 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,...
1 vote
1 answer
95 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 ...
  • 169
1 vote
1 answer
46 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....
0 votes
4 answers
78 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....
  • 18.1k
2 votes
1 answer
83 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 ...
3 votes
4 answers
308 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....
  • 3,577
0 votes
0 answers
91 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 ...
0 votes
0 answers
39 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 ...
1 vote
1 answer
95 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, ...
0 votes
3 answers
223 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 ...
  • 1,152
0 votes
1 answer
61 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-...
  • 1,152
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 ...
1 vote
1 answer
85 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)",...
  • 123
0 votes
1 answer
36 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 ...
  • 274
1 vote
1 answer
87 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 ...
0 votes
1 answer
81 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 (...
  • 1,152
0 votes
1 answer
31 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 ...
  • 997
2 votes
2 answers
72 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 ...
0 votes
2 answers
213 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 ...
  • 169
3 votes
1 answer
71 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 ...
  • 173
1 vote
1 answer
100 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. ...
0 votes
1 answer
45 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
74 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 ...
1 vote
1 answer
192 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 () (...
0 votes
1 answer
110 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 ...
1 vote
1 answer
167 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 ...
3 votes
3 answers
1k 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 ...
  • 7,623
0 votes
1 answer
321 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 [ ...
  • 18.1k
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 &...
1 vote
1 answer
82 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 ...
1 vote
2 answers
414 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 ...
  • 121
0 votes
1 answer
219 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]+\\), \\)+&...
  • 665
1 vote
1 answer
44 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&...