[PLUG] Column/Block Editing in Emacs

Rogan Creswick creswick at gmail.com
Thu Nov 19 01:35:47 UTC 2009


On Wed, Nov 18, 2009 at 5:27 PM, Rogan Creswick <creswick at gmail.com> wrote:
>>   I need to remove double quotes from a specific column for all 3200 lines
>> in a file. I know that I can do a regex search and replace for the beginning
>> of each line, but the quotes I need to remove are in the interior. It seems
>> to me that there is a way to block a vertical column and manipulate text
>> within that marked block, but I no longer remember how to do this.
>
> Put the cursor on the first column of the text you want to remove, set
> the mark (c-space), move to the last row, and one colum *past* the
> right-most column you want to remove, and then run kill-rectangle (c-x
> r k).  There are a few other foo-rectangle commands, but I don't know
> them well, other than yank-rectangle (c-x r y).

After reading your email again, I realized that I probably didn't
actually answer your question.  I'm still not sure I know the best
way, but you can do manipulations on a specific rectangle by using
kill-rectangle as described above, then yanking that rectangle into
*scratch*, do your manipulations in *scratch*, then kill-rectangle the
modified rect again to get it into the kill-ring.

Finally, you can yank-rectangle right back into your original buffer
at the same location you first set the mark.  yank-rectangle should
shift all the old text back over to make room for the newly modified
rectangle of content.

There are also some promising foo-rectangle functions that may do this
more elegantly (eg: apply-on-rectangle) but I haven't taken the time
to puzzle out how to use them.  M-x apropos on 'rectangle' may help
you out.

--Rogan



More information about the PLUG mailing list