vim-patch:8.2.5019: cannot get the first screen column of a character (#23312)

Problem:    Cannot get the first screen column of a character.
Solution:   Let virtcol() optionally return a list. (closes vim/vim#10482,
            closes vim/vim#7964)

0f7a3e1de6

Co-authored-by: LemonBoy <thatlemon@gmail.com>
This commit is contained in:
zeertzjq
2023-04-25 22:22:26 +08:00
committed by GitHub
parent 43c49746d9
commit bfa92d3861
4 changed files with 53 additions and 17 deletions

View File

@@ -546,7 +546,8 @@ undotree() List undo file tree
uniq({list} [, {func} [, {dict}]])
List remove adjacent duplicates from a list
values({dict}) List values in {dict}
virtcol({expr}) Number screen column of cursor or mark
virtcol({expr} [, {list}]) Number or List
screen column of cursor or mark
virtcol2col({winid}, {lnum}, {col})
Number byte index of a character on screen
visualmode([expr]) String last visual mode used
@@ -637,6 +638,7 @@ add({object}, {expr}) *add()*
and({expr}, {expr}) *and()*
Bitwise AND on the two arguments. The arguments are converted
to a number. A List, Dict or Float argument causes an error.
Also see `or()` and `xor()`.
Example: >
:let flag = and(bits, 0x80)
< Can also be used as a |method|: >
@@ -9070,7 +9072,7 @@ values({dict}) *values()*
Can also be used as a |method|: >
mydict->values()
virtcol({expr}) *virtcol()*
virtcol({expr} [, {list}]) *virtcol()*
The result is a Number, which is the screen column of the file
position given with {expr}. That is, the last screen position
occupied by the character at that position, when the screen
@@ -9079,13 +9081,17 @@ virtcol({expr}) *virtcol()*
the <Tab>. For example, for a <Tab> in column 1, with 'ts'
set to 8, it returns 8. |conceal| is ignored.
For the byte position use |col()|.
For the use of {expr} see |col()|.
When 'virtualedit' is used {expr} can be [lnum, col, off], where
"off" is the offset in screen columns from the start of the
character. E.g., a position within a <Tab> or after the last
character. When "off" is omitted zero is used.
When Virtual editing is active in the current mode, a position
beyond the end of the line can be returned. |'virtualedit'|
When 'virtualedit' is used {expr} can be [lnum, col, off],
where "off" is the offset in screen columns from the start of
the character. E.g., a position within a <Tab> or after the
last character. When "off" is omitted zero is used. When
Virtual editing is active in the current mode, a position
beyond the end of the line can be returned. Also see
|'virtualedit'|
The accepted positions are:
. the cursor position
$ the end of the cursor line (the result is the
@@ -9097,11 +9103,22 @@ virtcol({expr}) *virtcol()*
cursor is the end). When not in Visual mode
returns the cursor position. Differs from |'<| in
that it's updated right away.
If {list} is present and non-zero then virtcol() returns a List
with the first and last screen position occupied by the
character.
Note that only marks in the current file can be used.
Examples: >
virtcol(".") with text "foo^Lbar", with cursor on the "^L", returns 5
virtcol("$") with text "foo^Lbar", returns 9
virtcol("'t") with text " there", with 't at 'h', returns 6
" With text "foo^Lbar" and cursor on the "^L":
virtcol(".") " returns 5
virtcol(".", 1) " returns [4, 5]
virtcol("$") " returns 9
" With text " there", with 't at 'h':
virtcol("'t") " returns 6
< The first column is 1. 0 is returned for an error.
A more advanced example that echoes the maximum length of
all lines: >