Home » Questions » Computers [ Ask a new question ]

How to do select column then do editing in GNU Emacs?

How to do select column then do editing in GNU Emacs?

I've been using ViM, TextMate, and GNU Emacs for years.

Asked by: Guest | Views: 83
Total answers/comments: 2
Guest [Entry]

"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)"
Guest [Entry]

"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."