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
1answer
26 views

How to call `replace-string` with specific strings from code?

Sometimes I want to replace [$] with \( and [/$] with \) either in the region or in the whole buffer. replace-string works well for that, except for requiring me to type the strings I want to replace. ...
1
vote
1answer
37 views

Regex: Don't Match Text Between Curly Braces (LaTeX Commands)

I've been using pandoc and emacs to convert beamer presentations to markdown format. In the beamer presentations we highlighted certain code in example code blocks red. Pandoc has left me to get rid ...
1
vote
1answer
31 views

How to paste a multiline regex from re-builder into `replace-regexp`

I built with M-x re-builder a regex to match empty quoted lines in emails. In read syntax it is: "^>\\s-*\n>" How can I copy this regex in re-builder, so that I can paste it in the first ...
1
vote
1answer
55 views

csv-mode: do not split line on newline inside quoted field

I'm using the latest csv-mode in Emacs 25.3.1 in centos 6.10. The problem is that I have many fields that are long documentation strings and many of them have embedded newlines. This messed up csv-...
1
vote
1answer
50 views

Search and replace two consecutive newlines

Running spacemacs 0.200. I am sorry if it is too basic. But I am just not able to get this. How do I convert two consecutive newlines with some text, say, 'there were two newlines here'? I could ...
0
votes
0answers
36 views

replace char at position using Emacs script

Below script will insert a char at position: #!/usr/bin/env emacs --script (defun modify(filename) (find-file-literally filename) (goto-char 3) (insert "\x39") (save-buffer 0) (kill-buffer)...
0
votes
2answers
55 views

Using Occur to to recursively search in a directory [duplicate]

I use 'occur' to search for regexp in current buffer and edit the results in occur buffer . Now my requirement is to search all the files in a directory(including sub-directories ) and edit the ...
1
vote
2answers
55 views

Emacs replace-regexp reference the match in the replace argument

Is there an easy way to use replace-regexp to do something like: XYZ001 XYZ002 XYZ003 to 'XYZ001' 'XYZ002' 'XYZ003' i.e. replace-regexp XYZ* 'XYZ*' Is replace-regexp the the wrong tool for the ...
0
votes
1answer
42 views

Search and replace isn't working in my function

I created the following function to remove macrons from vowels (this is a reduced version that only searches for the vowel "ā"): (defun nv/eliminatemacron () "" (interactive) (save-excursion ...
1
vote
1answer
53 views

Elisp expressions in projectile-replace-regexp

I need to execute a regular expression with case conversion in a entire project. If I run query-replace-regexp in a single file informing '\([A-Z]+\)' and '\,(downcase \1)', it works as expected. But ...
1
vote
1answer
120 views

search and replace double space

I've only recently started using emacs, for professional reasons. I'm trying to replace all double spaces in a text file by single ones using regex. In C-M-s the expression \s-\{2\} matches two spaces ...
4
votes
3answers
80 views

Search and replace TeX \over with LaTeX \frac

I have a source file that was originally coded in TeX (well, this is actually a conTeXt file). A fraction like 1/(2/x^2) is coded as {1 \over {2 \over x^2}}. I'd like to convert to LaTeX syntax, that ...
2
votes
1answer
43 views

Add multiple predicates to isearch-filter-predicate

I wrote a set of predicates to filter matches in my ìsearch-* and query-replace* routines. I also wrote a macro to bind the isearch-filter-predicate variable to multiple predicates: (defmacro with-...
6
votes
3answers
703 views

Regexp replace to match a string, but not match a superstring

Let's say I want to replace the string "Vector" by "VectorBase", but there are existing instances of "VectorBase". So I would like to omit "VectorBase". What is an elegant way to achieve this? An ...
0
votes
1answer
81 views

Replacing selected text in Emacs with one character

In Vim, I can do this trick on a line with the words "People": yy p Shift-v r + It will produce a set of lines that like this: People ++++++ I would like to be able to reproduce this in Emacs if ...
0
votes
1answer
36 views

How remove text before “,” (include) in every lines?

suppose I has the next text: -1,0x0 Fireplace HD 1160,0x0 Music HD 719,1 HD -1,1 MUSIC CHANNEL 154,1+1 -1,100% News -1,100AutoMoto TV I need to remove text before "," (include ,) So the result must ...
0
votes
0answers
18 views

Apply evil-mode Macro to helm-ag Results

I love using helm-ag-edit within projectile to make bulk edits to many files in my project in one fell swoop. However, sometimes I want to apply keyboard macros (using evil-mode) to these files. The ...
1
vote
3answers
68 views

Function that does `M-x replace-regexp` or `M-x occur` with a fixed pattern and replacement strings

I often use M-x replace-regexp and M-x occur with some fixed regexp pattern and replacement string on many files. Doing it manually by opening each file in an Emacs buffer and hitting the keys is ...
0
votes
1answer
55 views

Advanced search and replace

I have a file, with a lot of instances of ... fclose(f1); fclose(f2); fclose(f3); ... I'd like to replace these with ... if(fclose(f1)!=0) return 1; if(fclose(f2)!=0) return 1; if(fclose(f3)!=0) ...
1
vote
1answer
335 views

How to remove empty lines of a selected region of code in Emacs?

Is there a way to remove blank lines from a region of code I select? I am asking because I copy/pasted code and it seems to have several blank lines I want to get rid off.
0
votes
2answers
46 views

Create strings of a wordlist using replace-regexp

I have a word list with a lot of words that I want to convert into a json file. To do this I need to make them strings and add a comma in the end of all words. I figured it would be nice to use ...
0
votes
1answer
59 views

Using a predefined Regex on a yank

can you please help me to write a small emacs function? This is the first lisp function I am writing and I think I am getting confused with point and mark placement. I want to write a function that ...
1
vote
0answers
131 views

Match data clobbered by buffer modification hooks in tex files

I run into the error Match data clobbered by buffer modification hooks when editing tex files. The way to reproduce is as follows. In terminal, cd mkdir tèst/ cd tèst/ touch test.tex echo "\input ./...
0
votes
3answers
52 views

Change Case of last searched pattern

Is there a fast way of changing the case of the last searched pattern? Inside Evil mode, I press # key to quickly search for keywords at point. And I want to change the case of all occurences of ...
0
votes
1answer
109 views

In elisp, search and replace only on lines containing a specific string

Running spacemacs 0.200.13 on emacs 25.2.2 on Kubuntu 18.04. I need to search and replace only on lines containing a specific string. Interactively, I use occur, move to the occur buffer, and do all ...
0
votes
1answer
24 views

Replace a match only till some other match is found

Aiming to convert first row of a html table from to tags. So, I wrote the following code. (defun tdtoth () (if (search-forward "</tr>" nil t) (while (search-forward "td" nil t) ...
1
vote
1answer
146 views

Case-sensitive search and replace in elisp in spacemacs

Running Spacemacs v.0.200.13 on emacs 25.2.2 on Kubuntu 18.04. Consider the following code: (defun xx-ll () (interactive) (save-excursion (goto-char (point-min)) (xx-replace-...
1
vote
1answer
113 views

Produce \' in a string replacement

As you know, functions such as replace-regexp-in-string and replace-match have an argument LITERAL, meaning ... If optional ... arg LITERAL is non-nil, insert NEWTEXT literally. Otherwise treat ‘\’ ...
1
vote
1answer
119 views

Replacing autoref command format specification in auctex's font-latex-match-reference-keywords-local

With some help I have redefined the autoref command to take an optional argument, see https://tex.stackexchange.com/questions/428229/autoref-with-optional-argument-text-in-generated-link Now I am ...
-1
votes
1answer
136 views

How to find all characters, newlines included?

I have this LaTeX code: %%% 10 \bibitem{bib2} W.~Kockelmann, G.~Burca, J.F.~Kelleher, S.~Kabra, S.-Y.~Zhang, N.J.~Rhodes et~al., \emph{Status of the neutron imaging and diffraction instrument IMAT},...
2
votes
2answers
66 views

How can I use a char as a counter?

I have this LaTeX code: \begin{enumerate}[a] \affiliation{...} \affiliation{...} \affiliation{...} ... \affiliation{...} \end{enumerate} and, using a script written in Emacs Lisp, I want to ...
0
votes
3answers
73 views

Help with `replace-regexp-in-string`, to replace only first instance in every line

I have the following string: // const asdf = 'asdf' // // comment // const asdf2 = asdf And I want to run a regexp replace to make it look as follows: const asdf = 'asdf' // comment const asdf2 = ...
1
vote
2answers
389 views

How to search for any unicode octal character in a buffer?

I'm looking for a way to locate all unicode octal characters in a buffer such as \344 and replace them with ä or \353 with ë, etc. At the least if I could just locate octal characters using ...
11
votes
2answers
742 views

Incrementally replace a given string

Let us say I have a text like so below: AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) Now I want to replace the nn with numbers like so AC(0) AC(1) AC(2) AC(3) AC(4)...
2
votes
2answers
305 views

Replacing string in a region and conditional replace

My goal is to write a simple function that can do the following: Staring with an expression that looks like $$ x = y $$ $$ y = z $$ $$ z = x $$ (There can more lines of such equations) I want to ...
8
votes
4answers
495 views

How to replace matching parentheses?

I write (and rewrite) a lot of mathematical formulas in LaTeX with Emacs. I frequently run into situations where I want to change a pair of matching parentheses, to improve readability. My Emacs is ...
0
votes
1answer
34 views

How can I constrain a predefined replacement-function to selected text?

When using replace-string from the M-x while having some text selected, it only operates on that selection (specifically, on an Evil visual selection, in my case). However, if I put the same ...
1
vote
1answer
107 views

Replace certain multibyte characters

In my markdown file (coming from a Windows computer on which I have no control), I have several multi-byte characters. Some text xx Some text yy Some text In emacs, they are displayed as \221 and \...
1
vote
2answers
187 views

Find and replace a text among the files of a project

How can I do a "find and replace a string" in the files of a project? Is there a standard, built-in way?
3
votes
1answer
315 views

Find/replace in differrent file extensions

Windows 10, Emacs 25.1, Dired+, xah-find I use package xah-find for find/replace text in many files. OK. It's work. If I want to find in all java files I use the next regexp: File path regex: \.java\...
1
vote
1answer
55 views

Executing multiple replacement regexps against a string

I wanted to write a function that "auto-corrects" a string, based on a list of regular expressions and their respective replacements. I've come up with this, and it works: (setq auto-corrections-...
0
votes
1answer
86 views

Using result of an Elisp function as input to replace-regexp in interactive mode

I am using replace-regexp interactively. Can I programmatically refer to a match or otherwise interpolate values in the replacement string? In Ruby, for example, it is easily done, by using the #{ <...
1
vote
1answer
124 views

elisp replace float number with half value

I need to replace below string: (24.0000,28.0000) .. controls (27.3100,28.0000) and (29.9800,25.3100) .. (29.9800,22.0000) to: (12,14) .. controls (13.655,14) and (14.99,12.655) .. (14.99,11) The ...
2
votes
2answers
152 views

Query-replace-regexp alternative capable of handling nested braces?

TL;DR Is there some method in Emacs to replace text with nested braces/parentheses? Example I had a situation where I had to replace \dchi{ARG1}{ARG2} by \chi^{ARG2}(ARG1) For simple cases, ...
1
vote
2answers
29 views

M-x replace-regexp uppercases words in replacement text based on the first letter present in the line

So, I have the following buffer: 1234 Red blue green yellow # colors orange Now, if I run M-x replace-regexp I get odd results. If I have the search string: ^\(.+\)$ and the replacement string: ...
2
votes
2answers
179 views

Replace whole words in string

replace-string has the DELIMITED parameter, which can be used to replace only whole words. replace-in-string does not have such a parameter. Is there an easy work-around besides creating a temporary ...
2
votes
1answer
89 views

How can I replace outside of org-babel blocks?

I am using a command which affects the entire buffer, replacing all the ocurrences of a given expression (goto-char (point-min)) (replace-string "foo" "bar") Is it possible to apply a command like ...
2
votes
4answers
234 views

Search/replace inside a rectangular region, without CUA mode

I want to use search/replace (string or regexp) inside a rectangular region (aka column selection?). Consider this question: Search and replace inside a rectangle in emacs That's what I want, except ...
3
votes
1answer
142 views

Arithmetics in a regex in a lisp function

I want to replace all hard column widths in several LaTeX-documents, e.g. replace {90mm} by {0.75\textwidth}. I already found out that you can use \, and #1 to so arithmetics on captured groups, like ...
2
votes
1answer
83 views

Perform-replace only on text (no comments, no math) in latex-mode?

I need to write some Emacs-Lisp code that uses the perform-replace function, limiting its range of action only on text (ignoring comments, in-line math and math ambients) on LaTeX documents (in latex-...