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
0 votes
1 answer
35 views

Implementing a version of "how-many" function, sensitive to isearch-filter-predicate

I want to build a version of the how-many function that is sensitive to isearch-filter-predicate. To achieve this, I had to first build a version of re-search-forward that obeys isearch-filter-...
Gabriele's user avatar
  • 1,554
1 vote
1 answer
71 views

How save changed in all buffers (Embark export: consult-grep)?

consult-grep #hello# embark-export C-x C-q replace-string hello -> hi As you can see it's change in buffer "Embark Export: consult-grep". But how to save this changes in all files (...
a_subscriber's user avatar
  • 4,074
0 votes
1 answer
51 views

Replacing in nested regexps

I'm having to replace the configurations of keymaps in my use-package with define-key expressions and thought I'd use that to get more proficient with using regexp-replace. The situation is this: (:...
Alexander Praehauser's user avatar
0 votes
1 answer
63 views

How to replace, in a simple way, pairs of parentheses?

It would be useful for me to be able to replace, in a simple way, with simple emacs commands, parenthese pairs, like: (text text) [text text] {text text} ... How to do it?
Salvo Micciché's user avatar
0 votes
0 answers
44 views

Regexp searches that repeatedly cover expressions

I'm just going through an old Latex-text I've written and wanted to use regexp-replace to make any pair of brackets containing at least one other pair of brackets into a \left(.*\right)-expression. ...
Alexander Praehauser's user avatar
1 vote
1 answer
130 views

Function to replace strings from region and save result in kill-ring

I'm almost completely ignorant in elisp, but I'd like to have a function that does the following: Takes a string from (a) a region, if one is selected, or (b) user prompt, if a region is not selected....
pglpm's user avatar
  • 301
1 vote
1 answer
64 views

How would you remove all emojis from string?

Basically what the title says, I'm looking for the best way to remove all emojis from a string.
thanosapollo's user avatar
0 votes
1 answer
123 views

replace nth-match of a regexp in a string

I'm looking for a function that can replace the nth-match in a string. Here's an example. 2 is the index of the nth-match, [0-9]+ is the regular expression to search. foo is the replacement and "...
rdrg109's user avatar
  • 408
1 vote
1 answer
41 views

function needed to replace short, static list of keywords

In my workflow I copy emails into an orgmode file. I'd like to have head of the email formatted. In english emails (just as an explanation) I'd like to have *To:* instead of To:, because orgmode then ...
Keks Dose's user avatar
  • 508
2 votes
1 answer
635 views

What am I supposed to do about the error “Invalid search bound (wrong side of point)” in my code calling re-search-forward?

I have several interactive functions that pretty straightforwardly do re-search-forward and replace-match in a loop. Once in a while, if I have a region selected and do the replacement in it, re-...
aaa's user avatar
  • 436
0 votes
3 answers
117 views

How to turn numeric percent cell content |86%| into progress bar ▊▊▊▊------ purely with TBLFM & elisp code?

This is a bit trickier, but the result is awesome: |-------------------------------------------------------| | Progress | | [%, ...
starquake's user avatar
0 votes
2 answers
88 views

How can I interactively replace text in all files in all subfolders?

Emacs 27.1 Linux Mint 21 I have text modifyNetwork in 50 files in differents folders. I need to replace them by text performCommand. What is the easiest way to replace text in all files in all ...
a_subscriber's user avatar
  • 4,074
0 votes
0 answers
23 views

Append text to unfolded org-mode lines only

Sample org file: * H1 ** H1.1 *** H1.1.1 ** H1.2 *** H1.2.1 ** H1.3 *** H1.3.1 ** H1.4 *** H1.1.1 I want to append some text to lines ** H1.2 ** H1.3 First, cycle visibility of the file to show only ...
user2567544's user avatar
1 vote
1 answer
77 views

How can I search / replace in visible org mode lines only?

I have an org file where the majority of the text in the buffer at any one time is folded. I would like to be able to perform a search and replace on only the unfolded lines. For example, I have a ...
user2567544's user avatar
0 votes
1 answer
43 views

Multiple regexp replace in string

I need to search for every declared variable in a string with format %^{var}, prompt a value and replace in place. (let ((primitive "(%^{size}, %^{center})")) (if (string-match "%^{\\(...
my_display_name's user avatar
0 votes
2 answers
181 views

Regex to find and replace a specific character inside of multiple quoted strings in a string

Given an example string of JSON (formatted here for reading, actual input may or may not be formatted): { "page":1, "per_page":6, "total":12, "...
David's user avatar
  • 126
1 vote
1 answer
46 views

Search and replace to merge or eliminate text lines

A WinRAR command (rar vt -pmypassword -v myarc.part01.rar >source.txt) produces detailed information on files contained in .rar files or segments (e.g., filename.part01.rar). Here's an example for ...
Ray Woodcock's user avatar
1 vote
1 answer
11 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" ?
cjorssen's user avatar
  • 197
2 votes
1 answer
296 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 ...
B. Pillet's user avatar
1 vote
1 answer
93 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 ...
Joachim W's user avatar
  • 145
1 vote
1 answer
83 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, ...
Alessandro Bertulli's user avatar
0 votes
1 answer
90 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 ...
ideasman42's user avatar
  • 8,796
1 vote
1 answer
62 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}/ #+...
anquegi's user avatar
  • 749
-4 votes
1 answer
43 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 ...
Dilna's user avatar
  • 1
0 votes
2 answers
47 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 ...
Dilna's user avatar
  • 1
0 votes
1 answer
42 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 ...
Dilna's user avatar
  • 1
-1 votes
1 answer
28 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
Dilna's user avatar
  • 1
0 votes
1 answer
27 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&...
Dilna's user avatar
  • 1
2 votes
1 answer
109 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 ...
M0M0's user avatar
  • 143
0 votes
1 answer
52 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>, ...
Brian Fitzpatrick's user avatar
0 votes
3 answers
102 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} \...
Brian Fitzpatrick's user avatar
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
0 answers
41 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,...
Vadim Radionov's user avatar
1 vote
1 answer
264 views

word replacements with prettify-symbols-mode

I am writing a feature that changes the displaying of certain words as is done in texinfo-mode, where greek syntax \alpha is displayed as the actual greek symbol α. The implementation uses prettify-...
Dilna's user avatar
  • 1
2 votes
1 answer
113 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....
Rich Smith's user avatar
0 votes
4 answers
101 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....
lawlist's user avatar
  • 19.1k
2 votes
1 answer
91 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 ...
questionto42's user avatar
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
1 vote
0 answers
352 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 ...
Warrick Macmillan's user avatar
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
173 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, ...
Chris Stryczynski's user avatar
0 votes
3 answers
441 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 ...
alper's user avatar
  • 1,370
0 votes
1 answer
82 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-...
alper's user avatar
  • 1,370
0 votes
0 answers
37 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 ...
potatoe's user avatar
1 vote
1 answer
112 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)",...
Masroor's user avatar
  • 123
0 votes
1 answer
43 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 ...
xeruf's user avatar
  • 344
2 votes
1 answer
134 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 ...
Ashok Khanna's user avatar
0 votes
1 answer
90 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 (...
alper's user avatar
  • 1,370
0 votes
1 answer
39 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 ...
student's user avatar
  • 1,109