Thursday, March 25, 2010

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

Sven Guckes wrote:
> * AK <andrei.avk@gmail.com> [2010-03-26 02:11]:
>> Is there any way to get vim's 'w' command
>> (and similar) to move from word to word?
>
> :map w W

A nice thought, but given the OP's original condition, it does
seem weird that "w" stops where "\<" wouldn't match, and where
'iskeyword' isn't a match. As an example of where I'd *expect*
"w" to stop based on the help description:

:match Error /\k/

I'd expect "w" to stop at the beginning of each of these "words".
With the default 'isk' setting, that excludes "<" and "=" ...
both of which "w" stops on in the OP's example. Mapping "w" to
"W" would prevent "w" from stopping on "jar" in the example given.

For a certain reading of ":help word", it could be interpreted as
meaning there are 3 types of classification: 'isk' characters,
whitespace, and everything-else; with "w" stopping at the
beginning of 'isk' sequences or non-'isk' non-whitespace
sequences (the "everything-else"). Even more confusing, if you issue

:match Error /\w/

it doesn't highlight the "<" or "=" characters as "word"
characters, despite the same usage of "word" in the descriptor
(per ":help word", a "word" includes sequences of non-whitespace
non-keyword characters surrounded by whitespace). Yes, the help
for "\w" explicitly gives the character-class, but that seems in
conflict with the definition of "word". Sigh :-/

I agree with the Antony's response that, to get the "intuitive"
behavior of jumping between 'isk'-defined "word"s, one would have
to do a mapping. I'd likely use

:nnoremap w /\<lt><cr>
:nnoremap e /\>/e-<cr>
:nnoremap b ?\<lt><cr>

(and their kin for visual-mode). The only oddity is that "w" now
respects 'wrapscan'.

I originally thought the OP was jesting or had some odd setting;
but tried it (with my default vimrc and with "-u NONE") just to
make sure, and indeed it doesn't behave as I would have expected.
I can't say I hit it (the "w" or the issue at hand) often
because I usually use t/T/f/F/;/, for my horizontal jumping, or
use the "iw" text-object for deleting/changing/visualizing the
current word.

-tim


--
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: