写在前面
使用 vim 多年,意识到一个问题,vim 的 relativenumber 是从 0 开始索引的,而非 0,导致在当前行进行某些操作时,需要心里默默加一行,造成了不便,遂寻法解决。
编辑lazyvim
的ui
配置文件
打开.local/share/nvim/lazy/LazyVim/lua/lazyvim/util/ui.lua
文件
找到这一堆代码
-- Numbers in Neovim are weird
-- They show when either number or relativenumber is true
local is_num = vim.wo[win].number
local is_relnum = vim.wo[win].relativenumber
if (is_num or is_relnum) and vim.v.virtnum == 0 then
if vim.fn.has("nvim-0.11") == 1 then
components[2] = "%l" -- 0.11 handles both the current and other lines with %l
else
if vim.v.relnum == 0 then
components[2] = is_num and "%l" or "%r" -- the current line
else
-- components[2] = is_relnum and "%r" or "%l" -- other lines
components[2] = is_relnum and tostring(vim.v.relnum + 1) or "%l" -- other lines
end
end
components[2] = "%=" .. components[2] .. " " -- right align
end
修改
components[2] = is_relnum and "%r" or "%l" -- other lines
为
components[2] = is_relnum and tostring(vim.v.relnum + 1) or "%l" -- other lines
这里我选择注释掉原本的代码,然后添加新的代码。