Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select or highlight a block in Emacs?

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?

like image 786
systemsfault Avatar asked Mar 18 '09 10:03

systemsfault


People also ask

How do I select a block of text in Emacs?

You can select blocks of text in Emacs just as you would in most other environments. You could, for example, drag your mouse over a region. You could also hold down the Shift key and use arrow keys. But Emacs also has a number of commands that let you work in larger semantic units.

How do I highlight a region in Emacs?

Alternatively, if you are running Emacs in its own window (and not within an "xterm" window) as part of an X Window session, you can select the region simply by using the mouse. Click the mouse's left button at the start of the area to be selected, and drag the mouse to the end of the area.

How do I highlight all text in Emacs?

C-x h will select the entire buffer. You can search for help within Emacs using the built-in help system.

How do I select a word in Emacs?

Place the cursor on either side of the word, then hold the shift key down and hold the alt/option key down, and then use the left or right arrow.


1 Answers

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

like image 183
Svante Avatar answered Sep 19 '22 20:09

Svante