feat nvim: 新增編輯選取時的計數

This commit is contained in:
Yuan Chiu 2025-04-30 11:40:00 +08:00
parent d8768c6363
commit e8071d5545

View File

@ -6,6 +6,24 @@ return {
dependencies = { 'nvim-tree/nvim-web-devicons' }, dependencies = { 'nvim-tree/nvim-web-devicons' },
event = "VeryLazy", event = "VeryLazy",
opts = function() opts = function()
-- 選擇計數格式
local function selectionCount()
local mode = vim.fn.mode()
if not mode:find("[Vv]") then return "" end -- 僅在 Visual 模式下顯示
local starts = vim.fn.line("v")
local ends = vim.fn.line(".")
local lines = math.abs(ends - starts) + 1
local chars = vim.fn.wordcount().visual_chars or 0
return string.format("📏 %dL %dC", lines, chars)
end
-- 自定義 location 格式
local function customLocation()
local location = vim.api.nvim_eval_statusline("%l:%c", {}).str -- 獲取行和列
return "📍 " .. location -- 在字首添加 emoji
end
return { return {
options = { options = {
icons_enabled = true, icons_enabled = true,
@ -32,13 +50,13 @@ return {
lualine_c = {'filename'}, lualine_c = {'filename'},
lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'}, lualine_y = {'progress'},
lualine_z = {'location'} lualine_z = {{ selectionCount }, { customLocation },}
}, },
inactive_sections = { inactive_sections = {
lualine_a = {}, lualine_a = {},
lualine_b = {}, lualine_b = {},
lualine_c = {'filename'}, lualine_c = {'filename'},
lualine_x = {'location'}, lualine_x = {{ customLocation }},
lualine_y = {}, lualine_y = {},
lualine_z = {} lualine_z = {}
}, },