Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs reselect region, as Vim shortcut 'gv' does

Tags:

emacs

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.

like image 551
dragonfry Avatar asked Jun 24 '09 22:06

dragonfry


3 Answers

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

like image 123
Allen Avatar answered Oct 05 '22 23:10

Allen


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.

like image 20
baudtack Avatar answered Oct 06 '22 01:10

baudtack


Sounds like you're looking for the secondary selection, which stays put even as the region might change. (It stays put until you move it.)

See:

  • the Emacs manual, node Secondary Selection
  • Emacs wiki page Secondary Selection
  • library second-sel.el:
like image 20
Drew Avatar answered Oct 06 '22 01:10

Drew