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
0answers
47 views

How to replace a block of text with a “query-like” approach all at once?

I want to search and replace a block of text with a "query-like" approach all at once. For example, if I have \emph{``Foo $\bar$ baz''} to be replaced by \emph{Foo $\bar$ baz} using a &...
1
vote
1answer
35 views

How can I get the search string from incremental regexp search to use with replace regexp

If I want to do a replace-regexp I usually start with a isearch-forward-regexp so I can get immediate visual feedback on the search string. From there I'd like to grab the search string for using in ...
0
votes
2answers
43 views

How do I search/replace with case sensitive search?

In emacs I'm using M-% to replace occurrences of b_abcd (of which there are only a few) with B_abcd (of which there are very many). Currently Emacs asks if it's OK to replace at each B_abcd, which ...
0
votes
1answer
40 views

Regex to replace subset of repeated pattern

ABC、DEF, GHI, JKL、MNO PQR、STU, VWX、YZ How do I replace all , s with 、 in the repeated pattern above? The repeated pattern can be mapped with the regex below: "^\\([A-Z]+、\\)\\(\\([A-Z]+\\), \\)+&...
1
vote
1answer
22 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
29 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 () ...
1
vote
1answer
21 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 ...
0
votes
1answer
36 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
34 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-...
0
votes
1answer
46 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
32 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
75 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
55 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 ...
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
55 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 ...
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
324 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
16 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
237 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
2answers
62 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
101 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 ...
1
vote
2answers
286 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
118 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
125 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
108 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-...
3
votes
1answer
116 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
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
198 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
589 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
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
1answer
153 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
791 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
113 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
76 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-...
0
votes
1answer
68 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-...
6
votes
3answers
822 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
171 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
47 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 ...
1
vote
3answers
143 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
89 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
905 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
84 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
88 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
204 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
78 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
227 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
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) ...