Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for marked (selected) text in Emacs

I use emacs for viewing and editing code and other text files. I wanted to know if there is a way to search forward or backward for text which is marked in the current buffer. Similar to what I can do in notepad or wordpad. As in can I mark some text in the buffer and do a C-s or C-r and be able to search with the marked text without actually typing in the whole search text?

Thank you,

Rohit

like image 802
Rohit Avatar asked Oct 14 '08 21:10

Rohit


People also ask

How do I search for text in Emacs?

Simple Searches Emacs also offers a simple, or nonincremental, search. To use a more straightforward search, type C-s RETURN or select Search from the Search menu. Type the search string, press RETURN, and Emacs begins the search. Simply press C-s again to repeat the search.

How do I search backwards in Emacs?

To search backwards, use C-r ( isearch-backward ) instead of C-s to start the search. A backward search finds matches that end before the starting point, just as a forward search finds matches that begin after it.


1 Answers

@Alex nails it.

Another option I use quite often is C-s C-w to search for the word after the current mark. Hitting C-w repeatedly increases the search with additional words (e.g., C-s C-w C-w C-w searches for the 3 words after the current mark).

Similarly, C-s M-s C-e searches for the rest of the line after the current mark and C-s C-M-y searches for the character after the mark. These are both repeatable in the same way (the former by somewhat-awkwardly repeating M-s C-e after C-s).

like image 162
Chris Conway Avatar answered Sep 20 '22 00:09

Chris Conway