search next, prev while in /pattern editing
I am using incsearch. I wanted to define 2 mappings that act while I am in /search pattern editing mode, and that take me to next/prev match while leaving the cursor in /pattern commandline. Is it possible ? Yakov
Re: search next, prev while in /pattern editing
On Thu, May 18, 2006 at 12:27:26PM +, Yakov Lerner wrote: I am using incsearch. I wanted to define 2 mappings that act while I am in /search pattern editing mode, and that take me to next/prev match while leaving the cursor in /pattern commandline. Is it possible ? Yakov If you only use / and not ? then :cmap C-N CR/Up :cmap C-P C-CN/Up should work. If you want it to work with both / and ?, you have to work a little harder. Try this: cmap C-N C-R=Next()CRPlugNext fun! Next() if getcmdtype() == / cmap PlugNext CR/up elseif getcmdtype() == ? cmap PlugNext CRNN?Up else cmap PlugNext Nop endif return endfun The other direction is left as an exercise. HTH --Benji Fisher
Re: search next, prev while in /pattern editing
I think this does what you want. You only need to use /, though, since you can now go up and down while in / : cmap silent C-X c-cN:redrawCR/c-p cmap silent C-Z c-cn:redrawCR/c-p
Re: search next, prev while in /pattern editing
On 5/18/06, Eric Arnold [EMAIL PROTECTED] wrote: I think this does what you want. You only need to use /, though, since you can now go up and down while in / : cmap silent C-X c-cN:redrawCR/c-p cmap silent C-Z c-cn:redrawCR/c-p Rats. This works only if you set the @/ variable first by hitting return normally, which will highlight the pattern, then subsequence ^X or ^Y will move to the right pattern. Benji's simple example has the same problem if you start with c-p These come close, but the first time you use them, they do something slightly different than subsequent times. ^R go up *2* matches, and ^S just goes to what looks like the current match (i.e. it doesn't appear to move). It's all a problem of where the cursor actually is v.s. where the highlighting is for incsearch. cmap silent c-r crNN:redrawCR/c-p cmap silent c-s cr:redrawCR/c-p
Re: search next, prev while in /pattern editing
On 5/18/06, Eric Arnold [EMAIL PROTECTED] wrote: On 5/18/06, Eric Arnold [EMAIL PROTECTED] wrote: I think this does what you want. You only need to use /, though, since you can now go up and down while in / : cmap silent C-X c-cN:redrawCR/c-p cmap silent C-Z c-cn:redrawCR/c-p Thanks to everybody who responded. Yakov
Re: search next, prev while in /pattern editing
On Thu, 18 May 2006 at 9:31am, Benji Fisher wrote: On Thu, May 18, 2006 at 12:27:26PM +, Yakov Lerner wrote: I am using incsearch. I wanted to define 2 mappings that act while I am in /search pattern editing mode, and that take me to next/prev match while leaving the cursor in /pattern commandline. Is it possible ? Yakov If you only use / and not ? then :cmap C-N CR/Up :cmap C-P C-CN/Up should work. If you want it to work with both / and ?, you have to work a little harder. Try this: cmap C-N C-R=Next()CRPlugNext fun! Next() if getcmdtype() == / cmap PlugNext CR/up elseif getcmdtype() == ? cmap PlugNext CRNN?Up else cmap PlugNext Nop endif return endfun The other direction is left as an exercise. HTH --Benji Fisher The problem with this approach is that you can't cancel out of the search prompt and expect to be back at the original cursor position. Also, C-N is now lost for other modes, though you can fix that problem using the new expr map (see below), but may I first suggest you try my chcmdmode.vim plugin? I have the ^S at search prompt to do just this, and I have a few more maps that could be useful for you too. Now, back to improving what Benji suggested: cmap expr C-N Next() fun! Next() if getcmdtype() == / return \CR/\up elseif getcmdtype() == ? return \CRNN?\Up else return \C-N endif endfun You see, there is no temporary mapping involved, and you still didn't loose C-N for other modes. -- HTH, Hari __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com