How to do select column then do editing in GNU Emacs?
Two options come to mind. The first is rectangles (as mentioned in another answer). The explicit directions for that are:
- goto first line, first column
- C-SPC
- goto last line (first column)
- C-x r t bar SPC RET
Another option, which provides very nice rectangle/column editing commands is CUA mode. Here's a blog post (disclosure: my blog) that describes how to use it. To see the power of CUA mode it's totally worth watching this three minute video.
I integrate CUA mode with the following (because I prefer not to have transient mark mode):
(setq cua-enable-cua-keys nil)
(setq cua-highlight-region-shift-only t) ;; no transient mark mode
(setq cua-toggle-set-mark nil) ;; original set-mark behavior, i.e. no transient-mark-mode
(cua-mode)
In Emacs-24.4, the base support for rectangles has been improved a bit, so instead of using C-SPC
followed by C-x r t
, you can do:
C-x SPC
down down
C-t bar RET
One of the nice thing about it compared to the the C-SPC
method is that you'll get visual feedback about the rectangle you're selecting. Of course the cua-mode
method works as well (and works similarly).
In emacs these kind of columns are referred to as 'rectangles'. So this is the relevant documentation page.
All these commands require that the region contains the the rectangle you are operating on. So you need to set the mark on the top left character in the rectangle and extend the region to the bottom right character in the rectangle. The command you're after is M-x string-insert-rectangle
which then prompts you for the string to insert.