On Friday 01 June 2007 11:28:44 Yegappan Lakshmanan wrote:
> Hi,
>
> On 5/31/07, Joseph Barker <[EMAIL PROTECTED]> wrote:
> > Hello, all.
> >
> > I was recently helping someone out with a vim script
> > (camelcasemotion.vim) which adds additional motion commands (they treat
> > camel-cased words (WordsLikeThis) as separate words, rather than as a
> > single word). This is easy enough to do in normal and operator-pending
> > mode. It seems to be very complicated to do this in visual mode, though
> > -- calling a function (or anything that lets you move the cursor) seems
> > to force you to leave visual mode (i.e., doing `vmap ,w :<C-U>call
> > MoveCursor()` will move the cursor to the right place, but you're no
> > longer in visual mode).
> >
> > My approach to this was to call the movement function, set a mark,
> > select the previous visual block (with gv) and then jump to the mark
> > that was previously set. The mapping that I created to deal with this
> > is the following:
> >
> > vmap <silent> ,w @="\33:\25call
> > <SID>CamelCaseMotion('w',1,'v')"<CR><CR>m`gvg``
> >
> > This seems somewhat inelegant, and also clobbers a mark to be able to
> > accomplish its magic. Is there an easier way to accomplish the same
> > thing? It seems like there should be, but I was unable to figure one
> > out.
>
> Did you try specifying the <expr> attribute to the map command?
> Something along the lines of
>
> function! MoveToCursor()
>     return "/\\u\\|\\<\<CR>"
> endfunction
>
> vnoremap <expr> ,w MoveCursor()
>
> The MoveCursor() function should return a sequence of keys that will
> position the cursor at the desired location.

Hmm. Well, that works. That particular approach has the side-effect of 
adding items to the search history (and highlighting all your uppercase 
letters if you use highlightsearch). The way the function's written now, 
the function actually calls search(), which doesn't do that. We could 
definitely get the exact same behavior by switching to using "/", which 
works fine in visual mode, but then we'd have the problem mentioned 
earlier.

So I'd rather stick to using search() (or something similar), but it seems 
to be impossible to call it without leaving visual mode. Thanks for the 
suggestion, though.

JKB

Reply via email to