views:

863

answers:

3

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

+7  A: 

Yes. M-W (to get a copy of the selected text) C-s <RET> C-y <RET>. Then repeat C-s as needed. Similarly for C-r.

fivebells
Thank you so much!
Rohit
Glad I could help. Incidentally, the relevant section of the manual is "20.1 Basics of Incremental Search". C-h i d m emacs<RET> g Basic Isearch <RET> http://www.manpagez.com/info/emacs/emacs_95.php
fivebells
+6  A: 

@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 C-y 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.

Chris Conway
A handy tip indeed.
Rohit
+2  A: 

The shortest key sequence is M-w C-s M-y.

link0ff