I usesuse neovim 0.3.1
only.
I define the following function and map to do a test for getpos
in visual mode:
function! show_position()
echo getpos("'<") getpos("'>") getpos(".") getpos("v") getcurpos()
endfunction
vmap ;j :<c-u>call show_position()<cr>gv
The test file contains (please ignore :
and |
for now)
0123456789
11234:56789
2123456789
3123456789
4123456789
51234|56789
6123456789
7123456789
I then enter visual mode using v
, V
or <c-v>
, move around and then press ;j
to get the position of various markers. I have two cases tested (we can press o
in visual mode to switch the case):
- When
:
is the place I started the visual selection and|
is the current cursor place, - When
|
is the place I started the visual selection and:
is the current cursor place,
In both cases, the result shows that getcurpos() == getpos(".") == getpos("v") == upper left corner of the selection
, which I feel contradicts with common sense as well as the doc :h line
. the cursor position $ the last line in the current buffer 'x position of mark x (if the mark is not set, 0 is returned) v In Visual mode: the start of the Visual area (the cursor is the end). When not in Visual mode returns the cursor position. Differs from |'<| in that it's updated right away.
How to get the current cursor position in visual mode?