nvim.d/neovim/lua/statusline.lua

68 lines
1.4 KiB
Lua

local M = {}
local function t(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
function _G.format_mode(mode)
local map_table = {
["n"] = "normal",
["no"] = "normal·operator pending",
["v"] = "visual",
["V"] = "visual(line)",
[t('<C-v>')] = "visual(block)",
["s"] = "select",
["S"] = "select(line)",
[t('<C-s>')] = "select(block)",
["i"] = "insert",
["R"] = "replace",
["Rv"] = "v·replace",
["c"] = "command",
["cv"] = "vim ex",
["ce"] = "ex",
["r"] = "prompt",
["rm"] = "more",
["r?"] = "confirm",
["!" ] = "shell",
["t"] = "terminal",
}
local output = map_table[mode]
if output == nil then
output = mode
end
return output
end
function M.output()
local separator = ""
local mode = "%{%v:lua.format_mode(v:lua.vim.fn.mode())%} "
local open_file = separator .. "%r%t %m"
local buf_nr = "[%n]"
local right_align = "%="
local file_format = "%{&ff}"
local file_type = "%y "
local encoding = "%{''.(&fenc!=''?&fenc:&enc).''} "
local line_no = "line: %03l/%03L "
local percentage = "[%3p%%]"
return string.format(
"%s%s%s%s%s%s%s%s%s%s%s%s",
separator,
mode,
open_file,
buf_nr,
right_align,
separator,
file_format,
file_type,
encoding,
separator,
line_no,
percentage
)
end
return M