M-x all-things-emacs

Newbie Tip: isearch Word Yank

March 26th, 2007 by Ryan McGeary · 15 Comments

Our newbie tips are our way of expressing emacs features we might otherwise take for granted. We hope they help beginners climb the learning curve faster. This particular tip is one that I wish I knew far sooner when I first started using emacs.

Incremental searching with isearch-forward and isearch-backward (C-s and C-r) is crucial in day-to-day and even minute-by-minute emacs usage. Maybe you want to find all uses of a particular variable name, or maybe you want to make sure you’re not repeating the same word in a piece of literature. Let’s dive in with an example:

Suppose we want to search for the word “lorem” in the folowing paragraph:

Step 1: Incremental Search Yank

We could type C-s l o r e m, but seeing as our point is already at one particular instance of “lorem,” we can instead enter C-s C-w. The result is the same. When in isearch-mode, C-w yanks the next word in the buffer and appends it to the end of the current search string:

Step 2: Incremental Search Yank

Now suppose we want to search for instances of “lorem ipsum.” Just hit C-w again:

Step 3: Incremental Search Yank

Awesome, we just saved 9 key presses — a productivity boost.

C-w is part of the isearch-mode-map. There are many isearch modifiers. Here are some that I use most frequently:

  • C-s – to search again forward
  • C-r – to search again, but backward
  • C-w – to yank next word or character in buffer onto the end of the search string, and search for it
  • M-y – to yank last killed text onto end of search string and search for it
  • M-r – to toggle regular-expression mode
  • M-e – to edit the search string in the minibuffer

For a full listing of available isearch modifier keys, review the help for isearch (C-h f isearch-forward). It is also possible to add your own functions to the isearch-mode-map. Last month, we referenced a way to add occur to isearch.

Tags: isearch · newbie · quick · tips

15 responses so far ↓

  • 1 Jeff Squires // Mar 26, 2007 at 2:26 pm

    I’ve been using emacs for 10 years and didn’t know about C-w, and more importantly, M-y.

    It always frustrated me that I couldn’t paste something into the search string. I was always using C-y.

    This web site has been a wake up call for me. I got comfortable w/ my base set of emacs knowledge and I stopped learning.

    Thanks again guys

  • 2 Yang Zhao // Mar 26, 2007 at 3:01 pm

    me likes this site so much! Although I can visit the info document from time to time, this site is surely more fun to read. The article simply become more attractive when you put some neat pictures in.

    C-w, here I come.

  • 3 Mike Buksas // Mar 26, 2007 at 4:44 pm

    I missed learning about C-w also, and I’ve been using emacs for years. Thanks for a great tip.

  • 4 Engagement rings // Jul 22, 2015 at 12:31 am

    ... [Trackback]

    [...] Read More Infos here: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 5 Con-Cret Womens Elite // Jul 23, 2015 at 4:27 pm

    ... [Trackback]

    [...] There you will find 74871 more Infos: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 6 amazin gas station video // Jul 24, 2015 at 9:02 am

    ... [Trackback]

    [...] There you will find 81214 more Infos: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 7 amazin gas station video // Jul 24, 2015 at 10:35 am

    ... [Trackback]

    [...] Read More: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 8 attorney // Jul 24, 2015 at 9:32 pm

    ... [Trackback]

    [...] There you will find 82856 more Infos: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 9 driving under the influence // Jul 24, 2015 at 11:25 pm

    ... [Trackback]

    [...] Read More: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 10 limo rental atlanta // Jul 25, 2015 at 1:48 pm

    ... [Trackback]

    [...] Find More Informations here: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 11 locksmith Sacramento ca // Jul 26, 2015 at 6:26 am

    ... [Trackback]

    [...] Find More Informations here: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 12 do i need a prescription for propecia in uk // Jul 27, 2015 at 9:07 am

    ... [Trackback]

    [...] Read More Infos here: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 13 Marsna Design SEO // Jul 27, 2015 at 3:00 pm

    ... [Trackback]

    [...] Read More here: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 14 spring cleaning // Jul 27, 2015 at 6:24 pm

    ... [Trackback]

    [...] Informations on that Topic: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]

  • 15 online surf shop // Jul 28, 2015 at 6:39 am

    ... [Trackback]

    [...] Read More: emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/ [...]