Questions tagged [replace]
Replacing is the action of searching a string for a sub-string and replacing it with a different string.
198 questions
0
votes
1
answer
56
views
replace text in region without losing markers
Context: I want to create a command that can increment a number or character contained within an arbitrary area of a buffer. I've reduced the problem to calling some function to set the text of a ...
0
votes
1
answer
30
views
Paragraphs in regexps that are not defined in the minibuffer
I sometimes have epubs that I prefer reading in org-mode, so I convert them into text files and format them while reading. That leaves all the footnotes as bare numbers, so I used replace-regexp to ...
0
votes
1
answer
79
views
How do I apply a command or macro to text that matches a specific pattern?
I use Vim a lot, but now I've decided to switch to emacs.
Here is one of my questions:
How do I apply a command or macro to text that matches a specific pattern?
Or did I use emacs correctly below?
...
0
votes
1
answer
41
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-...
1
vote
1
answer
256
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 (...
0
votes
1
answer
57
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:
(:...
1
vote
1
answer
81
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?
0
votes
0
answers
45
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. ...
1
vote
1
answer
178
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....
1
vote
1
answer
194
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.
1
vote
1
answer
215
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 "...
1
vote
1
answer
42
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 ...
2
votes
1
answer
899
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-...
0
votes
3
answers
154
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 |
| [%, ...
0
votes
2
answers
101
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 ...
1
vote
1
answer
134
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 ...
0
votes
1
answer
65
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 "%^{\\(...
0
votes
2
answers
414
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,
"...
1
vote
1
answer
51
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 ...
1
vote
1
answer
16
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" ?
2
votes
1
answer
411
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
103
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 ...
1
vote
1
answer
97
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
172
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 ...
1
vote
1
answer
73
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}/
#+...
-4
votes
1
answer
44
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 ...
0
votes
2
answers
48
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 ...
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 ...
-1
votes
1
answer
30
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
0
votes
1
answer
29
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&...
2
votes
1
answer
173
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 ...
0
votes
1
answer
61
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
116
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
204
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
vote
2
answers
216
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 ...
0
votes
0
answers
51
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
314
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-...
3
votes
1
answer
158
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
118
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....
2
votes
1
answer
96
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 ...
5
votes
5
answers
904
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....
1
vote
0
answers
412
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
120
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
194
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
524
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 ...
0
votes
1
answer
84
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-...
0
votes
0
answers
45
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
126
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)",...
0
votes
1
answer
54
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 ...
2
votes
1
answer
159
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 ...