Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

For example here is the text I want to edit

foo
foo
foo

And here is the text result I want to have

bar foo
bar foo
bar foo

When I'm on Vim, I can do "Ctrl v" on the very first line and first column, then press "2 j", then press "i", then type "bar", done.

When I'm on Textmate, I can press "Apple Command Option" both while selecting down (by my mouse), then type "bar", done.

But when I'm on GNU Emacs 23.1, I don't know how to do it. :((

I searched EmacsWiki and googling around but didn't get the solution. Please guide me if you know my solution. Would be grateful for that.

share|improve this question
    
@Trey Jackson and @humble coffee, solved, thanks a lot!! –  Arie Dec 2 '09 at 1:13
add comment

2 Answers

up vote 6 down vote accepted

Two options come to mind. The first is rectangles (as mentioned in another answer). The explicit directions for that are:

  1. goto first line, first column
  2. C-SPC
  3. goto last line (first column)
  4. 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)
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.