For example: In VIM,
test
sample replace
test1
replace
sample test2
:g/sample/s/replace/test3/ - will replace "replace" only on matching lines with "sample"
test
sample test3
test1
replace
sample test2
In VIM, to replace only on non-matching lines can be done by :v/sample/s/replace/test3 - will replace "replace" only on non-matching lines which does not contain "sample"
test
sample replace
test1
test3
sample test2
How can above thing can be accomplished using emacs?
Are you using Emacs 24 perchance? If so, you can use the built-in occur-edit-mode:
occur
RET (pattern) RET There are third-party libraries to perform similar tricks on earlier versions of Emacs. I believe moccur-edit
is one of them, but I've never used it.
edit: Regarding the second part of your question, while I'm not familiar with a more direct way of accomplishing that, we can hack this same method to achieve it:
occur
RET .
RET to obtain occur buffer containing all linesflush-lines
RET (pattern) RET to delete matching linesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With