Questions tagged [replace]

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

190 questions
36
votes
5 answers

Is there a way to use query-replace from grep/ack/ag output modes?

I'm aware of find-grep-dired, marking the corresponding files and then pressing Q to run dired-do-query-replace-regexp on the marked files. Unfortunately that requires restarting the grep and no longer using git-grep, ack, or ag and switching to use…
dgtized
  • 4,169
  • 20
  • 41
22
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
  • 4,987
  • 7
  • 31
  • 60
16
votes
2 answers

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) AC(5) AC(6) AC(7) AC(8) AC(9) AC(10) I used…
Prasanna
  • 1,470
  • 16
  • 30
14
votes
5 answers

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 kind enough to show me the matching delimiter, but…
Mankka
  • 243
  • 2
  • 8
13
votes
3 answers

Is there an equivalent to sed-style substitution commands from vim?

One of the things I miss from vim is being able to type in a substitution command that will work over multiple lines, for example: :/begin/,/end/s/foo/bar/g The above command substitutes "foo" for "bar" starting with the first line containing…
Larry Coleman
  • 1,465
  • 2
  • 11
  • 10
11
votes
4 answers

How to convert a series of lines into a working HTML list?

Right now, this is a task I find a lot easier in something like gedit, because I can just replace "\n" (the line break) with "\n
  • " and then I have a list. One of the few little things I don't seem to be able to in Emacs quickly, but…
  • mattl
    • 215
    • 2
    • 7
    11
    votes
    2 answers

    Search/replace-like feature for swapping text

    I frequently find myself trying to replace e.g. foo with bar and bar with foo in a buffer. The way I usually do it is either: 3 query-replaces: aaa -> @@@, bbb -> aaa, @@@ -> bbb give up on automation and just do the replacement by hand I suppose…
    T. Verron
    • 4,233
    • 1
    • 22
    • 55
    9
    votes
    3 answers

    how do I do case sensitive searches using evil/spacemacs?

    I'm trying to perform a search and replace in spacemacs but I need it to be case sensitive when by default it appears to be case insensitive. So I try to do :set noignorecase but then I have this error message : State noignore case cannot be set as…
    ChiseledAbs
    • 449
    • 1
    • 4
    • 12
    9
    votes
    2 answers

    Replace two strings with each other

    I would like to change all occurrences of a string (say string1) with another string (say string2) and vice-versa. To be precise I have a long document and these strings occur many times. What I currently do, is to replace string1-->string3, then…
    Name
    • 7,689
    • 4
    • 38
    • 84
    7
    votes
    2 answers

    GROUP BY + COUNT over lines in a region

    What is the simplest way of getting the number of distinct repeated in a region? For example, from THIS IS LINE A THIS IS LINE A THIS IS LINE A THIS IS LINE B THIS IS LINE B THIS IS LINE C I would like to get THIS IS LINE A 3 THIS IS LINE B …
    rsenna
    • 315
    • 3
    • 9
    7
    votes
    2 answers

    query-replace in keyboard macro

    Let me define a keyboard-macro: I enter C-x (, then go to beginning with M-<, then type M-% to query-replace some occurrences of foo by bar. Out of 3 occurrences found, I replace only the last 2, then save with C-x C-s and finish the kbd-macro with…
    phs
    • 1,095
    • 6
    • 13
    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,082
    • 6
    • 21
    7
    votes
    1 answer

    Sane settings to show context when doing search and replace in org-mode

    If I run certain functions like isearch-forward (with C-s) in an org-mode buffer, all content become temporarily visible. When I end the search, headings automagically collapse the way they were before I searched. Nice. But if I run something like…
    Brian Z
    • 2,863
    • 16
    • 22
    7
    votes
    3 answers

    How to replace words in a region using iedit?

    I want to replace some words inside a region. I would like to use iedit more than query-replace, but found the following problems (probably because I don't understand its documentation): If I select a region, and then activate iedit, it takes the…
    El Diego Efe
    • 1,601
    • 1
    • 19
    • 24
    7
    votes
    1 answer

    Replace string in buffer programatically

    I'm writing some elisp code and would like to replace some string with some another string in a buffer. Which elisp function does that ? I did a search on documentation for the related function but all I'm getting is the interactive commands. Would…
    Sibi
    • 3,603
    • 2
    • 22
    • 35
    1
    2 3
    12 13