> This is so useful that I made cmap for it
> cmap <expr> <space> ( getcmdtype() =~ '[\/?]' && getcmdline() !~ '\\v' ?
> '\_s\+' : ( getcmdline() =~ '\\v' ? '\_s+' : ' ' ) )
>
> which also works if you use \v (very magic patterns).
There are some problems with this solution. First you don't need to
escape the '/' in the collation (which doesn't really harm in your
case, I just wanted to mention it).
Second, I am not sure, whether you want to have a Space replaced by
\_s\+ (the equivalence of ' \+'). Also this probably replaces too much
(e.g. spaces in collations).
It's probably a matter of taste, but I would hate not to be able to
search for 'foo bar' wihtout excluding 'foo bar'. I would simply
replace the space by \_s, which should also work.
Here is another solution which avoids replacing spaces in collations
(at least I hope so ;)):
fu! <sid>ReplaceSpace()
let result = getcmdline()
try
if getcmdtype() =~ "[/?]"
let result = substitute(result, '\[^\?[^ ]* ', '\\_&', 'g')
let result = substitute(result, '\%(\[[^]]*\)\@<! ', '\\_s', 'g')
let result = "\<C-U>" . result . "\n"
endif
catch
" noop
finally
return result
endtry
endfu
cnoremap <expr> <f4> <sid>ReplaceSpace()
Theoretically, you could map this to <enter>. But be aware, that if
something goes wrong, you can't input any commands anymore (at least,
if you don't have 'x' in your cpoptions settings).
regards,
Christian
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment