diff options
| author | Yi Ming <ofseed@foxmail.com> | 2026-06-02 20:06:08 +0800 |
|---|---|---|
| committer | Yi Ming <ofseed@foxmail.com> | 2026-06-08 19:52:51 +0800 |
| commit | 2bd13177b83a158f2e8a00e7aeac5ffe793e0923 (patch) | |
| tree | c40c4fdffbffff6da44aec0d2d6286d7046c1076 /runtime/doc/lua.txt | |
| parent | 3f37b230af914906084fd21d1c630ecf3fb30862 (diff) | |
| download | rneovim-2bd13177b83a158f2e8a00e7aeac5ffe793e0923.tar.gz rneovim-2bd13177b83a158f2e8a00e7aeac5ffe793e0923.tar.bz2 rneovim-2bd13177b83a158f2e8a00e7aeac5ffe793e0923.zip | |
feat(pos): create a cursor position by using the current of a window
Problem:
`vim.pos.cursor(vim.api.nvim_get_current_buf(win), vim.api.nvim_win_get_cursor(win))`
is too verbose to create a cursor position of a window,
but it is a common use case.
Solution:
Overload `vim.pos.cursor()`, so that it accepts `win` as an argument when `pos` is omitted.
Diffstat (limited to 'runtime/doc/lua.txt')
| -rw-r--r-- | runtime/doc/lua.txt | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 6effa6e7c3..c983c5798a 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -4503,15 +4503,24 @@ by |vim.Pos| objects. cursor({buf}, {pos}) *vim.pos.cursor()* Creates a new |vim.Pos| from cursor position (see |api-indexing|). + If {pos} is omitted, the first argument is treated as {win} instead of + {buf}, and the current cursor position of {win} is used. + Example: >lua + local buf = vim.api.nvim_win_get_buf(0) local cursor_pos = vim.api.nvim_win_get_cursor(0) - local pos = vim.pos.cursor(0, cursor_pos) + local pos = vim.pos.cursor(buf, cursor_pos) + -- This is equivalent: + local pos = vim.pos.cursor(0) < Parameters: ~ • {buf} (`integer`) • {pos} (`[integer, integer]`) (lnum, col) tuple + Overloads: ~ + • `fun(win: integer): vim.Pos` + Return: ~ (`vim.Pos`) See |vim.Pos|. |