When writing non-code with vim, I often have the need to search for multiple words that might be separated by a newline instead of a space.
开发者_运维问答For example, I may want to search for occurrences of "white house", but some occurrences may have a newline between "white" and "house".
I am aware that such multiline search is possible with "\_s" (e.g., "white\_shouse") but it is cumbersome. I would like to replace the search command such that spaces are treated as "\_s" without me having to type them out.
Is it possible to "remap" the / search command?
You have at least two options:
- Define a mapping that will remap, for example,
,s
to\_s
:,s
is easier to type:cnoremap ,t \\_s
- Define a custom search function that will replace all occurrences of
\s
with\_s
and use it:function Search(prompt) let searchstring=substitute(input(a:prompt), '\\\\s', '\\\\_s', 'g') return a:prompt.searchstring."\n" endfunction nnoremap <expr> <special> / Search('/')
or evenfunction Search(prompt) let searchstring=substitute(input(a:prompt), ' ', '\\\\_s', 'g') return a:prompt.searchstring."\n" endfunction nnoremap <expr> <special> / Search('/')
(this function replaces spaces with\_s
)
精彩评论