Hi Tim,

thanks! I will try that out. I'll post back here if I figure out how to do
it with characters, but for me the lines are the most important.

Thanks for your time

2008/12/29 Tim Chase <[email protected]>

>
> > How can I find the closest occurrence of a vim search (word or
> > regex)? For example, if from my current cursor location the
> > occurrence of the first 4 digit number going forward is 5
> > lines down and the occurrence of the first 4 digit number
> > backwards is 3 lines up, I would like to be taken backward.
>
> The following should do the trick at least line-wise
> (character-wise is a lot more convoluted):
>
>   function! Find(pattern)
>     let @/=a:pattern
>     let b:prev = search(a:pattern, 'nbcW')
>     if b:prev
>       let b:next = search(a:pattern, 'ncW')
>       if b:next
>         let b:cur = line('.')
>         if b:cur - b:prev < b:next - b:cur
>           ?
>         else
>           /
>         endif
>       else
>         ?
>       endif
>     else
>       /
>     endif
>   endfunction
>
>   command! -nargs=1 F call Find(<q-args>)
>
> You can then use:
>
>   :F some_regexp
>
> Hope this helps,
>
> -tim
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to