[英]How to store the current buffer filename with cursor position to register using neovim Lua API?
In vim I can use getcurpos()
and expand('%:t')
, but how does this work in lua?在 vim 中,我可以使用
getcurpos()
和expand('%:t')
,但这在 lua 中如何工作? The solution should ideally only use the neovim api.理想情况下,该解决方案应仅使用 neovim api。
Without the neovim api:没有neovim api:
function Fcolumn_noplenary()
local fname = vim.fn.expand('%:t')
local line_col_pair = vim.api.nvim_win_get_cursor(0) -- row is 1, column is 0 indexed
local fnamecol = fname .. ':' .. tostring(line_col_pair[1]) .. ':' .. tostring(line_col_pair[2])
vim.fn.setreg('+', fnamecol) -- register + has filename:row:column
end
function Fcolumn_plenary()
local Path = require "plenary.path"
local path = Path.path
local fileAbs = vim.api.nvim_buf_get_name(0)
local p = Path:new fileAbs
local fname = p.filename
local line_col_pair = vim.api.nvim_win_get_cursor(0) -- row is 1, column is 0 indexed
local fnamecol = fname .. ':' .. tostring(line_col_pair[1]) .. ':' .. tostring(line_col_pair[2])
vim.fn.setreg('+', fnamecol) -- register + has filename:row:column
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.