tags:

views:

357

answers:

3

In vim, visual block can be recall by 'gv' command so that multiple commands can be applied easily. (such as, comment out, then indent, then do_something_fun).

In Emacs, how can this be achieved? [C-xC-x] only works when current cursor position stays where previous block ended. If previous block was changed, the closest is to go through 'point-to-register' and 'jump-to-register'.

Just I am curious if there is an Emacs built-in command making this in one shot.

+4  A: 

If I understand correctly what you are asking for, then you don't need to do anything. When you select a region in emacs, it stays selected until you select a new one. So you could select the region and then perform as many actions as you want.

docgnome
Using Emacs 23(.0.93.1). Thanks, but it didn't work as you mentioned. I am selecting resion using CTRL-SPC for beginning, current-posision for the end. Region highlights after the selection. Applying a command makes this hightlight go away. I assumed this deselects region.
Raymond
@Raymond Try performing another action. The region is no longer highlighted but it is still selected.
docgnome
+1 Agreed that this solution works.
Trey Jackson
+4  A: 

If Transient Mark mode is off, the region is always active. If it's on (which it sounds like is your situation), you can set mark-even-if-inactive to non-nil to allow region commands to work while the region isn't highlighted.

However, note you also can cycle back through previous mark positions using C-u C-SPC -- this will pop the mark ring. Once you're back to where you want to be, C-x C-x will rehighlight the region you want. (It may take a little bit of playing with this feature to get a feel for it, but it's why I can't switch away from Emacs now.)

Allen
With this in mind, Emacs seems to be way more flexible than vi in this regard. However, C-x C-x should suffice in most situations like described by the OP.
kapuzineralex
+1  A: 

Also narrow-to-region (CTRL-x n n ) applies every command from then on just to that region- you can't hurt the rest of the buffer, it doesn't even show. After done editing , widen (CTRL-x n w )to get back the whole buffer. CMM

Well, thanks, that's an interesting one.
kapuzineralex