0

Windows 10, Emacs 25.1, package iedit

Suppose I has text:

1.aaa_1111_hello

2.aaa_2222_hello

3.aaa_1111_hello

4.aaa_4444_hello

5.aaa_1111_hello

6.aaa_5555_hello

7.aaa_1111_hello

8.aaa_1111_hello

...

100.aaa_1111_hello

I want to replace all (100 lines) "_1111" by text "_zero"

Steps:

Select text "_1111"

  1. M-x iedit-mode`
  2. M-D (to delete all find text _1111)
  3. Input new text _zero

Here result.

1.aaa_zero_hello

2.aaa_2222_hello

3.aaa_zero_hello

4.aaa_4444_hello

5.aaa_zero_hello

6.aaa_5555_hello

7.aaa_zero_hello

8.aaa_zero_hello

...

100.aaa_zero_hello

OK.

But now I want to replace text ONLY from line "5.aaa_1111_hello" and to the end down. So as result I need to replace 98 lines.

The result must like this:

1.aaa_1111_hello

2.aaa_2222_hello

3.aaa_1111_hello

4.aaa_4444_hello

5.aaa_zero_hello

6.aaa_5555_hello

7.aaa_zero_hello

8.aaa_zero_hello

...

100.aaa_zero_hello

Is it possible by iedit?

1 Answer 1

2

narrow the region you want to edit (https://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html). Then use iedit as usual

You can also iedit-toggle-selection to toggle certain selections before text replacement.

You can navigate between selections. See code from iedit-lib.el,

(defvar iedit-lib-keymap
  (let ((map (make-sparse-keymap)))
    ;; Default key bindings
    (define-key map (kbd "TAB") 'iedit-next-occurrence)
    (define-key map (kbd "<tab>") 'iedit-next-occurrence)
    (define-key map (kbd "<S-tab>") 'iedit-prev-occurrence)
    (define-key map (kbd "<S-iso-lefttab>") 'iedit-prev-occurrence)
    (define-key map (kbd "<backtab>") 'iedit-prev-occurrence)
    (define-key map (kbd "C-'") 'iedit-toggle-unmatched-lines-visible)
    map)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.