Questions tagged [replace]
Replacing is the action of searching a string for a sub-string and replacing it with a different string.
194
questions
0
votes
1
answer
52
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
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. ...
1
vote
1
answer
110
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
39
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.
0
votes
1
answer
39
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
39
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
393
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
96
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
79
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 ...
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 ...
0
votes
1
answer
60
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
36
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
0
answers
69
views
What would be the best way to turn Emacs into a life-friendly and peaceful editor not killing and burying anymore?
A naive and easy approach would be to replace all the occurrences of "-kill-","kill-", "-kill", "kill" and "-bury-", "bury-", "-bury&...
0
votes
2
answers
121
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
42
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
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" ?
2
votes
1
answer
201
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
81
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
64
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
71
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
55
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
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 ...
0
votes
2
answers
45
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
40
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
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
0
votes
1
answer
25
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
96
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
48
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
90
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
182
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
111
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
37
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
218
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-...
2
votes
1
answer
95
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
96
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
88
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
550
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....
0
votes
0
answers
268
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
78
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
155
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
388
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
77
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
32
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
100
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
40
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 ...
1
vote
1
answer
118
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
88
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 (...
0
votes
1
answer
38
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 ...
2
votes
2
answers
106
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
481
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 ...