简体   繁体   中英

in vim shift+w (W) does not work. It moves forward like w. How do I fix it?

I am using vim 7.3, installed through homebrew on OS X 10.8.3. For some reason neither W or E works as expected in normal mode. Rather than moving backward one word at a time, it moves forward. The behavior of W is identical to w . And the behavior of E is identical to e .

I have tried the o and O command in normal mode and it works as expected, so it is not like my shift key is broken.

This is driving me nuts because it is such core functionality that I can't get to work. I have tried erasing my vimrc and vim directory and change shell.

I will okay the answer of anybody who can either solve the problem for me or give good advice on how to diagnose the problem.

W and E are not the backward-versions of w and e ( b and ge are, respectively).

Lowercase versions consider words to stop at non-word characters such as punctuation or whitespace. Uppercase versions only consider whitespace (therefore moving past words with punctuation in them). The vim manual explains all combinations clearly:

           ge      b          w                             e
           <-     <-         --->                          --->
    This is-a line, with special/separated/words (and some more).
       <----- <-----         -------------------->         ----->
         gE      B                   W                       E

You can find this overview in Getting Started under Moving Around ( :help usr_03.txt ), and more details at :help word-motions .

shift+W does not usually work backwards. It moves forwards like w, just with a different definition of "word" (eg W will skip over "hello-world", w will end up at the hyphen).

Moving backwards is b.

Please use the vim help ( :h W in this instance) before thinking something is broken.

The functionality you described is not standard Vim, but if you're used to it, try these mappings:

nnoremap W B
nnoremap E gE

w means go forward to the start of a "word". In Vim, a "word" means:

  • sequence of alphanumerical and underscore (regex: \\w+ ), or
  • sequence of other non-blank characters (regex: [^\\s\\w]+ )

W means go forward to the start of a "WORD". In Vim, a "WORD" means:

  • a sequence of non-blank character (regex: \\S+ )

This example:

:help usr_03.txt
  • contains 7 words: " : ", " help ", " usr ", " _ ", " 03 ", " . ", " txt "
  • contains 2 WORDs: " :help ", " usr_03.txt "

e , E , b , B works in a similar manner.


Not directly related to the question, but if you want to find what a key (or key combination) does, simply use

:h {key}

Note: casing matters.

Examples:

  • :h W
  • :hw
  • :h yy
  • :h CTRL-W_T or the shorthand ^W_T

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM