Hello all,
I want to select or highlight a block in emacs without mouse but from the keyboard like vim's visual mode. What is the easiest way to do this from a keyboard?
Hello all,
I want to select or highlight a block in emacs without mouse but from the keyboard like vim's visual mode. What is the easiest way to do this from a keyboard?
Take a look at region-rectangle in emacs.
In short, you start selection like usual with C-spc, then kill region with C-x r k and paste/yank killed block with C-x r y.
Use C-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.
See the article: "Working with rectangular selections", especially the comments section. See also the section of CUA mode documentation titled "CUA rectangle support". There's also a nice video on vimeo.
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
).