Repository: neovim
Issue: e in visual mode with selection exclusive skips ends of some words, cursor style is not updated when option is changed
Labels: bug-vim,needs:vim-patch

### Problem

If the `selection` option in set to `exclusive`, moving with 'e' while in visual mode when the cursor is located _on_ the last character of a `word`, that word is skipped, even though the cursor should move to one past the end of that word.


With the cursor positioned below `#` , repeatedly pressing 'e' in _normal mode_ moves the cursor to where the '^' and 'v' are pointing, and the same happens in visual mode with `set selection=inclusive` or `old`:

1)
```
# v v
 a(b) c
 ^ ^  ^

 # v  v
 a(b) c
  ^ ^  
```
With `set selection=exclusive`,  in visual mode the cursor is displayed as I-beam (pipe symbol in the example), and the character at its position is not included in the selection (when the cursor is past the start of the selection), so pressing 'e' repeatedly should move the cursor the same way as with `selection` set to `inclusive` but one character to the left, like this:

2)
```
|  v v
 a(b) c
  ^ ^  ^
  
 | v v
 a(b) c
  ^ ^  ^
```

(Note that when the cursor starts at 'a', 'e' can be pressed five times before moving to the next line, unlike in example (1) because the end of the word 'a' is already selected when starting visual mode in that example).


But current behavior of both vim and neovim is this:

3)
```
¦   v
 a(b) c
  ^    ^
 ¦   v
 a(b) c
   ^   ^
```

In both examples, some `word` ends are skipped, as the cursor is located at their last character, even though the actual selection is one character shorter, and the ends of these words are not yet included in selection.

Moreover, using 'e' with `count`, like '2e' or '3e', works differently from pressing 'e' two or three times, and almost works correctly (the starting 'last character' is still skipped):

4)
```
¦   v ee
 a(b) c
   ^ 2e

  2e 4e
¦  v v
 a(b) c
  ^ ^  ^
  e 3e 5e

   2e  4e
 ¦  v  v
 a(b) c
   ^ ^
   e 3e
```


While testing all of this, I came up with this mapping that works correctly for the example at the beginning:

```
function! End()
    let saved = &selection
    set selection=inclusive
    silent! normal! hel
    let &selection = saved
    echoerr 'fix my cursor'
endfunction

noremap r <cmd>call End()<cr>
```

What is odd to me is that:
1. `selection` needs to be set `inclusive` as `normal! e` uses the incorrect 'e' behavior from visual mode and not normal mode (`:h :normal` says that it "Execute _Normal mode_ commands"), but this is probably intended behavior.
2. Having `echoerr 'anything'` is also important as running this function changes how the cursor looks (from I-beam back to Block), even though the behavior stays the same and the cursor is still not included in the selection; 'echoerroring' anything somehow fixes that.

Also, pressing 'ge' with `selection=exclusive` either does not select the last character from the word (if the cursor is after the start of the selection) or selects one char from a word (if the cursor is before the start of the selection), the same applies for gE.

Other keys like 'b' and 'w' seem to work correctly and consistently.




### Steps to reproduce

nvim --clean
:so [mapping.txt](https://github.com/neovim/neovim/files/13111195/mapping.txt)
:e [examples.txt](https://github.com/neovim/neovim/files/13111196/examples.txt)

try the examples with `:set selection=inclusive` or `:set selection=exclusive`


### Expected behavior

1. 'e'  in visual mode skips a word end when `selection` option is set to `exclusive` and cursor is located at the last character of a `word` (which is excluded, so logically the cursor is not at the end of the word).
2. 'gE' maybe should be adjusted to go to the right side of the last character instead of the left.
3. Setting and restoring `selection` option in a function correctly restores the behavior but doesn't restore the cursor style, leaving it as `inclusive` 'block' even though it is not included in the selection.


### Neovim version (nvim -v)

0.9.4 commit d772f69  (latest as of 2023-10-24)

### Vim (not Nvim) behaves the same?

yes, 8.2.3995

### Operating system/version

neovim - Windows 10, vim - WSL Ubuntu 22.04.2 LTS

### Terminal name/version

?

### $TERM environment variable

xterm-256color linux

### Installation

nvim-win64.zip