Tip 82Preview the First Match Before Execution

Vim’s search command is much more useful when the incremental search feature is enabled. Here are a couple of ways that this option can improve your workflow.

By default, Vim sits idle as we prepare our search pattern, only springing into action when we press <CR>. My favorite enhancement is enabled with the ‘incsearch’ setting (see 'incsearch'). This tells Vim to show a preview of the first match based on what has been entered so far into the search field. Each time we enter another character, Vim instantly updates the preview. This table illustrates how it works:

KeystrokesBuffer Contents
{start}
 The car was the color of a carrot.

/car

 The car was the color of a carrot.

/carr

 The car ...

Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.