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
$ 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
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.
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()
linebreak turned off.getregionpos() will accurately report the positions inside of the bounds defined by the two getpos() parameters, accounting for UI elements such as linebreak.
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Nov 15 2024 03:05:17) Included patches: 1-866 Compiled by Arch Linux
OS: Arch Linux
Kernel: Linux 6.12.4-arch1-1
Terminal: Wezterm
$TERM: wezterm
shell: zsh 5.9 (x86_64-pc-linux-gnu)
No response
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
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.![]()
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.![]()
I am not sure I understand.
:set linebreakchanges 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.![]()
Closed #16275 as completed.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()