[vim/vim] `set linebreak` changes the results of `getregionpos()` for wrapped lines (Issue #16275)

13 views
Skip to first unread message

mcauley-penney

unread,
Dec 21, 2024, 1:48:25 PM12/21/24
to vim/vim, Subscribed

Steps to reproduce

  1. Open vim with the below config. This config affords reporting the output of getregionpos() on entering charwise, linewise, and blockwise visual, and affords reporting getpos('.') on mp.
set noshowmode
set linebreak

nnoremap <expr> k v:count == 0 ? 'gk' : 'k'
vnoremap <expr> k v:count == 0 ? 'gk' : 'k'
nnoremap <expr> j v:count == 0 ? 'gj' : 'j'
vnoremap <expr> j v:count == 0 ? 'gj' : 'j'

" getregionpos
nnoremap mp :echo getpos('.')<CR>

function! ReportGetRegionPos()
  let l:options = { 'type': mode(), 'eol': 1 }
  let l:pos = getregionpos(getpos('v'), getpos('.'), options)

  echom "== getregionpos() results =="
  echom l:pos
endfunction

augroup ReportGetRegionPos
  autocmd!

  autocmd ModeChanged *:[vV\x16] if &operatorfunc ==# '' |
      \ call ReportGetRegionPos() |
      \ endif

  autocmd CursorMoved * if mode() ==# 'v' || mode() ==# 'V' || mode() ==# "\<C-V>" |
      \ call ReportGetRegionPos() |
      \ endif

augroup END 
  1. Create a text file with a wrapped line:

$ echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus efficitur, erat nec sollicitudin malesuada, quam nibh commodo nisl, at volutpat sapien odio vel velit. Phasellus aliquet odio id consequat hendrerit. Duis interdum lobortis lacus, at fringilla mauris mattis sed. Cras convallis dignissim lacus, eu gravida enim euismod sed. Integer venenatis at urna id imperdiet. Pellentesque quis lectus porta, fringilla est non, placerat purus. Etiam fringilla viverra lacinia. Aliquam erat volutpat. Duis libero urna, tempor non pretium sit amet, viverra quis eros. Pellentesque et ultrices risus, vel aliquet est. Donec non congue justo." > getregionpos.txt

  1. Enter the text file and pick a position to test with. Use mp to get the column value at that position.

For example, at the space at the front of the sentence " Aliquam erat volutpat." you should get the below output.

image.png (view on web)

  1. Move one screen line above the position you tested, enter blockwise visual mode, and move down one screen line to the spot you tested before.

https://github.com/user-attachments/assets/3970c77c-5653-4cc2-a3b0-94ee4f3bd8c8

In this example, you can see that the end column reported by getposregion() is 503, where getpos('.') reports 480, even though this is the end position given as a parameter to getposregion()

  1. Repeat steps 3 and 4 with linebreak turned off.

Expected behaviour

getregionpos() will accurately report the positions inside of the bounds defined by the two getpos() parameters, accounting for UI elements such as linebreak.

Version of Vim

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Nov 15 2024 03:05:17) Included patches: 1-866 Compiled by Arch Linux

Environment

OS: Arch Linux
Kernel: Linux 6.12.4-arch1-1
Terminal: Wezterm
$TERM: wezterm
shell: zsh 5.9 (x86_64-pc-linux-gnu)

Logs and stack traces

No response


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/16275@github.com>

Christian Brabandt

unread,
Dec 22, 2024, 4:50:32 AM12/22/24
to vim/vim, Subscribed

I am not sure I understand. :set linebreak changes the wrapping, and it is expected that the position changes, since the text is on a different position.


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/16275/2558397044@github.com>

zeertzjq

unread,
Dec 22, 2024, 8:03:01 AM12/22/24
to vim/vim, Subscribed

This seems to happen because block_prep() resets 'linebreak' while calculating virtual columns:

#ifdef FEAT_LINEBREAK
		// Avoid a problem with unwanted linebreaks in block mode.
    int		lbr_saved = reset_lbr();
#endif

while getregionpos() doesn't:

	getvvcol(curwin, p1, &sc1, NULL, &ec1);
	getvvcol(curwin, p2, &sc2, NULL, &ec2);


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/16275/2558449226@github.com>

mcauley-penney

unread,
Dec 22, 2024, 10:36:20 AM12/22/24
to vim/vim, Subscribed

I am not sure I understand. :set linebreak changes the wrapping, and it is expected that the position changes, since the text is on a different position.

I think the real problem is that the two sources of information are different, not that they change. I agree that it makes sense for the values to change given line breaks, but they should report the same values under the same conditions.


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/16275/2558495110@github.com>

mcauley-penney

unread,
Dec 23, 2025, 11:27:24 PM (7 hours ago) Dec 23
to vim/vim, Subscribed

Closed #16275 as completed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/16275/issue_event/21736138028@github.com>

Reply all
Reply to author
Forward
0 new messages