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
1answer
20 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&...
1
vote
1answer
20 views

icicles search and replace; need help to do a successfull replace

I try to use Icicles to search and replace. I understand to search with it (some details, that I need), but I'm unable to do a replace. The link below shows a recipe, that I try to follow, but it ...
1
vote
1answer
27 views

Remove multiple blank lines in a buffer, leave one

I'd like to take a buffer which looks like this: one two three four five And turn it into this one two three four five I've tried using delete-blank-line, however, it will only effect the area ...
0
votes
0answers
9 views

How to use projectile-replace only for specific wildcard such as Python?

From this answer, I am using projectile-replace to replace words within a folder. It works fine but it covers all the buffers. I was able to accomplish it it using find-dired: (defun my-find-files () ...
0
votes
1answer
35 views

How to replace a letter with its numerical alphabetic position?

I have this code: \author[p]{...} \author[bc]{...} \author[p]{...} \author[l,o]{...} \author[t,q]{...} \author[at]{...} \author[z]{...} \author[ak]{...} \author[az]{...} \author[ah,bq]{...} ... I ...
0
votes
1answer
30 views

Programmatically find-and-replace custom sequence

I need to write a command which will apply to my buffer custom, predefined copy-and-replace sequence. What I have is: (defun custom-processor () "Formats logs to human-readable format" ((replace-...
10
votes
5answers
897 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
44 views

How to set a variable that matches different type of strings?

I have these strings: First Type: arXiv:1234.56789 arXiv:1234.56789v1 Second type: hep-th/123456789 hep-th.AB/12345689 hep-th/123456789v1 hep-th.AB/12345689 Belong to the second type even strings ...
0
votes
0answers
31 views

error in process sentinel: Invalid file-name during replacing words

I am getting following error error in process sentinel: Invalid file-name due to generated _flymake.py files, when I am following approach for the recursively find and replace in text files not ...
0
votes
2answers
60 views

Replace string in rectangular region?

When you select a region normally, you can do a replace-string on only that region. It would be very useful to select a rectangular region (via C-x SPC), and be able to replace-string on only that ...
2
votes
1answer
50 views

Query replace regexp with a distant match?

I have a single transcript file for a set of course lectures I am watching. After doing some formatting on the file. I have it broken up into sets of lessons where the main heading is the lesson title ...
1
vote
3answers
350 views

Search and replace on lines range, numerically

I was lately being teased by a vi user. He said that within few commands, one can do search-replace (both regexp and simple string ), on lines range. And one does not need to do highlight. One inputs ...
3
votes
1answer
54 views

How to add a suffix to the end of a string in a line?

Here's an example of content in a file This_is_line_1 : 1 This_is_another_line :2 This_is_3rd_line :3 Here_is_line_4 :4 So, how can using emacs to add char @ immediately to the end 1 string ...
0
votes
2answers
54 views

How to replace first 100 digits with letters?

I want to replace the first 104 digits as it follows: 1 --> a ... 26 --> z 27 --> aa ... 52 --> az 53 --> ba ... 104 --> bz I have tried as it follows: (...
0
votes
0answers
43 views

How to replace a LaTex macro with its argument?

I want to replace a macro with its argument, that's to say, if I have \newcommand{\foo}{FOO} I want to replace every occurence of \foo with its argument FOO in a specified region. I am trying to ...
19
votes
6answers
7k views

How to search and replace in the entire buffer?

Search and replace, by M-% and !, is done from current position to the end of the buffer. How can I do it for the entire buffer? Thanks.
0
votes
1answer
86 views

need help with very complex find and replace

I have a very complex (at least to my mind) text replacement task. ideally this would be a function or macro I could run over every org header in a buffer. I want to 1. move over any TODO state to a ...
1
vote
1answer
241 views

Search/replace and replace within a block of selected text of buffer in spacemacs

As stated in the title, I want to search and edit (including replace) certain strings in a selected part of a buffer, not the entire buffer!!!, how can I do it? Are there any built-in keystrokes?
0
votes
0answers
15 views

How to replace all search-highlighted text resulting from a search with evil mode?

Once there is a search result, either from... Pressing / and entering the search term. Pressing * over a word. How can I replace the highlighted text after performing a search? Currently I ...
0
votes
1answer
199 views

Replace full-width numerals with half-width numerals

I'd like to convert numerals from half-width to full-width characters with a simple regex search and replace as follows: replace-regexp-in-string regexp rep string &optional fixedcase literal ...
0
votes
1answer
64 views

How safe is “with-silent-modifications” to mask (hide) strings before and after buffer modification?

In my LaTeX code I want to replace one-line eqnarray environments with the equation environment. To do that I need to "count" the new-line (\\) strings in a region and I also need to ignore some new-...
0
votes
2answers
58 views

Replace a block of code with another

How can I replace a block of code with another, akin to query-replace/query-replace-regexp? For example: Replacing the following block: for(A) { if(B) { s1; } else { C; } } with ...
0
votes
3answers
100 views

Complex searching and replacing [duplicate]

Suppose I have following pattern: throw "some message"; which I'd like to replace with: throw new Error("some message"); So, "some message" part should not be changed (or copied as is), and ...
3
votes
1answer
101 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
1answer
64 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
2answers
235 views

Selecting next occurrence of word incrementally

I want to make changes inside a paragraph of a large text file. If I have the cursor at the word "foo", what key combination would get the cursor at the next occurrences of this word? The cursor ...
0
votes
1answer
41 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
109 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
119 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
104 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-...
0
votes
0answers
37 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
180 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 ...
2
votes
2answers
524 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 ...
1
vote
1answer
140 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
695 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
106 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
72 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
803 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 ...
1
vote
1answer
163 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
46 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
3answers
72 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 ...
1
vote
3answers
131 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
88 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
860 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
79 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 ...
1
vote
0answers
196 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
1answer
87 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 ...
0
votes
1answer
218 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 ...
2
votes
2answers
80 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
1answer
25 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) ...