I want to select or highlight a block in emacs without using mouse but doing it from the keyboard like vim\'s visual mode. What is the easiest way to do this from a keyboard
If I understand the question correctly, it is not about rectangular regions originally.
C-Spc
puts a mark at the current position.
Wherever your cursor is afterwards, the text between the last mark and the current position is "selected" (you can highlight this by activating transient-mark-mode
, but this will also mean that marks have to be deleted when you don't want highlight).
You can operate on that region with commands like:
C-w
. . Kill region. This deletes and puts the region into the kill ring.
C-y
. . Yank. This inserts the last snippet from the kill ring.
M-y
. . Cycle kill ring. Immediately after C-y
, this replaces the yanked part by the other snippets in the kill ring.
M-w
. . Save region into kill ring. Like C-w
, but doesn't delete.
This is just the basic usage. Marks have other uses, too. I recommend the tutorial (C-h t
).
Emacs 24.4 now has rectangle-mark-mode. C-x space to invoke it.
Use Control-Space to set a mark and move your cursor.
The transient-mark-mode
will highlight selections for you. M-x transient-mark-mode
.
You can setup Emacs to enable this mode by default using a customization. M-x customize-option
RET transient-mark-mode
.