Questions tagged [replace]

Replacing is the action of searching a string for a sub-string and replacing it with a different string.

196 questions
23
votes
7 answers

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.
Tim
  • 5,007
  • 7
  • 32
  • 61
7
votes
2 answers

How to refactor elisp programs using pattern matching on sexps with replacement?

I'm looking for functionality that can do source-to-source transformation of elisp programs given a set of rewriting rules. For example, given a rule like: (set (make-local-variable (quote ?var) ?value)) => (setq-local ?var ?value) It will find…
Gracjan Polak
  • 1,102
  • 6
  • 21
5
votes
3 answers

Repeat replacement until not possible?

I would like to repeat replacing a string with another string in a text file, until it is not possible. Is it possible to do that in Emacs? I only know to replace just once with M-% and !. For example, replace " " (two spaces) with " " (one space)…
Tim
  • 5,007
  • 7
  • 32
  • 61
5
votes
5 answers

How to cancel the default in replace-string?

When I use replace-string for the first time, it asks me for the string to replace and string to replace with. When running it again, it uses the previous values as default: Replace string (default a -> b): I want to replace an empty string now. I…
choroba
  • 2,045
  • 11
  • 16
4
votes
3 answers

Find/replace all files in a directory? (recursively)

One task I still end up using an IDE for is project wide find-replace. The steps are as follows. Select a directory to replace in(this could default to the projects root). Select the file extensions to match(this could initialize from other…
ideasman42
  • 8,786
  • 1
  • 32
  • 114
3
votes
1 answer

Quoting a replacement string for a regular expression

Emacs Lisp has regexp-quote to quote any string to match it literally. Apparently, there is no equivalent function to quote an arbitrary replacement string to use it literally. I mean, what could I use instead of the imaginary…
Eleno
  • 1,448
  • 11
  • 17
3
votes
1 answer

Processing of text

It is pleasure to ask you about something I cannot solve myself. I am working with big text files with many similar lines. The format of the files is defined and I want to replace repetitively some characters appearing in some columns of the files.…
mnlmrn
  • 33
  • 3
2
votes
1 answer

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 on each line, i.e. This_is_line_1@ : …
vbrnrt
  • 23
  • 2
2
votes
1 answer

wgrep cannot modify read-only files?

I am using wgrep but somehow for those read-only files (under version control), it always reports not to apply changes. Even the var of wgrep-change-readonly-file is set to t. Any idea how to fix it?
macs
  • 21
  • 2
1
vote
2 answers

How to change the name of a variable in a function within a selection?

I want to use Ctrl-space at the start of a function, and at the end of a function to select the area of the function and then change the name of a variable var1 to var2. How to do this?
Vass
  • 723
  • 1
  • 5
  • 13
1
vote
1 answer

(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}/ #+end_src * more things ... And i created this…
anquegi
  • 749
  • 5
  • 22
1
vote
1 answer

Replace "fl"like two-letter combo with two letters

I have a text file, whose content is from a pdf file. I would like to replace two letter combos, such as "fl" and more, with the two letters. Is it possible to do that in Emacs just once, without repeating for each specific combo? Thanks.
Tim
  • 5,007
  • 7
  • 32
  • 61
1
vote
1 answer

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 possible.
Edman
  • 1,207
  • 8
  • 13
1
vote
1 answer

Replace word at point preserving the case pattern

Currently, I am doing the replacement of the word under the cursor on a script using: (setq bounds (bounds-of-thing-at-point 'word)) (setq pos1 (car bounds)) (setq pos2 (cdr bounds)) (delete-region pos1 pos2) (insert newword) But this does not…
Mario Román
  • 281
  • 2
  • 11
1
vote
1 answer

Anonymizing text using emacs (replace all non-whitespace characters by x)

Suppose I select some text in an emacs buffer using point and mark. How do I tell emacs to replace each non-whitespace character with x, say? For concreteness, that I select the text using point and mark. Also, for clarity, I consider newlines to be…
Faheem Mitha
  • 406
  • 4
  • 16
1
2