Sunday, March 28, 2010

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

Andy Wokula wrote:
> Am 26.03.2010 14:03, schrieb AK:
>> 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>
>
> I just uploaded motpat.vim:
>
> http://www.vim.org/scripts/script.php?script_id=3030
>
> call motpat#Map(0, 'w', 'b', '\i\+')
>
> " 0 for global mapping, 1 for buffer-local
>
> btw: due the nature of search(), w will not go to EOF when the pattern
> is not
> found.
>

Excellent! Works like a charm.. I thought at first that I'd want to have
cw work as vim default, but I decided to use ce instead when I need that
behaviour, and that gives me an option of using cw to change word and
all trailing punctuation.

Thanks! -ak

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments: