Another way to approach this is to use occur
to select the lines you want to modify, and then apply your modification in the occur
buffer:
M-x occur
, enter the regexp that matches the lines you want to edit
- Switch to the
occur
window
- Type
e
to enter occur-edit-mode
M-C-%
to call query-replace-regexp
, do your replacements
C-c C-c
to leave occur-edit-mode
- Move back to your original window, where the modifications you made in step 4 will be made.
This does the same thing that @icarus suggests, but uses two different regexps: one to select the line, and a second to modify the selected lines. This approach requires a few more steps, but might be easier if @icarus solution requires a very complicated regexp.
You could also do variants of this using helm-occur
or other packages, but what I describe here works in regular Emacs without any additional packages.
^
to match the beginning of the line?query-replace
,query-replace
regexp, or
replace-regexp`?query-replace-regexp
. i can replace using ^ but that covers ALL lines and i dont want to add a prefix in non text (empty) lines