Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #793 - Search for selected phrase ignoring spaces

Created: September 17, 2004 15:22 Complexity: basic Author: mosh albany Version: 6.0 Karma: 17/7 Imported from: Tip#793

This builds on two previous tips to search for sentences.


What: To re-search for a phrase again, ignoring space differences.


How: Visually select a phrase with the mouse and press //

to find the phrase again (modulo spaces). 


:vmap <silent> // y/<C-R>=substitute(escape(@", '\\/.*$^~[]'),"[ \\t\\r\\n]\\+","\\\\_s\\\\+","g")<CR><CR> 


How, it escapes metachars in selection,

and changes spaces in selection to generic space+.


HTTP post might garble the backslashes in the mapping above, it

has 2,2,2,2,2,4,4 backslashes.


- Mosh http://www.cs.albany.edu/~mosh

Comments

You mean, the line

:vmap .... 

goes into my ~/_vimrc, and it maps // in visual mode to a search-phrase command?

thank you.

Agrippa Nagpada , September 19, 2004 22:20


the original tip# is 780, please see that also, for more discussion.

mosh , September 29, 2004 14:49


Advertisement