Pressing W (as in Shift+w) when there is only one word in front of the cursor causes the cursor to immediately jump to the next line. This is unlike what happens when doing the reverse with B, where the cursor stops at the beginning of the line before continuing to the previous line.Is there some way to configure W to act more like B, in that it stops when it reaches the end of the line, then jumps to the next if pressed again?
Prevent W from jumping to next line
cursor movement;vi words
As Tumbler41 pointed out in the comments, the simpler solution would be to use E instead of W. However, if you would like to configure W to behave this way, you could do this:nnoremap <expr> W getline('.')[col('.') - 1:] =~# '\s\S' ? 'W' : (col('.') + 1 == col('$') ? 'W' : '$')Unfortunately, this solution is longer thank I'd like, and somewhat hacky, but it works. Here's a quick explanation of how it works:Use an 'expression mapping' on the key W. This means that we will evalue themapping as vimscript code to determine what keystrokes to pressnnoremap <expr> W  Get everything after the cursors position  getline('.')[col('.') - 1:]  Does it contain a whitespace character followed by a non-whitespace character?  =~# '\s\S'  If it does, return 'W'  ? 'W'  Otherwise:  :    Are we on the last character?    (col('.') + 1 == col('$')    If we are. return 'W'    ? 'W'      Otherwise, return '$'      : '$')