Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add or remove text to the end of many lines at once in Emacs?

Tags:

emacs

e.g. I want to add a double quote to the end of a bunch of highlighted lines. Or I want to delete two characters from a bunch of highlighted lines. Is there a command for this? I know there is "M-x r t" for inserting a rectangle of text, but this only works if everything is lined up vertically, which isn't generally the case of the ends of lines.

like image 652
allyourcode Avatar asked May 09 '12 23:05

allyourcode


1 Answers

You can

  1. save a keyboard macro with C-x(C-e"C-fC-x), resp. C-x(C-eBackspaceBackspaceC-fC-x). Then invoke the macro with C-xe, e, e, e...
  2. do a regex replacement with M-C-%. Replace $ with " to add a double quote, replace ..$ with nothing to delete last two characters.
like image 97
choroba Avatar answered Nov 03 '22 00:11

choroba