On Thu, 18 May 2006 at 9:31am, Benji Fisher wrote: > On Thu, May 18, 2006 at 12:27:26PM +0000, 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-C>N/<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()<CR><Plug>Next > fun! Next() > if getcmdtype() == "/" > cmap <Plug>Next <CR>/<up> > elseif getcmdtype() == "?" > cmap <Plug>Next <CR>NN?<Up> > else > cmap <Plug>Next <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 "\<CR>NN?\<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