Merge pull request #29322 from zeertzjq/vim-02f3ebacfbfa

vim-patch:02f3eba,d353d27
This commit is contained in:
zeertzjq 2024-06-14 05:10:38 +08:00 committed by GitHub
commit 6589d05894
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 177 additions and 180 deletions

119
runtime/doc/builtin.txt generated
View File

@ -701,33 +701,33 @@ clearmatches([{win}]) *clearmatches()*
col({expr} [, {winid}]) *col()* col({expr} [, {winid}]) *col()*
The result is a Number, which is the byte index of the column The result is a Number, which is the byte index of the column
position given with {expr}. The accepted positions are: position given with {expr}.
. the cursor position For accepted positions see |getpos()|.
$ the end of the cursor line (the result is the When {expr} is "$", it means the end of the cursor line, so
number of bytes in the cursor line plus one) the result is the number of bytes in the cursor line plus one.
'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.
Additionally {expr} can be [lnum, col]: a |List| with the line Additionally {expr} can be [lnum, col]: a |List| with the line
and column number. Most useful when the column is "$", to get and column number. Most useful when the column is "$", to get
the last column of a specific line. When "lnum" or "col" is the last column of a specific line. When "lnum" or "col" is
out of range then col() returns zero. out of range then col() returns zero.
With the optional {winid} argument the values are obtained for With the optional {winid} argument the values are obtained for
that window instead of the current window. that window instead of the current window.
To get the line number use |line()|. To get both use To get the line number use |line()|. To get both use
|getpos()|. |getpos()|.
For the screen column position use |virtcol()|. For the For the screen column position use |virtcol()|. For the
character position use |charcol()|. character position use |charcol()|.
Note that only marks in the current file can be used. Note that only marks in the current file can be used.
Examples: >vim Examples: >vim
echo col(".") " column of cursor echo col(".") " column of cursor
echo col("$") " length of cursor line plus one echo col("$") " length of cursor line plus one
echo col("'t") " column of mark t echo col("'t") " column of mark t
echo col("'" .. markname) " column of mark markname echo col("'" .. markname) " column of mark markname
< The first column is 1. Returns 0 if {expr} is invalid or when <
The first column is 1. Returns 0 if {expr} is invalid or when
the window with ID {winid} is not found. the window with ID {winid} is not found.
For an uppercase mark the column may actually be in another For an uppercase mark the column may actually be in another
buffer. buffer.
@ -2739,9 +2739,34 @@ getpid() *getpid()*
This is a unique number, until Vim exits. This is a unique number, until Vim exits.
getpos({expr}) *getpos()* getpos({expr}) *getpos()*
Get the position for String {expr}. For possible values of Get the position for String {expr}.
{expr} see |line()|. For getting the cursor position see The accepted values for {expr} are:
|getcurpos()|. . The cursor position.
$ The last line in the current buffer.
'x Position of mark x (if the mark is not set, 0 is
returned for all values).
w0 First line visible in current window (one if the
display isn't updated, e.g. in silent Ex mode).
w$ Last line visible in current window (this is one
less than "w0" if no lines are visible).
v When not in Visual mode, returns the cursor
position. In Visual mode, returns the other end
of the Visual area. A good way to think about
this is that in Visual mode "v" and "." complement
each other. While "." refers to the cursor
position, "v" refers to where |v_o| would move the
cursor. As a result, you can use "v" and "."
together to work on all of a selection in
characterwise Visual mode. If the cursor is at
the end of a characterwise Visual area, "v" refers
to the start of the same Visual area. And if the
cursor is at the start of a characterwise Visual
area, "v" refers to the end of the same Visual
area. "v" differs from |'<| and |'>| in that it's
updated right away.
Note that a mark in another file can be used. The line number
then applies to another buffer.
The result is a |List| with four numbers: The result is a |List| with four numbers:
[bufnum, lnum, col, off] [bufnum, lnum, col, off]
"bufnum" is zero, unless a mark like '0 or 'A is used, then it "bufnum" is zero, unless a mark like '0 or 'A is used, then it
@ -2752,20 +2777,25 @@ getpos({expr}) *getpos()*
it is the offset in screen columns from the start of the it is the offset in screen columns from the start of the
character. E.g., a position within a <Tab> or after the last character. E.g., a position within a <Tab> or after the last
character. character.
Note that for '< and '> Visual mode matters: when it is "V"
(visual line mode) the column of '< is zero and the column of For getting the cursor position see |getcurpos()|.
'> is a large number equal to |v:maxcol|.
The column number in the returned List is the byte position The column number in the returned List is the byte position
within the line. To get the character position in the line, within the line. To get the character position in the line,
use |getcharpos()|. use |getcharpos()|.
Note that for '< and '> Visual mode matters: when it is "V"
(visual line mode) the column of '< is zero and the column of
'> is a large number equal to |v:maxcol|.
A very large column number equal to |v:maxcol| can be returned, A very large column number equal to |v:maxcol| can be returned,
in which case it means "after the end of the line". in which case it means "after the end of the line".
If {expr} is invalid, returns a list with all zeros. If {expr} is invalid, returns a list with all zeros.
This can be used to save and restore the position of a mark: >vim This can be used to save and restore the position of a mark: >vim
let save_a_mark = getpos("'a") let save_a_mark = getpos("'a")
" ... " ...
call setpos("'a", save_a_mark) call setpos("'a", save_a_mark)
< Also see |getcharpos()|, |getcurpos()| and |setpos()|. <
Also see |getcharpos()|, |getcurpos()| and |setpos()|.
getqflist([{what}]) *getqflist()* getqflist([{what}]) *getqflist()*
Returns a |List| with all the current quickfix errors. Each Returns a |List| with all the current quickfix errors. Each
@ -4091,39 +4121,16 @@ libcallnr({libname}, {funcname}, {argument}) *libcallnr()*
< <
line({expr} [, {winid}]) *line()* line({expr} [, {winid}]) *line()*
The result is a Number, which is the line number of the file See |getpos()| for accepted positions.
position given with {expr}. The {expr} argument is a string.
The accepted positions are:
. the cursor position
$ the last line in the current buffer
'x position of mark x (if the mark is not set, 0 is
returned)
w0 first line visible in current window (one if the
display isn't updated, e.g. in silent Ex mode)
w$ last line visible in current window (this is one
less than "w0" if no lines are visible)
v When not in Visual mode, returns the cursor
position. In Visual mode, returns the other end
of the Visual area. A good way to think about
this is that in Visual mode "v" and "." complement
each other. While "." refers to the cursor
position, "v" refers to where |v_o| would move the
cursor. As a result, you can use "v" and "."
together to work on all of a selection in
characterwise visual mode. If the cursor is at
the end of a characterwise visual area, "v" refers
to the start of the same visual area. And if the
cursor is at the start of a characterwise visual
area, "v" refers to the end of the same visual
area. "v" differs from |'<| and |'>| in that it's
updated right away.
Note that a mark in another file can be used. The line number
then applies to another buffer.
To get the column number use |col()|. To get both use To get the column number use |col()|. To get both use
|getpos()|. |getpos()|.
With the optional {winid} argument the values are obtained for With the optional {winid} argument the values are obtained for
that window instead of the current window. that window instead of the current window.
Returns 0 for invalid values of {expr} and {winid}. Returns 0 for invalid values of {expr} and {winid}.
Examples: >vim Examples: >vim
echo line(".") " line number of the cursor echo line(".") " line number of the cursor
echo line(".", winid) " idem, in window "winid" echo line(".", winid) " idem, in window "winid"
@ -8746,7 +8753,9 @@ virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
set to 8, it returns 8. |conceal| is ignored. set to 8, it returns 8. |conceal| is ignored.
For the byte position use |col()|. For the byte position use |col()|.
For the use of {expr} see |col()|. For the use of {expr} see |getpos()| and |col()|.
When {expr} is "$", it means the end of the cursor line, so
the result is the number of cells in the cursor line plus one.
When 'virtualedit' is used {expr} can be [lnum, col, off], When 'virtualedit' is used {expr} can be [lnum, col, off],
where "off" is the offset in screen columns from the start of where "off" is the offset in screen columns from the start of
@ -8756,18 +8765,6 @@ virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
beyond the end of the line can be returned. Also see beyond the end of the line can be returned. Also see
|'virtualedit'| |'virtualedit'|
The accepted positions are:
. the cursor position
$ the end of the cursor line (the result is the
number of displayed characters in the cursor line
plus one)
'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.
If {list} is present and non-zero then virtcol() returns a If {list} is present and non-zero then virtcol() returns a
List with the first and last screen position occupied by the List with the first and last screen position occupied by the
character. character.
@ -8786,7 +8783,9 @@ virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
" With text " there", with 't at 'h': " With text " there", with 't at 'h':
echo virtcol("'t") " returns 6 echo virtcol("'t") " returns 6
< The first column is 1. 0 or [0, 0] is returned for an error. <
The first column is 1. 0 or [0, 0] is returned for an error.
A more advanced example that echoes the maximum length of A more advanced example that echoes the maximum length of
all lines: >vim all lines: >vim
echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))

View File

@ -911,33 +911,33 @@ function vim.fn.cindent(lnum) end
function vim.fn.clearmatches(win) end function vim.fn.clearmatches(win) end
--- The result is a Number, which is the byte index of the column --- The result is a Number, which is the byte index of the column
--- position given with {expr}. The accepted positions are: --- position given with {expr}.
--- . the cursor position --- For accepted positions see |getpos()|.
--- $ the end of the cursor line (the result is the --- When {expr} is "$", it means the end of the cursor line, so
--- number of bytes in the cursor line plus one) --- the result is the number of bytes in the cursor line plus one.
--- '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.
--- Additionally {expr} can be [lnum, col]: a |List| with the line --- Additionally {expr} can be [lnum, col]: a |List| with the line
--- and column number. Most useful when the column is "$", to get --- and column number. Most useful when the column is "$", to get
--- the last column of a specific line. When "lnum" or "col" is --- the last column of a specific line. When "lnum" or "col" is
--- out of range then col() returns zero. --- out of range then col() returns zero.
---
--- With the optional {winid} argument the values are obtained for --- With the optional {winid} argument the values are obtained for
--- that window instead of the current window. --- that window instead of the current window.
---
--- To get the line number use |line()|. To get both use --- To get the line number use |line()|. To get both use
--- |getpos()|. --- |getpos()|.
---
--- For the screen column position use |virtcol()|. For the --- For the screen column position use |virtcol()|. For the
--- character position use |charcol()|. --- character position use |charcol()|.
---
--- Note that only marks in the current file can be used. --- Note that only marks in the current file can be used.
---
--- Examples: >vim --- Examples: >vim
--- echo col(".") " column of cursor --- echo col(".") " column of cursor
--- echo col("$") " length of cursor line plus one --- echo col("$") " length of cursor line plus one
--- echo col("'t") " column of mark t --- echo col("'t") " column of mark t
--- echo col("'" .. markname) " column of mark markname --- echo col("'" .. markname) " column of mark markname
--- <The first column is 1. Returns 0 if {expr} is invalid or when --- <
--- The first column is 1. Returns 0 if {expr} is invalid or when
--- the window with ID {winid} is not found. --- the window with ID {winid} is not found.
--- For an uppercase mark the column may actually be in another --- For an uppercase mark the column may actually be in another
--- buffer. --- buffer.
@ -3329,9 +3329,34 @@ function vim.fn.getmousepos() end
--- @return integer --- @return integer
function vim.fn.getpid() end function vim.fn.getpid() end
--- Get the position for String {expr}. For possible values of --- Get the position for String {expr}.
--- {expr} see |line()|. For getting the cursor position see --- The accepted values for {expr} are:
--- |getcurpos()|. --- . The cursor position.
--- $ The last line in the current buffer.
--- 'x Position of mark x (if the mark is not set, 0 is
--- returned for all values).
--- w0 First line visible in current window (one if the
--- display isn't updated, e.g. in silent Ex mode).
--- w$ Last line visible in current window (this is one
--- less than "w0" if no lines are visible).
--- v When not in Visual mode, returns the cursor
--- position. In Visual mode, returns the other end
--- of the Visual area. A good way to think about
--- this is that in Visual mode "v" and "." complement
--- each other. While "." refers to the cursor
--- position, "v" refers to where |v_o| would move the
--- cursor. As a result, you can use "v" and "."
--- together to work on all of a selection in
--- characterwise Visual mode. If the cursor is at
--- the end of a characterwise Visual area, "v" refers
--- to the start of the same Visual area. And if the
--- cursor is at the start of a characterwise Visual
--- area, "v" refers to the end of the same Visual
--- area. "v" differs from |'<| and |'>| in that it's
--- updated right away.
--- Note that a mark in another file can be used. The line number
--- then applies to another buffer.
---
--- The result is a |List| with four numbers: --- The result is a |List| with four numbers:
--- [bufnum, lnum, col, off] --- [bufnum, lnum, col, off]
--- "bufnum" is zero, unless a mark like '0 or 'A is used, then it --- "bufnum" is zero, unless a mark like '0 or 'A is used, then it
@ -3342,20 +3367,25 @@ function vim.fn.getpid() end
--- it is the offset in screen columns from the start of the --- it is the offset in screen columns from the start of the
--- character. E.g., a position within a <Tab> or after the last --- character. E.g., a position within a <Tab> or after the last
--- character. --- character.
--- Note that for '< and '> Visual mode matters: when it is "V" ---
--- (visual line mode) the column of '< is zero and the column of --- For getting the cursor position see |getcurpos()|.
--- '> is a large number equal to |v:maxcol|.
--- The column number in the returned List is the byte position --- The column number in the returned List is the byte position
--- within the line. To get the character position in the line, --- within the line. To get the character position in the line,
--- use |getcharpos()|. --- use |getcharpos()|.
---
--- Note that for '< and '> Visual mode matters: when it is "V"
--- (visual line mode) the column of '< is zero and the column of
--- '> is a large number equal to |v:maxcol|.
--- A very large column number equal to |v:maxcol| can be returned, --- A very large column number equal to |v:maxcol| can be returned,
--- in which case it means "after the end of the line". --- in which case it means "after the end of the line".
--- If {expr} is invalid, returns a list with all zeros. --- If {expr} is invalid, returns a list with all zeros.
---
--- This can be used to save and restore the position of a mark: >vim --- This can be used to save and restore the position of a mark: >vim
--- let save_a_mark = getpos("'a") --- let save_a_mark = getpos("'a")
--- " ... --- " ...
--- call setpos("'a", save_a_mark) --- call setpos("'a", save_a_mark)
--- <Also see |getcharpos()|, |getcurpos()| and |setpos()|. --- <
--- Also see |getcharpos()|, |getcurpos()| and |setpos()|.
--- ---
--- @param expr string --- @param expr string
--- @return integer[] --- @return integer[]
@ -4960,39 +4990,16 @@ function vim.fn.libcall(libname, funcname, argument) end
--- @return any --- @return any
function vim.fn.libcallnr(libname, funcname, argument) end function vim.fn.libcallnr(libname, funcname, argument) end
--- The result is a Number, which is the line number of the file --- See |getpos()| for accepted positions.
--- position given with {expr}. The {expr} argument is a string. ---
--- The accepted positions are:
--- . the cursor position
--- $ the last line in the current buffer
--- 'x position of mark x (if the mark is not set, 0 is
--- returned)
--- w0 first line visible in current window (one if the
--- display isn't updated, e.g. in silent Ex mode)
--- w$ last line visible in current window (this is one
--- less than "w0" if no lines are visible)
--- v When not in Visual mode, returns the cursor
--- position. In Visual mode, returns the other end
--- of the Visual area. A good way to think about
--- this is that in Visual mode "v" and "." complement
--- each other. While "." refers to the cursor
--- position, "v" refers to where |v_o| would move the
--- cursor. As a result, you can use "v" and "."
--- together to work on all of a selection in
--- characterwise visual mode. If the cursor is at
--- the end of a characterwise visual area, "v" refers
--- to the start of the same visual area. And if the
--- cursor is at the start of a characterwise visual
--- area, "v" refers to the end of the same visual
--- area. "v" differs from |'<| and |'>| in that it's
--- updated right away.
--- Note that a mark in another file can be used. The line number
--- then applies to another buffer.
--- To get the column number use |col()|. To get both use --- To get the column number use |col()|. To get both use
--- |getpos()|. --- |getpos()|.
---
--- With the optional {winid} argument the values are obtained for --- With the optional {winid} argument the values are obtained for
--- that window instead of the current window. --- that window instead of the current window.
---
--- Returns 0 for invalid values of {expr} and {winid}. --- Returns 0 for invalid values of {expr} and {winid}.
---
--- Examples: >vim --- Examples: >vim
--- echo line(".") " line number of the cursor --- echo line(".") " line number of the cursor
--- echo line(".", winid) " idem, in window "winid" --- echo line(".", winid) " idem, in window "winid"
@ -10410,7 +10417,9 @@ function vim.fn.values(dict) end
--- set to 8, it returns 8. |conceal| is ignored. --- set to 8, it returns 8. |conceal| is ignored.
--- For the byte position use |col()|. --- For the byte position use |col()|.
--- ---
--- For the use of {expr} see |col()|. --- For the use of {expr} see |getpos()| and |col()|.
--- When {expr} is "$", it means the end of the cursor line, so
--- the result is the number of cells in the cursor line plus one.
--- ---
--- When 'virtualedit' is used {expr} can be [lnum, col, off], --- When 'virtualedit' is used {expr} can be [lnum, col, off],
--- where "off" is the offset in screen columns from the start of --- where "off" is the offset in screen columns from the start of
@ -10420,18 +10429,6 @@ function vim.fn.values(dict) end
--- beyond the end of the line can be returned. Also see --- beyond the end of the line can be returned. Also see
--- |'virtualedit'| --- |'virtualedit'|
--- ---
--- The accepted positions are:
--- . the cursor position
--- $ the end of the cursor line (the result is the
--- number of displayed characters in the cursor line
--- plus one)
--- '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.
---
--- If {list} is present and non-zero then virtcol() returns a --- If {list} is present and non-zero then virtcol() returns a
--- List with the first and last screen position occupied by the --- List with the first and last screen position occupied by the
--- character. --- character.
@ -10450,7 +10447,9 @@ function vim.fn.values(dict) end
--- " With text " there", with 't at 'h': --- " With text " there", with 't at 'h':
--- ---
--- echo virtcol("'t") " returns 6 --- echo virtcol("'t") " returns 6
--- <The first column is 1. 0 or [0, 0] is returned for an error. --- <
--- The first column is 1. 0 or [0, 0] is returned for an error.
---
--- A more advanced example that echoes the maximum length of --- A more advanced example that echoes the maximum length of
--- all lines: >vim --- all lines: >vim
--- echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) --- echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))

View File

@ -1238,33 +1238,33 @@ M.funcs = {
base = 1, base = 1,
desc = [=[ desc = [=[
The result is a Number, which is the byte index of the column The result is a Number, which is the byte index of the column
position given with {expr}. The accepted positions are: position given with {expr}.
. the cursor position For accepted positions see |getpos()|.
$ the end of the cursor line (the result is the When {expr} is "$", it means the end of the cursor line, so
number of bytes in the cursor line plus one) the result is the number of bytes in the cursor line plus one.
'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.
Additionally {expr} can be [lnum, col]: a |List| with the line Additionally {expr} can be [lnum, col]: a |List| with the line
and column number. Most useful when the column is "$", to get and column number. Most useful when the column is "$", to get
the last column of a specific line. When "lnum" or "col" is the last column of a specific line. When "lnum" or "col" is
out of range then col() returns zero. out of range then col() returns zero.
With the optional {winid} argument the values are obtained for With the optional {winid} argument the values are obtained for
that window instead of the current window. that window instead of the current window.
To get the line number use |line()|. To get both use To get the line number use |line()|. To get both use
|getpos()|. |getpos()|.
For the screen column position use |virtcol()|. For the For the screen column position use |virtcol()|. For the
character position use |charcol()|. character position use |charcol()|.
Note that only marks in the current file can be used. Note that only marks in the current file can be used.
Examples: >vim Examples: >vim
echo col(".") " column of cursor echo col(".") " column of cursor
echo col("$") " length of cursor line plus one echo col("$") " length of cursor line plus one
echo col("'t") " column of mark t echo col("'t") " column of mark t
echo col("'" .. markname) " column of mark markname echo col("'" .. markname) " column of mark markname
<The first column is 1. Returns 0 if {expr} is invalid or when <
The first column is 1. Returns 0 if {expr} is invalid or when
the window with ID {winid} is not found. the window with ID {winid} is not found.
For an uppercase mark the column may actually be in another For an uppercase mark the column may actually be in another
buffer. buffer.
@ -4141,9 +4141,34 @@ M.funcs = {
args = 1, args = 1,
base = 1, base = 1,
desc = [=[ desc = [=[
Get the position for String {expr}. For possible values of Get the position for String {expr}.
{expr} see |line()|. For getting the cursor position see The accepted values for {expr} are:
|getcurpos()|. . The cursor position.
$ The last line in the current buffer.
'x Position of mark x (if the mark is not set, 0 is
returned for all values).
w0 First line visible in current window (one if the
display isn't updated, e.g. in silent Ex mode).
w$ Last line visible in current window (this is one
less than "w0" if no lines are visible).
v When not in Visual mode, returns the cursor
position. In Visual mode, returns the other end
of the Visual area. A good way to think about
this is that in Visual mode "v" and "." complement
each other. While "." refers to the cursor
position, "v" refers to where |v_o| would move the
cursor. As a result, you can use "v" and "."
together to work on all of a selection in
characterwise Visual mode. If the cursor is at
the end of a characterwise Visual area, "v" refers
to the start of the same Visual area. And if the
cursor is at the start of a characterwise Visual
area, "v" refers to the end of the same Visual
area. "v" differs from |'<| and |'>| in that it's
updated right away.
Note that a mark in another file can be used. The line number
then applies to another buffer.
The result is a |List| with four numbers: The result is a |List| with four numbers:
[bufnum, lnum, col, off] [bufnum, lnum, col, off]
"bufnum" is zero, unless a mark like '0 or 'A is used, then it "bufnum" is zero, unless a mark like '0 or 'A is used, then it
@ -4154,20 +4179,25 @@ M.funcs = {
it is the offset in screen columns from the start of the it is the offset in screen columns from the start of the
character. E.g., a position within a <Tab> or after the last character. E.g., a position within a <Tab> or after the last
character. character.
Note that for '< and '> Visual mode matters: when it is "V"
(visual line mode) the column of '< is zero and the column of For getting the cursor position see |getcurpos()|.
'> is a large number equal to |v:maxcol|.
The column number in the returned List is the byte position The column number in the returned List is the byte position
within the line. To get the character position in the line, within the line. To get the character position in the line,
use |getcharpos()|. use |getcharpos()|.
Note that for '< and '> Visual mode matters: when it is "V"
(visual line mode) the column of '< is zero and the column of
'> is a large number equal to |v:maxcol|.
A very large column number equal to |v:maxcol| can be returned, A very large column number equal to |v:maxcol| can be returned,
in which case it means "after the end of the line". in which case it means "after the end of the line".
If {expr} is invalid, returns a list with all zeros. If {expr} is invalid, returns a list with all zeros.
This can be used to save and restore the position of a mark: >vim This can be used to save and restore the position of a mark: >vim
let save_a_mark = getpos("'a") let save_a_mark = getpos("'a")
" ... " ...
call setpos("'a", save_a_mark) call setpos("'a", save_a_mark)
<Also see |getcharpos()|, |getcurpos()| and |setpos()|. <
Also see |getcharpos()|, |getcurpos()| and |setpos()|.
]=], ]=],
name = 'getpos', name = 'getpos',
@ -6070,39 +6100,16 @@ M.funcs = {
args = { 1, 2 }, args = { 1, 2 },
base = 1, base = 1,
desc = [=[ desc = [=[
The result is a Number, which is the line number of the file See |getpos()| for accepted positions.
position given with {expr}. The {expr} argument is a string.
The accepted positions are:
. the cursor position
$ the last line in the current buffer
'x position of mark x (if the mark is not set, 0 is
returned)
w0 first line visible in current window (one if the
display isn't updated, e.g. in silent Ex mode)
w$ last line visible in current window (this is one
less than "w0" if no lines are visible)
v When not in Visual mode, returns the cursor
position. In Visual mode, returns the other end
of the Visual area. A good way to think about
this is that in Visual mode "v" and "." complement
each other. While "." refers to the cursor
position, "v" refers to where |v_o| would move the
cursor. As a result, you can use "v" and "."
together to work on all of a selection in
characterwise visual mode. If the cursor is at
the end of a characterwise visual area, "v" refers
to the start of the same visual area. And if the
cursor is at the start of a characterwise visual
area, "v" refers to the end of the same visual
area. "v" differs from |'<| and |'>| in that it's
updated right away.
Note that a mark in another file can be used. The line number
then applies to another buffer.
To get the column number use |col()|. To get both use To get the column number use |col()|. To get both use
|getpos()|. |getpos()|.
With the optional {winid} argument the values are obtained for With the optional {winid} argument the values are obtained for
that window instead of the current window. that window instead of the current window.
Returns 0 for invalid values of {expr} and {winid}. Returns 0 for invalid values of {expr} and {winid}.
Examples: >vim Examples: >vim
echo line(".") " line number of the cursor echo line(".") " line number of the cursor
echo line(".", winid) " idem, in window "winid" echo line(".", winid) " idem, in window "winid"
@ -12459,7 +12466,9 @@ M.funcs = {
set to 8, it returns 8. |conceal| is ignored. set to 8, it returns 8. |conceal| is ignored.
For the byte position use |col()|. For the byte position use |col()|.
For the use of {expr} see |col()|. For the use of {expr} see |getpos()| and |col()|.
When {expr} is "$", it means the end of the cursor line, so
the result is the number of cells in the cursor line plus one.
When 'virtualedit' is used {expr} can be [lnum, col, off], When 'virtualedit' is used {expr} can be [lnum, col, off],
where "off" is the offset in screen columns from the start of where "off" is the offset in screen columns from the start of
@ -12469,18 +12478,6 @@ M.funcs = {
beyond the end of the line can be returned. Also see beyond the end of the line can be returned. Also see
|'virtualedit'| |'virtualedit'|
The accepted positions are:
. the cursor position
$ the end of the cursor line (the result is the
number of displayed characters in the cursor line
plus one)
'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.
If {list} is present and non-zero then virtcol() returns a If {list} is present and non-zero then virtcol() returns a
List with the first and last screen position occupied by the List with the first and last screen position occupied by the
character. character.
@ -12499,7 +12496,9 @@ M.funcs = {
" With text " there", with 't at 'h': " With text " there", with 't at 'h':
echo virtcol("'t") " returns 6 echo virtcol("'t") " returns 6
<The first column is 1. 0 or [0, 0] is returned for an error. <
The first column is 1. 0 or [0, 0] is returned for an error.
A more advanced example that echoes the maximum length of A more advanced example that echoes the maximum length of
all lines: >vim all lines: >vim
echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))