docs: vim.pos

This commit is contained in:
Justin M. Keyes
2026-04-09 17:42:29 +02:00
parent a321c9adad
commit 30a80cbd7c
3 changed files with 12 additions and 12 deletions

View File

@@ -4270,8 +4270,8 @@ by |vim.Pos| objects.
To create a new |vim.Pos| object, call `vim.pos()`.
Example: >lua
local pos1 = vim.pos(3, 5)
local pos2 = vim.pos(4, 0)
local pos1 = vim.pos(vim.api.nvim_get_current_buf(), 3, 5)
local pos2 = vim.pos(vim.api.nvim_get_current_buf(), 4, 0)
-- Operators are overloaded for comparing two `vim.Pos` objects.
if pos1 < pos2 then
@@ -4320,7 +4320,7 @@ Pos:to_lsp({position_encoding}) *Pos:to_lsp()*
local pos = vim.pos(buf, 3, 5)
-- Convert to LSP position, you can call it in a method style.
local lsp_pos = pos:lsp('utf-16')
local lsp_pos = pos:to_lsp('utf-16')
<
Parameters: ~
@@ -4390,13 +4390,13 @@ Provides operations to compare, calculate, and convert ranges represented by
format conversions.
Example: >lua
local pos1 = vim.pos(3, 5)
local pos2 = vim.pos(4, 0)
local pos1 = vim.pos(vim.api.nvim_get_current_buf(), 3, 5)
local pos2 = vim.pos(vim.api.nvim_get_current_buf(), 4, 0)
-- Create a range from two positions.
local range1 = vim.range(pos1, pos2)
-- Or create a range from four integers representing start and end positions.
local range2 = vim.range(3, 5, 4, 0)
local range2 = vim.range(vim.api.nvim_get_current_buf(), 3, 5, 4, 0)
-- Because `vim.Range` is end exclusive, `range1` and `range2` both represent
-- a range starting at the row 3, column 5 and ending at where the row 3 ends

View File

@@ -18,8 +18,8 @@ local validate = vim.validate
---
--- Example:
--- ```lua
--- local pos1 = vim.pos(3, 5)
--- local pos2 = vim.pos(4, 0)
--- local pos1 = vim.pos(vim.api.nvim_get_current_buf(), 3, 5)
--- local pos2 = vim.pos(vim.api.nvim_get_current_buf(), 4, 0)
---
--- -- Operators are overloaded for comparing two `vim.Pos` objects.
--- if pos1 < pos2 then
@@ -127,7 +127,7 @@ end
--- local pos = vim.pos(buf, 3, 5)
---
--- -- Convert to LSP position, you can call it in a method style.
--- local lsp_pos = pos:lsp('utf-16')
--- local lsp_pos = pos:to_lsp('utf-16')
--- ```
---@param position_encoding lsp.PositionEncodingKind
function Pos:to_lsp(position_encoding)

View File

@@ -20,13 +20,13 @@ local api = vim.api
---
--- Example:
--- ```lua
--- local pos1 = vim.pos(3, 5)
--- local pos2 = vim.pos(4, 0)
--- local pos1 = vim.pos(vim.api.nvim_get_current_buf(), 3, 5)
--- local pos2 = vim.pos(vim.api.nvim_get_current_buf(), 4, 0)
---
--- -- Create a range from two positions.
--- local range1 = vim.range(pos1, pos2)
--- -- Or create a range from four integers representing start and end positions.
--- local range2 = vim.range(3, 5, 4, 0)
--- local range2 = vim.range(vim.api.nvim_get_current_buf(), 3, 5, 4, 0)
---
--- -- Because `vim.Range` is end exclusive, `range1` and `range2` both represent
--- -- a range starting at the row 3, column 5 and ending at where the row 3 ends