Gary, thanks for the alternative approaches.
I see them as alternative ways to implement a feature, rather than as
the feature already being there. For me it was much easier to look at
the C code and add the feature (as dirtily as I did), than use the Vim
macro scripting language; in fact, I can't quite connect the two things
you wrote to be able to influence the behavior of / and ?.
I guess I have a question now, for the Vim developers in general: would
you say this would be a useful feature in Vim?
If so, I don't care how it gets done, as long as I can set some option
and get the described search behavior. If my patch is useful, I'll be
happy; and also if I can do some other contribution (documentation?) or
clean-up.
If not, I'll just maintain my own patch. I find it very useful when
editing text with something like textwidth=80, getting the line breaks
in the text automatically but wanting to ignore them in most searches. I
edit HTML and LaTeX this way.
Best regards,
Jacek
On Thu, 2010-01-21 at 21:37 -0800, Gary Johnson wrote:
> On 2010-01-22, Jacek Kopecky wrote:
> > Hi,
> >
> > for some time now I've wanted to be able easily to search in text files
> > without caring about whitespace much:
> > when I look for "foo bar" it should match "foo bar" as well as "foo
> > bar" (with the new line there).
> >
> > Basically, I'd like an option that transforms a space in search into
> > "\_s+".
> >
> > Attached is an svn diff of a quick and dirty hack that introduces the
> > option 'magicspace' to do the above. I won't pretend I understand the
> > machinery of regexp.c, but it seems to work for me.
> >
> > I'll be happy to learn if there's already a way to do it. Otherwise, I'd
> > suggest that this might be a useful feature, and I'm willing to add
> > documentation if pointed to where to do so; but I'd appreciate help with
> > cleaning up the code if necessary.
>
> There are a couple of ways to do this already in vim. As one
> example, I have created a visual-mode mapping for g* that replaces
> every occurrence of white space in the selected text with "\_s\+"
> before executing the search.
>
> vnoremap <silent> g* :<C-U>
> \let old_reg=getreg('"')<bar>
> \let old_regmode=getregtype('"')<cr>
> \gvy/<C-R><C-R>=substitute(
> \escape(@", '\\/.*$^~[]'), '\_s\+', '\\_s\\+', 'g')<cr><cr>
> \:call setreg('"', old_reg, old_regmode)<cr>
>
> As another example, take a look at the mappings of / in
> $VIMRUNTIME/macros/less.vim. These interrupt the execution of the /
> command to change the behavior of the search. The same technique
> could be used to modify the pattern before continuing the search.
> You could control the behavior of / and ? by setting the value of a
> b:magicspace variable.
>
> Regards,
> Gary
>
>
--
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php