[vim/vim] getpos and setpos are not consistent with visual marks (Issue #19049)

3 views
Skip to first unread message

Eric Larson

unread,
2:46 AM (3 hours ago) 2:46 AM
to vim/vim, Subscribed
numEricL created an issue (vim/vim#19049)

Steps to reproduce

When visual selection is reversed (the cursor is at the start of the selection) the getpos and setpos functions do not operate on the same visual mark.

The reproducer visually selects with the cursor at the left side of the selection. The first visual mark '< is modified with getpos() and setpos() by incrementing the column by 1. Then getpos() shows first visual mark unchanged, but the last visual mark '> has instead been updated.

vim -u NONE -S repro.txt

repro.txt

Expected behaviour

getpos() and setpos() should be consistent with the visual marks.

" Expected output:
" first visual mark before and after: [0, 1, 1, 0] -> [0, 1, 2, 0]
" last visual mark before and after:  [0, 1, 7, 0] -> [0, 1, 7, 0]

" Actual output:
" first visual mark before and after: [0, 1, 1, 0] -> [0, 1, 1, 0]
" last visual mark before and after:  [0, 1, 7, 0] -> [0, 1, 2, 0]

Version of Vim

9.1 Included patches: 1-16, 647, 678, 697

Environment

WSL ubuntu 24.04
windows terminal
xterm-256color
bash

Logs and stack traces


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/19049@github.com>

Christian Brabandt

unread,
5:18 AM (1 hour ago) 5:18 AM
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19049)

Pasting the script here for easier reproduction:

" invoke this script with "vim -u NONE -S repro.vim"

" setup
call append(0, "hello world")
call cursor(1,1)
execute "normal! vwo\<esc>"

" get positions of visual marks before modification
let first_visual_before = getpos("'<")
let last_visual_before = getpos("'>")

" modify the first visual mark's column, not changing the relative order
let pos = getpos("'<")
let pos[2] += 1
call setpos("'<", pos)

" get positions of visual marks after modification
let first_visual_after = getpos("'<")
let last_visual_after = getpos("'>")

echom "first visual mark before and after: " . string(first_visual_before) . " -> " . string(first_visual_after)
echom "last visual mark before and after:  " . string(last_visual_before)  . " -> " . string(last_visual_after)

" Expected output:
" first visual mark before and after: [0, 1, 1, 0] -> [0, 1, 2, 0]
" last visual mark before and after:  [0, 1, 7, 0] -> [0, 1, 7, 0]

" Actual output:
" first visual mark before and after: [0, 1, 1, 0] -> [0, 1, 1, 0]
" last visual mark before and after:  [0, 1, 7, 0] -> [0, 1, 2, 0]


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/19049/3701910971@github.com>

Reply all
Reply to author
Forward
0 new messages