A very fast neovim config :D
at master 152 lines 4.9 kB view raw
1local modes = { 2 ["n"] = { "NORMAL", "ColorColumn" }, 3 ["niI"] = { "NORMAL i", "ColorColumn" }, 4 ["niR"] = { "NORMAL r", "ColorColumn" }, 5 ["niV"] = { "NORMAL v", "ColorColumn" }, 6 ["no"] = { "N-PENDING", "ColorColumn" }, 7 ["i"] = { "INSERT", "StatusInsert" }, 8 ["ic"] = { "INSERT (completion)", "StatusInsert" }, 9 ["ix"] = { "INSERT completion", "StatusInsert" }, 10 ["t"] = { "TERMINAL", "StatusTerminal" }, 11 ["nt"] = { "NTERMINAL", "StatusTerminal" }, 12 ["v"] = { "VISUAL", "StatusVisual" }, 13 ["V"] = { "V-LINE", "StatusVisual" }, 14 ["Vs"] = { "V-LINE (Ctrl O)", "StatusVisual" }, 15 [""] = { "V-BLOCK", "StatusVisual" }, 16 ["R"] = { "REPLACE", "StatusReplace" }, 17 ["Rv"] = { "V-REPLACE", "StatusReplace" }, 18 ["s"] = { "SELECT", "StatusVisual" }, 19 ["S"] = { "S-LINE", "StatusVisual" }, 20 [""] = { "S-BLOCK", "StatusVisual" }, 21 ["c"] = { "COMMAND", "StatusCommand" }, 22 ["cv"] = { "COMMAND", "StatusCommand" }, 23 ["ce"] = { "COMMAND", "StatusCommand" }, 24 ["r"] = { "PROMPT", "StatusVisual" }, 25 ["rm"] = { "MORE", "StatusVisual" }, 26 ["r?"] = { "CONFIRM", "StatusVisual" }, 27 ["!"] = { "SHELL", "StatusTerminal" }, 28} 29 30local function current_mode() 31 local mode = vim.api.nvim_get_mode().mode 32 return "%#Normal#" .. " " .. "%#" .. modes[mode][2] .. "#" .. " " .. modes[mode][1] .. " " .. "%#NormalNC#" 33end 34 35local function get_current_file_name() 36 local file = vim.fn.expand("%:t") 37 if vim.fn.empty(file) == 1 then 38 return "" 39 end 40 return "%#Normal#" .. " " .. file .. " " .. "%#NormalNC#" 41end 42 43local function git_branch() 44 -- Safely check if gitsigns status is available 45 local git_status = vim.b.gitsigns_status_dict 46 if not git_status or not git_status.head or git_status.head == "" then 47 return "" 48 end 49 50 local branch_name = "(λ • " .. git_status.head .. ")" 51 return "%#Normal#" .. branch_name .. "%#NormalNC#" 52end 53 54local function git_diff() 55 -- Safely check if gitsigns status is available 56 local git_status = vim.b.gitsigns_status_dict 57 if not git_status then 58 return "" 59 end 60 61 local added, changed, removed = "", "", "" 62 63 if git_status.added and git_status.added > 0 then 64 added = "%#DiagnosticSignInfo#" .. " +" .. git_status.added 65 end 66 67 if git_status.changed and git_status.changed > 0 then 68 changed = "%#DiagnosticSignWarn#" .. " ~" .. git_status.changed 69 end 70 71 if git_status.removed and git_status.removed > 0 then 72 removed = "%#DiagnosticSignError#" .. " -" .. git_status.removed 73 end 74 75 if added ~= "" or changed ~= "" or removed ~= "" then 76 return "%#Normal#" .. added .. changed .. removed .. "%#NormalNC#" .. " " 77 else 78 return " " 79 end 80end 81 82local function macro_status() 83 local rec = vim.fn.reg_recording() 84 if rec ~= "" then 85 return "%#Normal#" .. "@" .. rec .. " " .. "%#NormalNC#" 86 else 87 return "%#NormalNC#" 88 end 89end 90 91local function search_count() 92 if vim.v.hlsearch == 0 then 93 return "" 94 end 95 96 local ok, result = pcall(vim.fn.searchcount, { maxcount = 999, timeout = 500 }) 97 if not ok or next(result) == nil then 98 return "" 99 end 100 101 local denominator = math.min(result.total, result.maxcount) 102 return string.format("%d/%d", result.current, denominator) 103end 104 105local function buffer_diagnostics() 106 local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) 107 local ERROR = "%#DiagnosticSignError#" .. errors .. "%#NormalNC#" .. " " 108 109 local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) 110 local WARNING = "%#DiagnosticSignWarn#" .. warnings .. "%#NormalNC#" .. " " 111 112 local info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) 113 local INFO = (info and info > 0) and ("%#DiagnosticSignInfo#" .. info .. "%#NormalNC#") or "" .. " " 114 115 local hint = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) 116 local HINT = (hint and hint > 0) and ("%#DiagnosticSignHint#" .. hint .. "%#NormalNC#") or "" .. " " 117 118 return "%#Normal#" .. HINT .. INFO .. ERROR .. WARNING .. "%#NormalNC#" .. " " 119end 120 121local function file_type() 122 local type = vim.bo.filetype 123 return "%#Normal#" .. type .. "%#NormalNC#" .. " " 124end 125 126local function cursor_position() 127 local row = vim.fn.line(".") 128 local column = vim.fn.col(".") 129 return row .. ":" .. column .. " " 130end 131 132-- StatusLine Modes 133Status = function() 134 return table.concat({ 135 current_mode(), 136 get_current_file_name(), 137 git_branch(), 138 git_diff(), 139 "%=", -- right align 140 macro_status(), 141 search_count(), 142 buffer_diagnostics(), 143 file_type(), 144 cursor_position(), 145 }) 146end 147 148-- Execute statusline 149vim.api.nvim_create_autocmd({ "BufWinEnter" }, { 150 pattern = "*", 151 command = "setlocal statusline=%!v:lua.Status()", 152})