Friday, March 26, 2010

Re: 'w' command to actually move to the next word

Christian Brabandt wrote:
[snip]
>
> Something like this may be?
>
> fu! <sid>MyWMotion(count)
>     for i in range(a:count)
>     call search('\i\+')
>     endfor
> endfu
>
> noremap <silent> w :<c-u>call <sid>MyWMotion(v:count1)<cr>
>
> I haven't looked at how to make this work with visual mode yet.
>
> regards,
> Christian
>



Excellent! Here I extended this to handle 'b'. I think that's enough for now, when I have a bit more spare time, I'll think of adding more stuff.

fu! <sid>MyWMotion(count, dir)
    for i in range(a:count)
        if a:dir
            call search('\i\+', 'b')
        else
            call search('\i\+')
        endif
    endfor
endfu

nnoremap <silent> w :<c-u>call <sid>MyWMotion(v:count1, 0)<cr>
nnoremap <silent> b :<c-u>call <sid>MyWMotion(v:count1, 1)<cr>



No comments: