diff options
Diffstat (limited to 'nvim/lua/plugins')
39 files changed, 10945 insertions, 0 deletions
diff --git a/nvim/lua/plugins/airline.lua b/nvim/lua/plugins/airline.lua new file mode 100644 index 0000000..76f3655 --- /dev/null +++ b/nvim/lua/plugins/airline.lua @@ -0,0 +1,9 @@ +-- airline +vim.cmd([[ + let g:airline#extensions#tabline#enabled = 1 + let g:airline#extensions#tabline#show_buffers = 1 + let g:airline_powerline_fonts = 1 + let g:airline#extensions#tabline#buffer_nr_show = 1 + let g:airline#extensions#tagbar#enabled = 0 + let g:airline_theme='onedark' +]]) diff --git a/nvim/lua/plugins/autopairs.lua b/nvim/lua/plugins/autopairs.lua new file mode 100644 index 0000000..577e571 --- /dev/null +++ b/nvim/lua/plugins/autopairs.lua @@ -0,0 +1,33 @@ +-- Setup nvim-cmp. +local status_ok, npairs = pcall(require, "nvim-autopairs") +if not status_ok then + return +end + +npairs.setup { + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + fast_wrap = { + map = "<M-e>", + chars = { "{", "[", "(", '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "PmenuSel", + highlight_grey = "LineNr", + }, +} + +local cmp_autopairs = require "nvim-autopairs.completion.cmp" +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } }) diff --git a/nvim/lua/plugins/bufferline.lua b/nvim/lua/plugins/bufferline.lua new file mode 100644 index 0000000..6488f29 --- /dev/null +++ b/nvim/lua/plugins/bufferline.lua @@ -0,0 +1,323 @@ +require("bufferline").setup({ + options = { + numbers = "buffer_id", -- | "ordinal" | "buffer_id" | "both" | "none" | function({ ordinal, id, lower, raise }): string, + close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + --indicator = { + -- icon = '', -- this should be omitted if indicator style is not 'icon' + -- style = 'icon', -- | 'underline' | 'none', + --}, + --indicator_icon = " ", + --left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" + modified_icon = '●', + left_trunc_marker = "", + right_trunc_marker = "", + show_buffer_close_icons = true, + --diagnostics = "nvim_lsp", + diagnostics = false, --"nvim_lsp", --false, -- | "nvim_lsp" | "coc", + diagnostics_update_in_insert = false, + buffer_close_icon = "", + separator_style = "thin", + enforce_regular_tabs = true, + always_show_bufferline = true, + max_name_length = 25, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + highlight = "StatusLine", + text_align = "center", + }, + }, + custom_areas = { + right = function() + local result = {} + local error = vim.diagnostic.get_count(0, [[Error]]) + local warning = vim.diagnostic.get_count(0, [[Warning]]) + local info = vim.diagnostic.get_count(0, [[Information]]) + local hint = vim.diagnostic.get_count(0, [[Hint]]) + + if error ~= 0 then + result[1] = { text = " " .. error, fg = "#EC5241" } + end + + if warning ~= 0 then + result[2] = { text = " " .. warning, fg = "#EFB839" } + end + + if hint ~= 0 then + result[3] = { text = " " .. hint, fg = "#A3BA5E" } + end + + if info ~= 0 then + result[4] = { text = " " .. info, fg = "#7EA9A7" } + end + + return result + end, + }, + }, + highlights = { + background = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab_selected = { + fg = "#fdf6e3", + bg = "#002b36", + --fg = tabline_sel_bg, + }, + tab_close = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_selected = { + fg = "002b36", + bg = "#fdf6e3", + bold = true, + italic = true, + }, + numbers = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + hint = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + hint_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + error = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + error_diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + modified = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + duplicate_selected = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true, + }, + duplicate_visible = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + duplicate = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + separator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator = { + fg = "#fdf6e3", + bg = "#002b36", + }, + indicator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + pick_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick_visible = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + --offset_separator = { + -- fg = win_separator_fg, + -- bg = separator_background_color, + --}, + } +}) diff --git a/nvim/lua/plugins/bufferline.lua-202209041657.backup b/nvim/lua/plugins/bufferline.lua-202209041657.backup new file mode 100644 index 0000000..1d45e5f --- /dev/null +++ b/nvim/lua/plugins/bufferline.lua-202209041657.backup @@ -0,0 +1,322 @@ +require("bufferline").setup({ + options = { + numbers = "buffer_id", -- | "ordinal" | "buffer_id" | "both" | "none" | function({ ordinal, id, lower, raise }): string, + close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + --indicator = { + -- icon = '', -- this should be omitted if indicator style is not 'icon' + -- style = 'icon', -- | 'underline' | 'none', + --}, + --indicator_icon = " ", + --left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" + modified_icon = '●', + left_trunc_marker = "", + right_trunc_marker = "", + show_buffer_close_icons = true, + --diagnostics = "nvim_lsp", + diagnostics = false, --"nvim_lsp", --false, -- | "nvim_lsp" | "coc", + diagnostics_update_in_insert = false, + buffer_close_icon = "", + separator_style = "slant", + enforce_regular_tabs = true, + always_show_bufferline = true, + max_name_length = 25, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + highlight = "StatusLine", + text_align = "center", + }, + }, + custom_areas = { + right = function() + local result = {} + local error = vim.diagnostic.get_count(0, [[Error]]) + local warning = vim.diagnostic.get_count(0, [[Warning]]) + local info = vim.diagnostic.get_count(0, [[Information]]) + local hint = vim.diagnostic.get_count(0, [[Hint]]) + + if error ~= 0 then + result[1] = { text = " " .. error, fg = "#EC5241" } + end + + if warning ~= 0 then + result[2] = { text = " " .. warning, fg = "#EFB839" } + end + + if hint ~= 0 then + result[3] = { text = " " .. hint, fg = "#A3BA5E" } + end + + if info ~= 0 then + result[4] = { text = " " .. info, fg = "#7EA9A7" } + end + + return result + end, + }, + }, + highlights = { + background = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab_selected = { + fg = tabline_sel_bg, + bg = "#002b36", + }, + tab_close = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_selected = { + fg = normal_fg, + bg = "#002b36", + bold = true, + italic = true, + }, + numbers = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + hint = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + hint_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + error = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + error_diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + modified = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + duplicate_selected = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true, + }, + duplicate_visible = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + duplicate = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + separator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator = { + fg = "#fdf6e3", + bg = "#002b36", + }, + indicator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + pick_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick_visible = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + --offset_separator = { + -- fg = win_separator_fg, + -- bg = separator_background_color, + --}, + } +}) diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua new file mode 100644 index 0000000..93bc5b2 --- /dev/null +++ b/nvim/lua/plugins/cmp.lua @@ -0,0 +1,134 @@ +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local lspkind = require("lspkind") +cmp.setup({ + formatting = { + format = lspkind.cmp_format({ + mode = "symbol", -- show only symbol annotations + maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) + ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) + + -- The function below will be called before any actual modifications from lspkind + -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) + before = function(entry, vim_item) + --... + return vim_item + end, + }), + }, +}) + +require("luasnip/loaders/from_vscode").lazy_load() + +-- פּ ﯟ some other good icons +local kind_icons = { + Text = "", + Method = "", + Function = "", + Constructor = "⚙️", + Field = "", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} + +-- find more here: https://www.nerdfonts.com/cheat-sheet + +cmp.setup({ + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + ["<C-d>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + ["<C-Space>"] = cmp.mapping.complete(), + ["<C-e>"] = cmp.mapping.close(), + ["<CR>"] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + }), + sources = cmp.config.sources({ + { name = "path" }, + { name = "nvim_lsp", keyword_length = 3 }, + { name = "buffer", keyword_length = 3 }, + { name = "luasnip", keyword_length = 4 }, + { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, + --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this + --{name = 'luasnip', keyword_length = 2}, + }), + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + vim_item.menu = ({ + nvim_lsp = "[LSP]", + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + }, + experimental = { + ghost_text = true, + native_menu = false, + --view = { + -- entries = "native" + --}, + }, +}) + +--vim.cmd([[ +-- set completeopt=menuone,noinsert,noselect +-- highlight! default link CmpItemKind CmpItemMenuDefault +--]]) + +cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, +}) + +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), +}) diff --git a/nvim/lua/plugins/colorizer.lua b/nvim/lua/plugins/colorizer.lua new file mode 100644 index 0000000..14d25e2 --- /dev/null +++ b/nvim/lua/plugins/colorizer.lua @@ -0,0 +1,6 @@ +local status, colorizer = pcall(require, "colorizer") +if (not status) then return end + +colorizer.setup({ + '*'; +}) diff --git a/nvim/lua/plugins/colorscheme.lua b/nvim/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..a7653e2 --- /dev/null +++ b/nvim/lua/plugins/colorscheme.lua @@ -0,0 +1,29 @@ +-- Colorscheme +-- ayu gruvbox molokai onedark srcery everblush vscode edge nightfly +local colorscheme = "onedark" +local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) +if not status_ok then + vim.notify("colorscheme " .. colorscheme .. " not found!") + return +end + +vim.api.nvim_command("syntax on") +vim.api.nvim_command("highlight Normal guibg=none") +vim.api.nvim_command("highlight SignColumn guibg=none") +vim.api.nvim_command("highlight TabLine guibg=#333842 gui=bold") +--vim.api.nvim_command("highlight TabLine guibg=none gui=bold") +vim.api.nvim_command("highlight StatusLine guibg=#333842 gui=bold") +--vim.api.nvim_command("highlight StatusLine guibg=#333842 guifg=#d6d3ea gui=bold") +--vim.api.nvim_command("highlight StatusLine guibg=none gui=bold") +--vim.api.nvim_command("highlight TabLineNC guibg=none gui=bold") +--vim.api.nvim_command("highlight TabLineSel guibg=#bd93f9 gui=bold") +vim.api.nvim_command("highlight TabLineSel guibg=#333842 gui=bold") +vim.api.nvim_command("highlight TabLineFill guibg=none gui=bold") +vim.api.nvim_command("highlight WinBar guibg=none gui=bold") +--vim.api.nvim_command("highlight StatusLine guibg=none gui=bold") +--vim.api.nvim_command("highlight StatusLineNC guibg=none gui=bold") +--vim.api.nvim_command("highlight StatusLineNC guibg=none ctermfg=Cyan guifg=#80a0ff gui=bold") + +require("notify").setup({ + background_colour = "#000000", +}) diff --git a/nvim/lua/plugins/feline.lua b/nvim/lua/plugins/feline.lua new file mode 100644 index 0000000..f259108 --- /dev/null +++ b/nvim/lua/plugins/feline.lua @@ -0,0 +1,726 @@ +require('feline').setup() +--local lsp = require("feline.providers.lsp") +--local vi_mode_utils = require("feline.providers.vi_mode") +--local navic = require("nvim-navic") +-- +--local force_inactive = { +-- filetypes = {}, +-- buftypes = {}, +-- bufnames = {}, +--} +-- +--local winbar_components = { +-- active = { {}, {}, {} }, +-- inactive = { {}, {}, {} }, +--} +-- +--local components = { +-- active = { {}, {}, {} }, +-- inactive = { {}, {}, {} }, +--} +-- +--local colors = { +-- bg = "#282828", +-- black = "#282828", +-- yellow = "#d8a657", +-- cyan = "#89b482", +-- oceanblue = "#45707a", +-- green = "#a9b665", +-- orange = "#e78a4e", +-- violet = "#d3869b", +-- magenta = "#c14a4a", +-- white = "#a89984", +-- fg = "#a89984", +-- skyblue = "#7daea3", +-- red = "#ea6962", +--} +-- +--local vi_mode_colors = { +-- NORMAL = "green", +-- OP = "green", +-- INSERT = "red", +-- CONFIRM = "red", +-- VISUAL = "skyblue", +-- LINES = "skyblue", +-- BLOCK = "skyblue", +-- REPLACE = "violet", +-- ["V-REPLACE"] = "violet", +-- ENTER = "cyan", +-- MORE = "cyan", +-- SELECT = "orange", +-- COMMAND = "green", +-- SHELL = "green", +-- TERM = "green", +-- NONE = "yellow", +--} +-- +--local vi_mode_text = { +-- NORMAL = "<|", +-- OP = "<|", +-- INSERT = "|>", +-- VISUAL = "<>", +-- LINES = "<>", +-- BLOCK = "<>", +-- REPLACE = "<>", +-- ["V-REPLACE"] = "<>", +-- ENTER = "<>", +-- MORE = "<>", +-- SELECT = "<>", +-- COMMAND = "<|", +-- SHELL = "<|", +-- TERM = "<|", +-- NONE = "<>", +-- CONFIRM = "|>", +--} +-- +--local buffer_not_empty = function() +-- if vim.fn.empty(vim.fn.expand("%:t")) ~= 1 then +-- return true +-- end +-- return false +--end +-- +--local checkwidth = function() +-- local squeeze_width = vim.fn.winwidth(0) / 2 +-- if squeeze_width > 40 then +-- return true +-- end +-- return false +--end +-- +--force_inactive.filetypes = { +-- "NvimTree", +-- "dbui", +-- "packer", +-- "startify", +-- "fugitive", +-- "fugitiveblame", +--} +-- +--force_inactive.buftypes = { +-- "terminal", +--} +-- +---- STATUSLINE +---- LEFT +-- +---- vi-mode +--components.active[1][1] = { +-- provider = " NV-IDE ", +-- hl = function() +-- local val = {} +-- +-- val.bg = vi_mode_utils.get_mode_color() +-- val.fg = "black" +-- val.style = "bold" +-- +-- return val +-- end, +-- right_sep = " ", +--} +---- vi-symbol +--components.active[1][2] = { +-- provider = function() +-- return vi_mode_text[vi_mode_utils.get_vim_mode()] +-- end, +-- hl = function() +-- local val = {} +-- val.fg = vi_mode_utils.get_mode_color() +-- val.bg = "bg" +-- val.style = "bold" +-- return val +-- end, +-- right_sep = " ", +--} +---- filename +--components.active[1][3] = { +-- provider = function() +-- return vim.fn.expand("%:F") +-- end, +-- hl = { +-- fg = "white", +-- bg = "bg", +-- style = "bold", +-- }, +--} +---- MID +-- +---- gitBranch +--components.active[2][1] = { +-- provider = "git_branch", +-- hl = { +-- fg = "yellow", +-- bg = "bg", +-- style = "bold", +-- }, +--} +---- diffAdd +--components.active[2][2] = { +-- provider = "git_diff_added", +-- hl = { +-- fg = "green", +-- bg = "bg", +-- style = "bold", +-- }, +--} +---- diffModfified +--components.active[2][3] = { +-- provider = "git_diff_changed", +-- hl = { +-- fg = "orange", +-- bg = "bg", +-- style = "bold", +-- }, +--} +---- diffRemove +--components.active[2][4] = { +-- provider = "git_diff_removed", +-- hl = { +-- fg = "red", +-- bg = "bg", +-- style = "bold", +-- }, +--} +-- +---- RIGHT +-- +---- fileIcon +--components.active[3][1] = { +-- provider = function() +-- local filename = vim.fn.expand("%:t") +-- local extension = vim.fn.expand("%:e") +-- local icon = require("nvim-web-devicons").get_icon(filename, extension) +-- if icon == nil then +-- icon = "" +-- end +-- return icon +-- end, +-- hl = function() +-- local val = {} +-- local filename = vim.fn.expand("%:t") +-- local extension = vim.fn.expand("%:e") +-- local icon, name = require("nvim-web-devicons").get_icon(filename, extension) +-- if icon ~= nil then +-- val.fg = vim.fn.synIDattr(vim.fn.hlID(name), "fg") +-- else +-- val.fg = "white" +-- end +-- val.bg = "bg" +-- val.style = "bold" +-- return val +-- end, +-- right_sep = " ", +--} +---- fileType +--components.active[3][2] = { +-- provider = "file_type", +-- hl = function() +-- local val = {} +-- local filename = vim.fn.expand("%:t") +-- local extension = vim.fn.expand("%:e") +-- local icon, name = require("nvim-web-devicons").get_icon(filename, extension) +-- if icon ~= nil then +-- val.fg = vim.fn.synIDattr(vim.fn.hlID(name), "fg") +-- else +-- val.fg = "white" +-- end +-- val.bg = "bg" +-- val.style = "bold" +-- return val +-- end, +-- right_sep = " ", +--} +---- fileSize +--components.active[3][3] = { +-- provider = "file_size", +-- enabled = function() +-- return vim.fn.getfsize(vim.fn.expand("%:t")) > 0 +-- end, +-- hl = { +-- fg = "skyblue", +-- bg = "bg", +-- style = "bold", +-- }, +-- right_sep = " ", +--} +---- fileFormat +--components.active[3][4] = { +-- provider = function() +-- return "" .. vim.bo.fileformat:upper() .. "" +-- end, +-- hl = { +-- fg = "white", +-- bg = "bg", +-- style = "bold", +-- }, +-- right_sep = " ", +--} +---- fileEncode +--components.active[3][5] = { +-- provider = "file_encoding", +-- hl = { +-- fg = "white", +-- bg = "bg", +-- style = "bold", +-- }, +-- right_sep = " ", +--} +--components.active[3][6] = { +-- provider = "position", +-- hl = { +-- fg = "white", +-- bg = "bg", +-- style = "bold", +-- }, +-- right_sep = " ", +--} +---- linePercent +--components.active[3][7] = { +-- provider = "line_percentage", +-- hl = { +-- fg = "white", +-- bg = "bg", +-- style = "bold", +-- }, +-- right_sep = " ", +--} +---- scrollBar +--components.active[3][8] = { +-- provider = "scroll_bar", +-- hl = { +-- fg = "yellow", +-- bg = "bg", +-- }, +--} +-- +---- INACTIVE +-- +---- fileType +--components.inactive[1][1] = { +-- provider = "file_type", +-- hl = { +-- fg = "black", +-- bg = "cyan", +-- style = "bold", +-- }, +-- left_sep = { +-- str = " ", +-- hl = { +-- fg = "NONE", +-- bg = "cyan", +-- }, +-- }, +-- right_sep = { +-- { +-- str = " ", +-- hl = { +-- fg = "NONE", +-- bg = "cyan", +-- }, +-- }, +-- " ", +-- }, +--} +-- +---- WINBAR +---- LEFT +-- +---- nvimGps +--winbar_components.active[1][1] = { +-- provider = function() +-- return navic.get_location() +-- end, +-- enabled = function() +-- return navic.is_available() +-- end, +-- hl = { +-- fg = "orange", +-- style = "bold", +-- }, +--} +-- +---- MID +-- +---- RIGHT +-- +---- LspName +--winbar_components.active[3][1] = { +-- provider = "lsp_client_names", +-- hl = { +-- fg = "yellow", +-- style = "bold", +-- }, +-- right_sep = " ", +--} +---- diagnosticErrors +--winbar_components.active[3][2] = { +-- provider = "diagnostic_errors", +-- enabled = function() +-- return lsp.diagnostics_exist(vim.diagnostic.severity.ERROR) +-- end, +-- hl = { +-- fg = "red", +-- style = "bold", +-- }, +--} +---- diagnosticWarn +--winbar_components.active[3][3] = { +-- provider = "diagnostic_warnings", +-- enabled = function() +-- return lsp.diagnostics_exist(vim.diagnostic.severity.WARN) +-- end, +-- hl = { +-- fg = "yellow", +-- style = "bold", +-- }, +--} +---- diagnosticHint +--winbar_components.active[3][4] = { +-- provider = "diagnostic_hints", +-- enabled = function() +-- return lsp.diagnostics_exist(vim.diagnostic.severity.HINT) +-- end, +-- hl = { +-- fg = "cyan", +-- style = "bold", +-- }, +--} +---- diagnosticInfo +--winbar_components.active[3][5] = { +-- provider = "diagnostic_info", +-- enabled = function() +-- return lsp.diagnostics_exist(vim.diagnostic.severity.INFO) +-- end, +-- hl = { +-- fg = "skyblue", +-- style = "bold", +-- }, +--} +-- +---- INACTIVE +-- +---- fileType +--winbar_components.inactive[1][1] = { +-- provider = "file_type", +-- hl = { +-- fg = "black", +-- bg = "cyan", +-- style = "bold", +-- }, +-- left_sep = { +-- str = " ", +-- hl = { +-- fg = "NONE", +-- bg = "cyan", +-- }, +-- }, +-- right_sep = { +-- { +-- str = " ", +-- hl = { +-- fg = "NONE", +-- bg = "cyan", +-- }, +-- }, +-- " ", +-- }, +--} +-- +--require("feline").setup({ +-- theme = colors, +-- default_bg = bg, +-- default_fg = fg, +-- vi_mode_colors = vi_mode_colors, +-- components = components, +-- force_inactive = force_inactive, +--}) +-- +--require("feline").winbar.setup({ +-- components = winbar_components, +-- force_inactive = force_inactive, +--}) +----local M = { vi = {} } +---- +---- +----M.vi.text = { +---- n = "NORMAL", +---- no = "NORMAL", +---- i = "INSERT", +---- v = "VISUAL", +---- V = "V-LINE", +---- [""] = "V-BLOCK", +---- c = "COMMAND", +---- cv = "COMMAND", +---- ce = "COMMAND", +---- R = "REPLACE", +---- Rv = "REPLACE", +---- s = "SELECT", +---- S = "SELECT", +---- [""] = "SELECT", +---- t = "TERMINAL", +----} +---- +----M.vi.colors = { +---- n = "FlnViCyan", +---- no = "FlnViCyan", +---- i = "FlnStatus", +---- v = "FlnViMagenta", +---- V = "FlnViMagenta", +---- [""] = "FlnViMagenta", +---- R = "FlnViRed", +---- Rv = "FlnViRed", +---- r = "FlnViBlue", +---- rm = "FlnViBlue", +---- s = "FlnViMagenta", +---- S = "FlnViMagenta", +---- [""] = "FelnMagenta", +---- c = "FlnViYellow", +---- ["!"] = "FlnViBlue", +---- t = "FlnViBlue", +----} +---- +----M.vi.sep = { +---- n = "FlnCyan", +---- no = "FlnCyan", +---- i = "FlnStatusBg", +---- v = "FlnMagenta", +---- V = "FlnMagenta", +---- [""] = "FlnMagenta", +---- R = "FlnRed", +---- Rv = "FlnRed", +---- r = "FlnBlue", +---- rm = "FlnBlue", +---- s = "FlnMagenta", +---- S = "FlnMagenta", +---- [""] = "FelnMagenta", +---- c = "FlnYellow", +---- ["!"] = "FlnBlue", +---- t = "FlnBlue", +----} +---- +----M.icons = { +---- locker = "", -- #f023 +---- page = "☰", -- 2630 +---- line_number = "", -- e0a1 +---- connected = "", -- f817 +---- dos = "", -- e70f +---- unix = "", -- f17c +---- mac = "", -- f179 +---- mathematical_L = "𝑳", +---- vertical_bar = "┃", +---- vertical_bar_thin = "│", +---- left = "", +---- right = "", +---- block = "█", +---- left_filled = "", +---- right_filled = "", +---- slant_left = "", +---- slant_left_thin = "", +---- slant_right = "", +---- slant_right_thin = "", +---- slant_left_2 = "", +---- slant_left_2_thin = "", +---- slant_right_2 = "", +---- slant_right_2_thin = "", +---- left_rounded = "", +---- left_rounded_thin = "", +---- right_rounded = "", +---- right_rounded_thin = "", +---- circle = "●", +----} +---- +----return M +------ Feline statusline definition. +------ +------ Note: This statusline does not define any colors. Instead the statusline is +------ built on custom highlight groups that I define. The colors for these +------ highlight groups are pulled from the current colorscheme applied. Check the +------ file: `lua/eden/modules/ui/colors.lua` to see how they are defined. +---- +----local u = require("eden.modules.ui.feline.util") +----local fmt = string.format +---- +------ "┃", "█", "", "", "", "", "", "", "●" +---- +----local get_diag = function(str) +---- local count = vim.lsp.diagnostic.get_count(0, str) +---- return (count > 0) and " " .. count .. " " or "" +----end +---- +----local function vi_mode_hl() +---- return u.vi.colors[vim.fn.mode()] or "FlnViBlack" +----end +---- +----local function vi_sep_hl() +---- return u.vi.sep[vim.fn.mode()] or "FlnBlack" +----end +---- +----local c = { +---- vimode = { +---- provider = function() +---- return string.format(" %s ", u.vi.text[vim.fn.mode()]) +---- end, +---- hl = vi_mode_hl, +---- right_sep = { str = " ", hl = vi_sep_hl }, +---- }, +---- gitbranch = { +---- provider = "git_branch", +---- icon = " ", +---- hl = "FlnGitBranch", +---- right_sep = { str = " ", hl = "FlnGitBranch" }, +---- enabled = function() +---- return vim.b.gitsigns_status_dict ~= nil +---- end, +---- }, +---- file_type = { +---- provider = function() +---- return fmt(" %s ", vim.bo.filetype:upper()) +---- end, +---- hl = "FlnAlt", +---- }, +---- fileinfo = { +---- provider = { name = "file_info", opts = { type = "relative" } }, +---- hl = "FlnAlt", +---- left_sep = { str = " ", hl = "FlnAltSep" }, +---- right_sep = { str = "", hl = "FlnAltSep" }, +---- }, +---- file_enc = { +---- provider = function() +---- local os = u.icons[vim.bo.fileformat] or "" +---- return fmt(" %s %s ", os, vim.bo.fileencoding) +---- end, +---- hl = "StatusLine", +---- left_sep = { str = u.icons.left_filled, hl = "FlnAltSep" }, +---- }, +---- cur_position = { +---- provider = function() +---- -- TODO: What about 4+ diget line numbers? +---- return fmt(" %3d:%-2d ", unpack(vim.api.nvim_win_get_cursor(0))) +---- end, +---- hl = vi_mode_hl, +---- left_sep = { str = u.icons.left_filled, hl = vi_sep_hl }, +---- }, +---- cur_percent = { +---- provider = function() +---- return " " .. require("feline.providers.cursor").line_percentage() .. " " +---- end, +---- hl = vi_mode_hl, +---- left_sep = { str = u.icons.left, hl = vi_mode_hl }, +---- }, +---- default = { -- needed to pass the parent StatusLine hl group to right hand side +---- provider = "", +---- hl = "StatusLine", +---- }, +---- lsp_status = { +---- provider = function() +---- return require("lsp-status").status() +---- end, +---- hl = "FlnStatus", +---- left_sep = { str = "", hl = "FlnStatusBg", always_visible = true }, +---- right_sep = { str = "", hl = "FlnErrorStatus", always_visible = true }, +---- }, +---- lsp_error = { +---- provider = function() +---- return get_diag("Error") +---- end, +---- hl = "FlnError", +---- right_sep = { str = "", hl = "FlnWarnError", always_visible = true }, +---- }, +---- lsp_warn = { +---- provider = function() +---- return get_diag("Warning") +---- end, +---- hl = "FlnWarn", +---- right_sep = { str = "", hl = "FlnInfoWarn", always_visible = true }, +---- }, +---- lsp_info = { +---- provider = function() +---- return get_diag("Information") +---- end, +---- hl = "FlnInfo", +---- right_sep = { str = "", hl = "FlnHintInfo", always_visible = true }, +---- }, +---- lsp_hint = { +---- provider = function() +---- return get_diag("Hint") +---- end, +---- hl = "FlnHint", +---- right_sep = { str = "", hl = "FlnBgHint", always_visible = true }, +---- }, +---- +---- in_fileinfo = { +---- provider = "file_info", +---- hl = "StatusLine", +---- }, +---- in_position = { +---- provider = "position", +---- hl = "StatusLine", +---- }, +----} +---- +----local active = { +---- { -- left +---- c.vimode, +---- c.gitbranch, +---- c.fileinfo, +---- c.default, -- must be last +---- }, +---- { -- right +---- c.lsp_status, +---- c.lsp_error, +---- c.lsp_warn, +---- c.lsp_info, +---- c.lsp_hint, +---- c.file_type, +---- c.file_enc, +---- c.cur_position, +---- c.cur_percent, +---- }, +----} +---- +----local inactive = { +---- { c.in_fileinfo }, -- left +---- { c.in_position }, -- right +----} +---- +------ -- Define autocmd that generates the highlight groups from the new colorscheme +------ -- Then reset the highlights for feline +------ edn.aug.FelineColorschemeReload = { +------ { +------ { "SessionLoadPost", "ColorScheme" }, +------ function() +------ require("eden.modules.ui.feline.colors").gen_highlights() +------ -- This does not look like it is required. If this is called I see the ^^^^^^ that +------ -- seperates the two sides of the bar. Since the entire config uses highlight groups +------ -- all that is required is to redefine them. +------ -- require("feline").reset_highlights() +------ end, +------ }, +------ } +---- +----require("feline").setup({ +---- components = { active = active, inactive = inactive }, +---- highlight_reset_triggers = {}, +---- force_inactive = { +---- filetypes = { +---- "NvimTree", +---- "packer", +---- "dap-repl", +---- "dapui_scopes", +---- "dapui_stacks", +---- "dapui_watches", +---- "dapui_repl", +---- "LspTrouble", +---- "qf", +---- "help", +---- }, +---- buftypes = { "terminal" }, +---- bufnames = {}, +---- }, +---- disable = { +---- filetypes = { +---- "dashboard", +---- "startify", +---- }, +---- }, +----}) diff --git a/nvim/lua/plugins/floaterm.lua b/nvim/lua/plugins/floaterm.lua new file mode 100644 index 0000000..ea554af --- /dev/null +++ b/nvim/lua/plugins/floaterm.lua @@ -0,0 +1,6 @@ +vim.cmd([[ + let g:floaterm_keymap_new = '<leader>t' + let g:floaterm_keymap_prev = '<leader>tn' + let g:floaterm_keymap_next = '<leader>tp' + let g:floaterm_keymap_toggle = '<leader>tt' +]]) diff --git a/nvim/lua/plugins/fzf.lua b/nvim/lua/plugins/fzf.lua new file mode 100644 index 0000000..4195cd6 --- /dev/null +++ b/nvim/lua/plugins/fzf.lua @@ -0,0 +1,66 @@ +vim.cmd([[ + " FZF fuzzy finder + "--------------------------------------- + " Enable per-command history. + " CTRL-N and CTRL-P will be automatically bound to next-history and + " previous-history instead of down and up. If you don't like the change, + " explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS. + let g:fzf_history_dir = '~/.local/share/fzf-history' + map <leader>fz :FZF<CR> + map <leader>a :Files<CR> + map <leader>l :Lines<CR> + map <leader>L :BLines<CR> + map <leader>B :Buffers<CR> + map <leader>h :History:<CR> + nnoremap <leader>g :Rg<CR> + "nnoremap <leader>t :Tags<CR> + nnoremap <leader>m :Marks<CR> + " This is the default extra key bindings + let g:fzf_action = { + \ 'ctrl-t': 'tab split', + \ 'ctrl-x': 'split', + \ 'ctrl-y': 'vsplit' } + let g:fzf_tags_command = 'ctags -R' + " Border color + let g:fzf_layout = {'up':'~90%', 'window': { 'width': 0.8, 'height': 0.8,'yoffset':0.5,'xoffset': 0.5, 'highlight': 'Todo', 'border': 'sharp' } } + let $FZF_DEFAULT_OPTS = '--layout=reverse --info=inline' + let $FZF_DEFAULT_COMMAND="rg --files --hidden" + " Customize fzf colors to match your color scheme + let g:fzf_colors = + \ { 'fg': ['fg', 'Normal'], + \ 'bg': ['bg', 'Normal'], + \ 'hl': ['fg', 'Comment'], + \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], + \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], + \ 'hl+': ['fg', 'Statement'], + \ 'info': ['fg', 'PreProc'], + \ 'border': ['fg', 'Ignore'], + \ 'prompt': ['fg', 'Conditional'], + \ 'pointer': ['fg', 'Exception'], + \ 'marker': ['fg', 'Keyword'], + \ 'spinner': ['fg', 'Label'], + \ 'header': ['fg', 'Comment'] } + " Get Files + command! -bang -nargs=? -complete=dir Files + \ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline']}), <bang>0) + " Get text in files with Rg + command! -bang -nargs=* Rg + \ call fzf#vim#grep( + \ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1, + \ fzf#vim#with_preview(), <bang>0) + " Ripgrep advanced + function! RipgrepFzf(query, fullscreen) + let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true' + let initial_command = printf(command_fmt, shellescape(a:query)) + let reload_command = printf(command_fmt, '{q}') + let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]} + call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen) + endfunction + command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0) + " Git grep + command! -bang -nargs=* GGrep + \ call fzf#vim#grep( + \ 'git grep --line-number '.shellescape(<q-args>), 0, + \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), <bang>0) + command! -bang FM call fzf#run(fzf#wrap({'source': 'cat ~/.fzf-marks | sed "s/.*: \(.*\)$/\1/" | sed "s#~#${HOME}#"', 'sink': 'lcd'}, <bang>0)) +]]) diff --git a/nvim/lua/plugins/git.lua b/nvim/lua/plugins/git.lua new file mode 100644 index 0000000..963f7f9 --- /dev/null +++ b/nvim/lua/plugins/git.lua @@ -0,0 +1,11 @@ +local status, git = pcall(require, "git") +if (not status) then return end + +git.setup({ + keymaps = { + -- Open blame window + blame = "<Leader>gb", + -- Open file/folder in git repository + browse = "<Leader>go", + } +}) diff --git a/nvim/lua/plugins/gitsigns.lua b/nvim/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..53d1a1e --- /dev/null +++ b/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1 @@ +require('gitsigns').setup {} diff --git a/nvim/lua/plugins/heirline.backup.lua b/nvim/lua/plugins/heirline.backup.lua new file mode 100644 index 0000000..d65de92 --- /dev/null +++ b/nvim/lua/plugins/heirline.backup.lua @@ -0,0 +1,733 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +require("nvim-gps").setup({ + icons = { + ["class-name"] = " ", + ["function-name"] = " ", + ["method-name"] = " ", + ["container-name"] = "炙", + ["tag-name"] = "炙", + }, +}) + +vim.o.laststatus = 3 + +local colors = { + bg = "#333842", + brown = "#504945", + white = "#f8f8f0", + grey = "#8F908A", + black = "#000000", + pink = "#f92672", + green = "#a6e22e", + blue = "#66d9ef", + yellow = "#e6db74", + orange = "#fd971f", + purple = "#ae81ff", + red = "#e95678", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +local ViMode = { + -- get vim current mode, this information will be required by the provider + -- and the highlight functions, so we compute it only once per component + -- evaluation and store it as a component attribute + init = function(self) + self.mode = vim.fn.mode(1) -- :h mode() + end, + -- Now we define some dictionaries to map the output of mode() to the + -- corresponding string and color. We can put these into `static` to compute + -- them at initialisation time. + static = { + mode_names = { + -- change the strings if you like it vvvvverbose! + ["n"] = "NORMAL ", + ["no"] = "N·OPERATOR PENDING ", + ["v"] = "VISUAL ", + ["V"] = "V·LINE ", + [""] = "V·BLOCK ", + ["s"] = "SELECT ", + ["S"] = "S·LINE ", + [""] = "S·BLOCK ", + ["i"] = "INSERT ", + ["R"] = "REPLACE ", + ["Rv"] = "V·REPLACE ", + ["c"] = "COMMAND ", + ["cv"] = "VIM EX ", + ["ce"] = "EX ", + ["r"] = "PROMPT ", + ["rm"] = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + ["t"] = "TERMINAL ", + }, + mode_colors = { + n = colors.green, + i = colors.pink, + v = colors.blue, + V = colors.blue, + [""] = colors.blue, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + }, + -- We can now access the value of mode() that, by now, would have been + -- computed by `init()` and use it to index our strings dictionary. + -- note how `static` fields become just regular attributes once the + -- component is instantiated. + -- To be extra meticulous, we can also add some vim statusline syntax to + -- control the padding and make sure our string is always at least 2 + -- characters long. Plus a nice Icon. + provider = function(self) + return " %2(" .. self.mode_names[self.mode] .. "%)" + end, + -- Same goes for the highlight. Now the foreground will change according to the current mode. + hl = function(self) + local mode = self.mode:sub(1, 1) -- get only the first mode character + return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } + end, +} + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} +-- We can now define some children separately and add them later + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "[No Name]" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + hl = { fg = utils.get_highlight("Directory").fg, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return "" + end + end, + hl = { fg = colors.orange }, + }, +} + +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + -- use `force` because we need to override the child's hl foreground + return { fg = colors.cyan, bold = true, force = true, bg = colors.bg } + end + end, +} + +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local Diagnostics = { + condition = conditions.has_diagnostics, + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, +} + +local Git = { + condition = conditions.is_git_repo, + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + hl = { fg = colors.orange, bg = colors.bg }, + { + -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + return count > 0 and (" " .. count) + end, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + return count > 0 and (" " .. count) + end, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + return count > 0 and (" " .. count) + end, + hl = { fg = colors.git.change, bg = colors.bg }, + }, +} + +local WorkDir = { + provider = function() + local icon = " " + local cwd = vim.fn.getcwd(0) + cwd = vim.fn.fnamemodify(cwd, ":~") + if not conditions.width_percent_below(#cwd, 0.25) then + cwd = vim.fn.pathshorten(cwd) + end + local trail = cwd:sub(-1) == "/" and "" or "/" + return icon .. cwd .. trail + end, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, +} + +local TerminalName = { + -- we could add a condition to check that buftype == 'terminal' + -- or we could do that later (see #conditional-statuslines below) + provider = function() + local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") + return " " .. tname + end, + hl = { bold = true, bg = colors.bg }, +} + +local Ruler = { + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + provider = "%7 %p%% Ln %l, Col %c", +} + +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " " } + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +local FileType = { + provider = function() + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileEncoding = { + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:upper() + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + FileEncoding, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileNameShort = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":t") + if filename == "" then + return "[No Name]" + end + return filename + end, + hl = { fg = colors.gray, bg = colors.bg }, +} + +local FileNameShortBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileNameShortBlock = utils.insert( + FileNameShortBlock, + FileIcon, + FileNameShort, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local Gps = { + condition = require("nvim-gps").is_available, + provider = function() + local loc = require("nvim-gps").get_location() + if loc == "" then + return "" + end + return "> " .. loc + end, + hl = { fg = colors.gray, bg = colors.bg }, +} + +local DefaultStatusline = { + ViMode, + Space, + FileNameBlock, + Space, + Diagnostics, + Align, + Ruler, + Space, + FileInfoBlock, + Space, + Git, +} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + FileType, + Space, + Align, +} + +local TerminalStatusline = { + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + TerminalName, + Align, +} + +local StatusLines = { + fallthrough = false, + SpecialStatusline, + TerminalStatusline, + DefaultStatusline, +} + +local GSpace = { provider = " ", hl = { bg = colors.bg } } + +local WinBars = { + fallthrough = false, + { + -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix", "nofile", "promt" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + provider = "", + }, + { + -- An inactive winbar for regular files + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) and not conditions.is_active() + end, + utils.surround( + { "", "" }, + colors.bright_bg, + { hl = { fg = "gray", force = true }, GSpace, TerminalName, Align } + ), + }, + { + -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, colors.dark_red, { + GSpace, + TerminalName, + Align, + }), + }, + { + -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround( + { "", "" }, + colors.bright_bg, + { hl = { fg = "gray", force = true }, GSpace, FileNameShortBlock, Align } + ), + }, + -- A winbar for regular files + { GSpace, FileNameShortBlock, GSpace, Gps, Align }, +} + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "[No Name]" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+]" + end + end, + hl = { fg = colors.green }, + }, + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return "" + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineDiagnostics = { + static = { + error_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + init = function(self) + self.errors = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.INFO }) + end, + { + provider = function(self) + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + else + return "TabLine" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = true }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineFileIcon, + TablineFileName, + TablineFileFlags, + TablineDiagnostics, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.bo[self.bufnr].modified + end, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +local TablineBufferBlock = utils.surround({ "", "" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLine").bg + end +end, { TablineFileNameBlock, TablineCloseButton }) + +-- and here we go +local BufferLine = utils.make_buflist( + TablineBufferBlock, + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + hl = "TabLine", +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +local TabLine = { TabLineOffset, BufferLine, TabPages } + +require("heirline").setup(StatusLines, WinBars, TabLine) + +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +vim.api.nvim_create_augroup("Heirline", { clear = true }) +vim.api.nvim_create_autocmd("ColorScheme", { + callback = function() + local colors = setup_colors() + utils.on_colorscheme(colors) + end, + group = "Heirline", +}) + +local function get_bufs() + return vim.tbl_filter(function(bufnr) + return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted + end, vim.api.nvim_list_bufs()) +end + +local function goto_buf(index) + local bufs = get_bufs() + if index > #bufs then + index = #bufs + end + vim.api.nvim_win_set_buf(0, bufs[index]) +end + +local function addKey(key, index) + vim.keymap.set("", "<A-" .. key .. ">", function() + goto_buf(index) + end, { noremap = true, silent = true }) +end + +for i = 1, 9 do + addKey(i, i) +end +addKey("0", 10) diff --git a/nvim/lua/plugins/heirline.backup2.lua b/nvim/lua/plugins/heirline.backup2.lua new file mode 100644 index 0000000..9f5c4ca --- /dev/null +++ b/nvim/lua/plugins/heirline.backup2.lua @@ -0,0 +1,1921 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +-- Colors +--local colors = { +-- bright_bg = utils.get_highlight("Folded").bg, +-- bright_fg = utils.get_highlight("Folded").fg, +-- red = utils.get_highlight("DiagnosticError").fg, +-- dark_red = utils.get_highlight("DiffDelete").bg, +-- green = utils.get_highlight("String").fg, +-- blue = utils.get_highlight("Function").fg, +-- gray = utils.get_highlight("NonText").fg, +-- orange = utils.get_highlight("Constant").fg, +-- purple = utils.get_highlight("Statement").fg, +-- cyan = utils.get_highlight("Special").fg, +-- diag_warn = utils.get_highlight("DiagnosticWarn").fg, +-- diag_error = utils.get_highlight("DiagnosticError").fg, +-- diag_hint = utils.get_highlight("DiagnosticHint").fg, +-- diag_info = utils.get_highlight("DiagnosticInfo").fg, +-- git_del = utils.get_highlight("diffDeleted").fg, +-- git_add = utils.get_highlight("diffAdded").fg, +-- git_change = utils.get_highlight("diffChanged").fg, +--} + +--local colors = { +-- gray = '#23232e', +-- lightgray = '#5f6a8e', +-- orange = '#ffb86c', +-- purple = '#bd93f9', +-- red = '#ff5555', +-- yellow = '#f1fa8c', +-- green = '#50fa7b', +-- white = '#f8f8f2', +-- black = '#282a36', +--} +local colors = { + bg = "#333842", + nobg = nil, + bright_fg = "#ffffff", + bright_bg = "#000000", + brown = "#504945", + white = "#f8f8f0", + grey = "#8F908A", + pink = "#f92672", + --green = "#a6e22e", + green = "#AAD94C", + --blue = "#66d9ef", + blue = "#39BAE6", + yellow = "#e6db74", + --orange = "#fd971f", + orange = "#FA8D3F", + purple = "#ae81ff", + --red = "#e95678", + red = "#F07171", + cyan = "#66d9eC", + mode_fg = "#242424", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +require("heirline").load_colors(colors) + +--local mode_lable = { +-- n = 'NORMAL', +-- no = 'OPPEND', +-- nov = 'N?', +-- noV = 'N?', +-- ['no\22'] = 'N?', +-- niI = 'Ni', +-- niR = 'Nr', +-- niV = 'Nv', +-- nt = 'N-TERM', +-- v = 'VISUAL', +-- vs = 'Vs', +-- V = 'V-LINE', +-- Vs = 'Vs', +-- ['\22'] = 'V-BLCK', +-- ['\22s'] = '^V', +-- s = 'SELECT', +-- S = 'S-LINE', +-- ['\19'] = 'S-BLCK', +-- i = 'INSERT', +-- ic = 'ICOMPL', +-- ix = 'Ix', +-- R = 'REPLACE', +-- Rc = 'Rc', +-- Rx = 'Rx', +-- Rv = 'VRPLCE', +-- Rvc = 'Rv', +-- Rvx = 'Rv', +-- c = 'CMMAND', +-- cv = 'PROMPT', +-- r = '...', +-- rm = 'MORE', +-- ['r?'] = 'CNFIRM', +-- ['!'] = 'SHELL', +-- t = 'TERM', +--} +-- +--local mode_colors_table = { +-- n = 'red', +-- no = 'blue', +-- nov = 'blue', +-- noV = 'blue', +-- niI = 'red', +-- niR = 'red', +-- niV = 'red', +-- nt = 'red', +-- v = 'cyan', +-- vs = 'cyan', +-- V = 'cyan', +-- Vs = 'cyan', +-- ['\22'] = 'cyan', +-- ['\22s'] = 'cyan', +-- s = 'purple', +-- S = 'purple', +-- ['\19'] = 'purple', +-- i = 'blue', +-- ic = 'blue', +-- ix = 'blue', +-- R = 'orange', +-- Rc = 'orange', +-- Rx = 'orange', +-- Rv = 'orange', +-- Rvc = 'orange', +-- Rvx = 'orange', +-- c = 'green', +-- cv = 'green', +-- r = 'green', +-- rm = 'green', +-- ['r?'] = 'green', +-- ['!'] = 'red', +-- t = 'red', +--} +-- +--local mode_colors = setmetatable({ +-- n = { fg = 'red' } +--}, { +-- __index = function(_, mode) +-- return { +-- fg = 'mode_fg', +-- bg = mode_colors_table[mode], +-- } +-- end +--}) +-- +-- +--local VimModeNormal = { +-- condition = function(self) +-- return self.mode == 'n' +-- end, +-- provider = ' ●', +--} +-- +--local VimModeOthers = { +-- condition = function(self) +-- return self.mode ~= 'n' +-- end, +-- +-- utils.surround({ '', '' }, +-- function(self) +-- return mode_colors[self.mode].bg +-- end, +-- { +-- { +-- provider = function(self) +-- return '● ' .. mode_lable[self.mode] +-- end, +-- }, +-- hl = function(self) +-- return mode_colors[self.mode] +-- end +-- } +-- ), +--} +-- +--local ViMode = { +-- init = function(self) +-- self.mode = vim.fn.mode(1) +-- end, +-- +-- VimModeNormal, VimModeOthers, +-- +-- update = { 'ModeChanged' } +--} +--local colors = require'kanagawa.colors'.setup() -- wink + +--utils.surround({ "", "" }, function(self) return self:mode_color() end, {Ruler, hl = {fg = 'black'}} ), +-- we are surrounding the component and adjusting the foreground in one go! + +-- ViMode truemode +--local ViMode = { +-- -- get vim current mode, this information will be required by the provider +-- -- and the highlight functions, so we compute it only once per component +-- -- evaluation and store it as a component attribute +-- init = function(self) +-- self.mode = vim.fn.mode(1) -- :h mode() +-- +-- -- execute this only once, this is required if you want the ViMode +-- -- component to be updated on operator pending mode +-- if not self.once then +-- vim.api.nvim_create_autocmd("ModeChanged", { +-- pattern = "*:*o", +-- command = "redrawstatus", +-- }) +-- self.once = true +-- end +-- end, +-- -- Now we define some dictionaries to map the output of mode() to the +-- -- corresponding string and color. We can put these into `static` to compute +-- -- them at initialisation time. +-- static = { +-- mode_names = { -- change the strings if you like it vvvvverbose! +-- ["n"] = "NORMAL ", +-- ["no"] = "N·OPERATOR PENDING ", +-- ["v"] = "VISUAL ", +-- ["V"] = "V·LINE ", +-- [""] = "V·BLOCK ", +-- ["s"] = "SELECT ", +-- ["S"] = "S·LINE ", +-- [""] = "S·BLOCK ", +-- ["i"] = "INSERT ", +-- ["R"] = "REPLACE ", +-- ["Rv"] = "V·REPLACE ", +-- ["c"] = "COMMAND ", +-- ["cv"] = "VIM EX ", +-- ["ce"] = "EX ", +-- ["r"] = "PROMPT ", +-- ["rm"] = "MORE ", +-- ["r?"] = "CONFIRM ", +-- ["!"] = "SHELL ", +-- ["t"] = "TERMINAL ", +-- }, +-- mode_colors = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- --n = "blue" , +-- --i = "green", +-- --v = "cyan", +-- --V = "cyan", +-- --["\22"] = "cyan", +-- --c = "orange", +-- --s = "purple", +-- --S = "purple", +-- --["\19"] = "purple", +-- --R = "orange", +-- --r = "orange", +-- --["!"] = "red", +-- --t = "red", +-- }, +-- }, +-- -- We can now access the value of mode() that, by now, would have been +-- -- computed by `init()` and use it to index our strings dictionary. +-- -- note how `static` fields become just regular attributes once the +-- -- component is instantiated. +-- -- To be extra meticulous, we can also add some vim statusline syntax to +-- -- control the padding and make sure our string is always at least 2 +-- -- characters long. Plus a nice Icon. +-- provider = function(self) +-- return " %2(" .. self.mode_names[self.mode] .. "%)" +-- --return " %2("..self.mode_names[self.mode].."%)" +-- -- +-- -- +-- -- +-- end, +-- -- Same goes for the highlight. Now the foreground will change according to the current mode. +-- hl = function(self) +-- local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { fg = self.mode_colors[mode], bold = true, } +-- return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +-- end, +-- -- Re-evaluate the component only on ModeChanged event! +-- -- This is not required in any way, but it's there, and it's a small +-- -- performance improvement. +-- update = { +-- "ModeChanged", +-- }, --optional +--} +local ViMode = { + static = { + mode_names = { -- change the strings if you like it vvvvverbose! + ["n"] = "NORMAL ", + ["no"] = "N·OPERATOR PENDING ", + ["v"] = "VISUAL ", + ["V"] = "V·LINE ", + [""] = "V·BLOCK ", + ["s"] = "SELECT ", + ["S"] = "S·LINE ", + [""] = "S·BLOCK ", + ["i"] = "INSERT ", + ["R"] = "REPLACE ", + ["Rv"] = "V·REPLACE ", + ["c"] = "COMMAND ", + ["cv"] = "VIM EX ", + ["ce"] = "EX ", + ["r"] = "PROMPT ", + ["rm"] = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + ["t"] = "TERMINAL ", + }, + }, + provider = function(self) + return " %2(" .. self.mode_names[vim.fn.mode(1)] .. "%)" + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color, fg = colors.bg, bold = true } + end, +} + +local ViModeColor = { + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + }, +} + +-- LSP + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = {'LspAttach', 'LspDetach'}, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +-- on_click = { +-- callback = function() +-- vim.defer_fn(function() +-- vim.cmd("LspInfo") +-- end, 100) +-- end, +-- name = "heirline_LSP", +-- }, +--} +-- +---- lsp status +---- I personally use it only to display progress messages! +---- See lsp-status/README.md for configuration options. +-- +---- Note: check "j-hui/fidget.nvim" for a nice statusline-free alternative. +--local LSPMessages = { +-- provider = require("lsp-status").status, +-- hl = { fg = "gray" }, +--} + +-- Nvim Navic +--local Navic = { +-- condition = require("nvim-navic").is_available, +-- provider = require("nvim-navic").get_location, +--} +--local Navic = utils.make_flexible_component(3, Navic, { provider = "" }) + +-- Full nerd (with icon colors)! +local Navic = { + condition = require("nvim-navic").is_available, + static = { + -- create a type highlight map + type_hl = { + File = "Directory", + Module = "Include", + Namespace = "TSNamespace", + Package = "Include", + Class = "Struct", + Method = "Method", + Property = "TSProperty", + Field = "TSField", + Constructor = "TSConstructor ", + Enum = "TSField", + Interface = "Type", + Function = "Function", + Variable = "TSVariable", + Constant = "Constant", + String = "String", + Number = "Number", + Boolean = "Boolean", + Array = "TSField", + Object = "Type", + Key = "TSKeyword", + Null = "Comment", + EnumMember = "TSField", + Struct = "Struct", + Event = "Keyword", + Operator = "Operator", + TypeParameter = "Type", + }, + }, + init = function(self) + local data = require("nvim-navic").get_data() or {} + local children = {} + -- create a child for each level + for i, d in ipairs(data) do + local child = { + { + provider = d.icon, + hl = self.type_hl[d.type], + }, + { + provider = d.name, + -- highlight icon only or location name as well + -- hl = self.type_hl[d.type], + }, + } + -- add a separator only if needed + if #data > 1 and i < #data then + table.insert(child, { + provider = " > ", + hl = { fg = "bright_fg" }, + }) + end + table.insert(children, child) + end + -- instantiate the new child, overwriting the previous one + self[1] = self:new(children, 1) + end, + hl = { fg = "gray" }, +} + +-- Diagnostics +local Diagnostics = { + + condition = conditions.has_diagnostics, + + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + + update = { "DiagnosticChanged", "BufEnter" }, + + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, + --{ + -- provider = "]", + --}, + on_click = { + callback = function() + require("trouble").toggle({ mode = "document_diagnostics" }) + -- or + -- vim.diagnostic.setqflist() + end, + name = "heirline_diagnostics", + }, +} + +-- Git +-- For the ones who're not (too) afraid of changes! Uses gitsigns. +local Git = { + condition = conditions.is_git_repo, + + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + --hl = { fg = "orange" }, + hl = { fg = colors.orange, bg = colors.bg }, + { -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + --hl = { bold = true }, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + --provider = "(" + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + --return count > 0 and ("+" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_add" }, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + --return count > 0 and ("-" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_del" }, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + --return count > 0 and ("~" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_change" }, + hl = { fg = colors.git.change, bg = colors.bg }, + }, + --{ + -- condition = function(self) + -- return self.has_changes + -- end, + -- provider = ")", + --}, + on_click = { + callback = function() + -- If you want to use Fugitive: + -- vim.cmd("G") + + -- If you prefer Lazygit + -- use vim.defer_fn() if the callback requires + -- opening of a floating window + -- (this also applies to telescope) + vim.defer_fn(function() + vim.cmd("Lazygit") + end, 100) + end, + name = "heirline_git", + }, +} + +-- Debugger +-- Display informations from nvim-dap! +local DAPMessages = { + -- display the dap messages only on the debugged file + condition = function() + local session = require("dap").session() + if session then + local filename = vim.api.nvim_buf_get_name(0) + if session.config then + local progname = session.config.program + return filename == progname + end + end + return false + end, + provider = function() + return " " .. require("dap").status() + end, + hl = { fg = utils.get_highlight("Debug").fg }, + -- Debugger on_click: step-over, step-into, next, previous, stop buttons + -- coming soon! +} + +-- Tests +-- This requires the great ultest. +--local UltTest = { +-- condition = function() +-- return vim .api.nvim_call_function("ultest#is_test_file", {}) ~= 0 +-- end, +-- static = { +-- passed_icon = vim.fn.sign_getdefined("test_pass")[1].text, +-- failed_icon = vim.fn.sign_getdefined("test_fail")[1].text, +-- passed_hl = { fg = utils.get_highlight("UltestPass").fg }, +-- failed_hl = { fg = utils.get_highlight("UltestFail").fg }, +-- }, +-- init = function(self) +-- self.status = vim.api.nvim_call_function("ultest#status", {}) +-- end, +-- +-- -- again, if you'd like icons and numbers to be colored differently, +-- -- just split the component in two +-- { +-- provider = function(self) +-- return self.passed_icon .. self.status.passed .. " " +-- end, +-- hl = function(self) +-- return self.passed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return self.failed_icon .. self.status.failed .. " " +-- end, +-- hl = function(self) +-- return self.failed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return "of " .. self.status.tests - 1 +-- end, +-- }, +--} + +-- FileName and Friends + +--local Align = { provider = "%=" } +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " ", hl = { bg = colors.bg } } +local fill = { provider = "%=", hl = { bg = colors.nobg } } +--local LeftSep = { provider = "" hl = { fg = colors.bg } } +--local RightSep = { provider = "" hl = { fg = colors.bg }} + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} +-- We can now define some children separately and add them later +-- + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + --return { fg = self.icon_color } + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "[No Name]" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + --hl = { fg = utils.get_highlight("Directory").fg, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return "" + end + end, + --hl = { fg = colors.orange }, + hl = { fg = colors.orange, bold = true, bg = colors.bg }, + }, +} +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + -- use `force` because we need to override the child's hl foreground + --return { fg = "cyan", bold = true, force = true } + return { fg = "blue", bold = true, force = true, bg = colors.bg } + end + end, +} + +-- FileType, FileEncoding and FileFormat +local FileType = { + provider = function() + -- return string.upper(vim.bo.filetype) + --end, + ----hl = { fg = utils.get_highlight("Type").fg, bold = true }, + --hl = { fg = utils.get_highlight("Type").fg, bold = true, bg = colors.bg }, + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +--local FileEncoding = { +-- provider = function() +-- local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' +-- return enc ~= "utf-8" and enc:upper() +-- end, +--} +local FileEncoding = { + Space, + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:upper() + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} + +local FileFormat = { + provider = function() + local fmt = vim.bo.fileformat + return fmt ~= "unix" and fmt:upper() + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- FileSize and FileLastModified +local FileSize = { + provider = function() + -- stackoverflow, compute human readable file size + local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) + fsize = (fsize < 0 and 0) or fsize + if fsize < 1024 then + return fsize .. suffix[1] + end + local i = math.floor((math.log(fsize) / math.log(1024))) + return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileLastModified = { + -- did you know? Vim is full of functions! + provider = function() + local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) + return (ftime > 0) and os.date("%c", ftime) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- Spell +-- Add indicator when spell is set! +local Spell = { + condition = function() + return vim.wo.spell + end, + provider = "SPELL ", + hl = { bold = true, fg = "orange" }, +} + +-- Cursor position: Ruler and ScrollBar +-- We're getting minimalists here! +local Ruler = { + -- We're getting minimalists here! + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + provider = "%3(%2l%):%c %P", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%3(%P%)", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%7 %p%% Ln %l, Col %c", + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} +--local ScrollBar = { +-- static = { +-- --sbar = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }, +-- sbar = { "🭶", "🭷", "🭸", "🭹", "🭺", "🭻" }, +-- }, +-- provider = function(self) +-- local curr_line = vim.api.nvim_win_get_cursor(0)[1] +-- local lines = vim.api.nvim_buf_line_count(0) +-- local i = math.floor((curr_line - 1) / lines * #self.sbar) + 1 +-- return string.rep(self.sbar[i], 2) +-- end, +-- --hl = { fg = "blue", bg = "bright_bg" }, +-- hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +--} +local WordCount = { + condition = function() + return conditions.buffer_matches({ + filetype = { + "markdown", + "txt", + "vimwiki", + }, + }) + end, + Space, + { + provider = function() + return "W:" .. vim.fn.wordcount().words + end, + }, +} + +local Position = { + Space, + { provider = "%l:%c" }, + hl = { bg = colors.bg }, +} + +local Percentage = { + Space, + { provider = "%p%%" }, + hl = { bg = colors.bg }, +} +-- Working Directory +local WorkDir = { + provider = function(self) + self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + local cwd = vim.fn.getcwd(0) + self.cwd = vim.fn.fnamemodify(cwd, ":~") + end, + --hl = { fg = "blue", bold = true }, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, + + utils.make_flexible_component(1, { + -- evaluates to the full-lenth path + provider = function(self) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. self.cwd .. trail .. " " + end, + }, { + -- evaluates to the shortened path + provider = function(self) + local cwd = vim.fn.pathshorten(self.cwd) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. cwd .. trail .. " " + end, + }, { + -- evaluates to "", hiding the component + provider = "", + }), +} + +-- Terminal Name +-- Special handling of the built-in terminal bufname. See conditional statuslines below to see an example of dedicated statusline for terminals! + +local TerminalName = { + -- we could add a condition to check that buftype == 'terminal' + -- or we could do that later (see #conditional-statuslines below) + provider = function() + local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") + return " " .. tname + end, + --hl = { fg = "blue", bold = true }, + hl = { bold = true, bg = colors.bg }, +} + +-- Snippets Indicator +-- This requires ultisnips +--local Snippets = { +-- -- check that we are in insert or select mode +-- condition = function() +-- return vim.tbl_contains({'s', 'i'}, vim.fn.mode()) +-- end, +-- provider = function() +-- local forward = (vim.fn["UltiSnips#CanJumpForwards"]() == 1) and "" or "" +-- local backward = (vim.fn["UltiSnips#CanJumpBackwards"]() == 1) and " " or "" +-- return backward .. forward +-- end, +-- hl = { fg = "red", bold = true }, +--} + +-- let's add the children to our FileNameBlock component +--FileNameBlock = utils.insert( +-- FileNameBlock, +--FileEncoding, +--Space, +--FileIcon, +--FileType, +--FileLastModified, +--FileSize, +--FileFormat, +--FileNameModifer, +-- unpack(FileFlags), +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + FileEncoding, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) +--FileNameBlock = utils.insert( +-- FileNameBlock, +-- FileIcon, +-- utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier +-- unpack(FileFlags), -- A small optimisation, since their parent does nothing +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) + +-- Statusline + +local Surrr = { + utils.surround({ "", "" }, "red", { + utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), + { provider = "Normal" }, + }), +} +--ViMode = utils.surround({ "", "" }, "bright_bg", { ViMode, Snippets }) +ViMode = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +--ViMode = utils.surround({ "◥", "" }, function(self) return self:mode_color() end, { +-- utils.surround({ "█", "" }, function(self) return self:mode_color() end, utils.surround({ "", "" }, function(self) return self:mode_color() end, { {provider = "normal" }, ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } )), +-- { provider = "heyya" }, +-- }) + +--utils.surround({ "█", "█" }, function(self) return self:mode_color() end, { FileNameBlock, hl = { fg = colors.bg, force = true } } ), +local DefaultStatusline = { + ViMode, + Space, + FileNameBlock, + Space, + Git, + Space, + Diagnostics, + Align, + Navic, + DAPMessages, + Align, + Space, + FileInfoBlock, + Space, + WordCount, + Ruler, + Space, + --Position, + --Percentage, + --ScrollBar, + --Space, + --LSPActive, Space, LSPMessages, Space, UltTest, Space, FileType, Space, Ruler, Space, ScrollBar +} + +--local InactiveStatusline = { +-- condition = conditions.is_not_active, +-- FileType, +-- Space, +-- FileName, +-- Align, +--} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + + FileType, + Space, + Align, + --FileType, Space, HelpFileName, Align +} + +local TerminalStatusline = { + + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + + hl = { bg = "dark_red" }, + + -- Quickly add a condition to the ViMode to only show it when buffer is active! + { condition = conditions.is_active, ViMode, Space }, + FileType, + Space, + TerminalName, + Align, +} + +--local StatusLines = { +-- +-- hl = function() +-- if conditions.is_active() then +-- return "StatusLine" +-- else +-- return "StatusLineNC" +-- end +-- end, +-- +-- -- the first statusline with no condition, or which condition returns true is used. +-- -- think of it as a switch case with breaks to stop fallthrough. +-- fallthrough = false, +-- +-- SpecialStatusline, +-- TerminalStatusline, +-- --InactiveStatusline, +-- DefaultStatusline, +--} +local StatusLines = { + + hl = function() + if conditions.is_active() then + return "StatusLine" + else + return "StatusLineNC" + end + end, + + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + }, + fallthrough = false, + + SpecialStatusline, + TerminalStatusline, + --InactiveStatusline, + DefaultStatusline, +} +--hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +-- hl = { bg = colors.bg }, +--require("heirline").setup(StatusLines) +-- we're done. + +--local FelineStyle = { +-- +-- -- stop at child where buftype/filetype/bufname matches +-- fallthrough = false, +-- +-- { -- Identify the buftype/filetype/bufname first +-- condtion = function() +-- return conditions.buffer_matches({...}) +-- end, +-- +-- -- Evaluate only the "active" or "inactive" child +-- fallthrough = false, +-- +-- { -- If it's the current window, display some components +-- condition = conditions.is_active +-- {...} -- +-- }, +-- { -- Otherwise, display some other components +-- {...} -- +-- } +-- }, +-- { -- this block can be exactly as the one above for a different kind of +-- -- buffer +-- ... +-- } +--} + +-- WinBar + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) +local active_middle_segment = { --{{{ + -- provider = "%999X %X", + + --provider = function(self) + -- --return " %999X %999X " + -- return " %2("..self.mode_names[self.mode].."%)" + -- -- + -- -- + -- -- + --end, + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + provider = "%f", + hl = function(self) + local color = self:mode_color() -- here! + return { fg = color } + end, + -- self.filename will be defined later, just keep looking at the example! + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, "dark_red", { + FileType, + Space, + TerminalName, + }), + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + --utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), + --utils.surround({ "", "" }, function(self) return self:mode_color() end, { FileNameBlock, hl = { fg = colors.bg, force = true } } ), + }, + -- A winbar for regular files + --utils.surround({ "", "" }, "bright_bg", FileNameBlock), + --█🙼🙽🙼█⮘██⮚ + --utils.surround({ "", "" }, function(self) return self:mode_color() end, { FileNameBlock, hl = function(self) + -- local color = self:mode_color() -- here! + -- return { bg = color, bold = true, force = true } + --end, + --}), + --utils.surround({ "", "" }, function(self) return self:mode_color() end, FileNameBlock), +} + +--utils.surround({ "", "" }, function(self) return self:mode_color() end, { active_middle_segment, hl = { fg = colors.bg, force = true } }) + +local WinBars = { + fill, + active_middle_segment, + fill, +} +-- --utils.surround({ " ", " " }, colors.nobg, { fill, active_middle_segment, fill }) +-- --static = { +-- -- mode_colors_map = { +-- -- n = colors.blue, +-- -- i = colors.green, +-- -- v = colors.purple, +-- -- V = colors.purple, +-- -- [""] = colors.purple, +-- -- c = colors.red, +-- -- s = colors.purple, +-- -- S = colors.purple, +-- -- [""] = colors.purple, +-- -- R = colors.orange, +-- -- r = colors.orange, +-- -- ["!"] = colors.red, +-- -- t = colors.red, +-- -- }, +-- -- mode_color = function(self) +-- -- local mode = conditions.is_active() and vim.fn.mode() or "n" +-- -- return self.mode_colors_map[mode] +-- -- end, +-- --}, +-- --utils.surround({ " ", " " }, colors.nobg, { active_middle_segment, hl = function(self) +-- -- local color = self:mode_color() -- here! +-- -- return { bg = color, bold = true, force = true } +-- --end, +-- --}) +--} +on_click = { + -- get the window id of the window in which the component was evaluated + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + -- winid is the window id of the window the component was clicked from + local winid = minwid + -- do something with the window id, e.g.: + local buf = vim.api.nvim_win_get_buf(winid) + -- ... + end, +} + +local CloseButton = { + condition = function(self) + return not vim.bo.modified + end, + -- a small performance improvement: + -- re register the component callback only on layout/buffer changes. + update = { "WinNew", "WinClosed", "BufEnter" }, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + vim.api.nvim_win_close(minwid, true) + end, + name = "heirline_winbar_close_button", + }, + }, +} + +-- Use it anywhere! +--local WinBarFileName = utils.surround({ "", "" }, "bright_bg", { +-- hl = function() +-- if not conditions.is_active() then +-- return { fg = "gray", force = true } +-- end +-- end, +-- FileNameBlock, +-- Space, +-- CloseButton, +--}) + +--local WinBars = { +-- -- init = utils.pick_child_on_condition, +-- fallthrough = false, +-- { +-- condition = function() +-- return conditions.buffer_matches({ +-- buftype = { "nofile", "prompt", "help", "quickfix" }, +-- filetype = { "^git.*", "fugitive" }, +-- }) +-- end, +-- init = function() +-- vim.opt_local.winbar = nil +-- end, +-- }, +-- { +-- condition = function() +-- return conditions.buffer_matches({ buftype = { "terminal" } }) +-- end, +-- utils.surround({ "", "" }, "dark_red", { +-- FileType, +-- Space, +-- TerminalName, +-- CloseButton, +-- }), +-- }, +-- utils.surround({ "", "" }, "bright_bg", { +-- hl = function() +-- if conditions.is_not_active() then +-- return { fg = "gray", force = true } +-- end +-- end, +-- +-- FileNameBlock, +-- CloseButton, +-- }), +--} + +-- TabLine +--local TabLine ={ +-- hl = { bg = colors.bg }, +--} +local TablineBufnr = { + provider = function(self) + return tostring(self.bufnr) .. ". " + end, + --hl = "Comment", + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "[No Name]" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +-- this looks exactly like the FileFlags component that we saw in +-- #crash-course-part-ii-filename-and-friends, but we are indexing the bufnr explicitly +-- also, we are adding a nice icon for terminal buffers. +--local TablineFileFlags = { +-- { +-- condition = function(self) +-- return vim.api.nvim_buf_get_option(self.bufnr, "modified") +-- end, +-- provider = "[+]", +-- --hl = { fg = colors.green }, +-- hl = { fg = colors.green, bold = true, bg = colors.bg }, +-- }, +-- { +-- condition = function(self) +-- return not vim.api.nvim_buf_get_option(self.bufnr, "modifiable") +-- or vim.api.nvim_buf_get_option(self.bufnr, "readonly") +-- end, +-- provider = function(self) +-- if vim.api.nvim_buf_get_option(self.bufnr, "buftype") == "terminal" then +-- return " " +-- else +-- return "" +-- end +-- end, +-- hl = { fg = "orange", bg = colors.bg }, +-- }, +--} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+]" + end + end, + hl = { fg = colors.green }, + }, + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return "" + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + -- why not? + --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then + --return { fg = "gray", bg = colors.bg } + else + return "TabLine" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = false }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineBufnr, + --FileIcon, -- turns out the version defined in #crash-course-part-ii-filename-and-friends can be reutilized as is here! + TablineFileIcon, + TablineFileName, + TablineFileFlags, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + end, + { provider = " " }, + { + provider = " ", + --hl = { fg = "red", bg = colors.bg }, + hl = { fg = "red" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +--local TablineBufferBlock = utils.surround({ "", "", hl = { bg =colors.bg } }, function(self) +-- if self.is_active then +-- return utils.get_highlight("TabLineSel").fg, utils.get_highlight("TabLineSel").bg +-- else +-- return utils.get_highlight("TabLine").fg, utils.get_highlight("TabLine").bg +-- end +----end, { TabLine, TablineFileNameBlock, TablineCloseButton }) +--end, { TablineFileNameBlock, TablineCloseButton }) + +--local TablineBufferBlock = utils.surround({ "█", "█" }, "bg", { +-- hl = function() +-- if not conditions.is_active() then +-- return { fg = "gray", force = true, bg = colors.bg } +-- end +-- end, +-- TablineFileNameBlock, +-- TablineCloseButton, +--}) +--local TablineBufferBlock = utils.surround({ "█", "█" }, +-- { hl = function(self) +-- local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { fg = self.mode_colors[mode], bold = true, } +-- return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +-- end, }, +--{ TablineFileNameBlock, TablineCloseButton, { hl = ViMode }, }) + +--local TablineBufferBlock = { +-- init = function(self) +-- +-- self.mode = vim.fn.mode(1) -- :h mode() +-- +-- vim.api.nvim_create_autocmd("ModeChanged", { +-- pattern = "*:*o", +-- command = "redrawstatus", +-- }) +-- self.once = true +-- end, +-- static = { +-- mode_colors = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- }, +-- }, +-- hl = function(self) +-- if self.is_active then +-- local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { fg = self.mode_colors[mode], bold = true, } +-- return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +-- else +-- return utils.get_highlight("TabLine").bg +-- end +-- end, +-- update = { +-- "ModeChanged", +-- }, --optional +-- { TablineFileNameBlock, TablineCloseButton } +--} + +--local TabLineSel = { +-- hl = { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +--} +--local ViMode2 = { +-- init = function(self) +-- self.mode = vim.fn.mode() +-- end, +-- static = { +-- mode_colors = { +-- n = "red", +-- i = "green", +-- v = "blue", +-- c = "orange" +-- +-- } +-- }, +-- provider = function(self) +-- return string.upper(self.mode) +-- end, +-- hl = function(self) +-- return { fg = self.mode_colors[self.mode], bold = true, } +-- end +--} +--local surrr = { +-- utils.surround({ "", "" }, "red", { +-- utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), +-- { provider = "Normal" }, +-- }), +--} +--local statusline = ViMode + +--local TablineBufferBlock = utils.surround({ "", "" }, function(self) +-- if self.is_active then +-- --self.mode = vim.fn.mode(1) -- :h mode() +-- +-- --return utils.get_highlight(vim.api.nvim_get_mode().mode).bg +-- return utils.get_highlight("TabLineSel").bg +-- --return utils.get_highlight("Normal").bg +-- --local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { bg = TabLineSel, fg = colors.bg, bold = true } +-- else +-- return utils.get_highlight("TabLine").bg +-- end +--end, { TablineFileNameBlock, TablineCloseButton }) + +local TablineBufferBlock = utils.surround({ "█", "▎" }, function(self) + --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLine").bg + end +end, { TablineFileNameBlock, TablineCloseButton }) +--█ +--local TablineBufferBlock = { +-- init = function(self) +-- self.mode = vim.fn.mode() +-- end, +-- static = { +-- mode_colors = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- }, +-- }, +-- hl = function(self) +-- if conditions.is_active() then +-- return { bg = self.mode_colors[self.mode], fg = colors.bg, bold = true } +-- else +-- return utils.get_highlight("Tabline").bg +-- end +-- end, +-- update = { +-- "ModeChanged", +-- }, --optional +-- { TablineFileNameBlock, TablineCloseButton }, +--} + +--local TablineBufferBlock = { +-- static = { +-- mode_colors_map = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- }, +-- mode_color = function(self) +-- local mode = conditions.is_active() and vim.fn.mode() or "n" +-- return self.mode_colors_map[mode] +-- end, +-- }, +-- { -- A special winbar for terminals +-- condition = function() +-- return conditions.buffer_matches({ buftype = { "terminal" } }) +-- end, +-- utils.surround({ "", "" }, "dark_red", { +-- FileType, +-- Space, +-- TerminalName, +-- }), +-- }, +-- { -- An inactive winbar for regular files +-- condition = function() +-- return conditions.is_not_active() +-- end, +-- utils.surround({ "█", "█" }, function() return utils.get_highlight("TabLine").bg end, { TablineFileNameBlock, TablineCloseButton } ) +-- }, +-- { +-- condition = function() +-- return conditions.is_active() +-- end, +-- utils.surround({ "█", "█" }, function(self) return self:mode_color() end, { TablineFileNameBlock, TablineCloseButton, hl = { fg = colors.bg, force = true } } ) +-- }, +--function() +--if self.is_active then +--utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), +--utils.surround({ "", "" }, function(self) return self:mode_color() end, { FileNameBlock, hl = { fg = colors.bg, force = true } } ), +--utils.surround({ "█", "█" }, function() return utils.get_highlight("TabLine").bg end, { TablineFileNameBlock, TablineCloseButton, hl = { fg = colors.bg, force = true } } ), +--} +--ViMode = utils.surround({ "", "" }, function(self) +-- if self.is_active then +-- return self:mode_color() +-- else +-- return utils.get_highlight("TabLine").bg +-- end +-- end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } ) +-- +----} +--local TablineBufferBlock = { +-- ViMode, +-- TablineFileName, +-- TablineCloseButton, +--} +-- A winbar for regular files +--utils.surround({ "", "" }, "bright_bg", FileNameBlock), +--utils.surround({ "", "" }, function(self) return self:mode_color() end, FileNameBlock), +local BufferLine = utils.make_buflist( + TablineBufferBlock, + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + --{ provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + --{ provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +-- if self.is_active then +-- return utils.get_highlight("TabLineSel").bg +-- else +-- return utils.get_highlight("TabLine").bg +-- end +--end, { TablineFileNameBlock, TablineCloseButton, } ) +-- TabList +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + --hl = "TabLine", + hl = { fg = colors.red, bg = colors.bg }, +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +-- TabLineOffset +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local TabLine = { + --hl = { bg = colors.bg }, + fallthrough = false, + TabLineOffset, + BufferLine, + TabPages, +} + +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) +--local StatusLines = { +-- +-- hl = function() +-- if conditions.is_active() then +-- return "StatusLine" +-- else +-- return "StatusLineNC" +-- end +-- end, +-- +-- -- the first statusline with no condition, or which condition returns true is used. +-- -- think of it as a switch case with breaks to stop fallthrough. +-- fallthrough = false, +-- +-- SpecialStatusline, +-- TerminalStatusline, +-- --InactiveStatusline, +-- DefaultStatusline, +--} +-- +-- --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +-- hl = { bg = colors.bg }, +--local TabLine ={ +-- hl = { bg = colors.bg }, +--} +-- Window Close button: Let the callback know from which window it was clicked from! +-- The following is the recommended way of achieving that: +require("heirline").setup(StatusLines, WinBars, TabLine) + +-- Yep, with heirline we're driving manual! +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +vim.api.nvim_create_augroup("Heirline", { clear = true }) +vim.api.nvim_create_autocmd("ColorScheme", { + callback = function() + local colors = setup_colors() + utils.on_colorscheme(colors) + end, + group = "Heirline", +}) + +local function get_bufs() + return vim.tbl_filter(function(bufnr) + return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted + end, vim.api.nvim_list_bufs()) +end + +local function goto_buf(index) + local bufs = get_bufs() + if index > #bufs then + index = #bufs + end + vim.api.nvim_win_set_buf(0, bufs[index]) +end + +local function addKey(key, index) + vim.keymap.set("", "<A-" .. key .. ">", function() + goto_buf(index) + end, { noremap = true, silent = true }) +end + +for i = 1, 9 do + addKey(i, i) +end +addKey("0", 10) +-- Theming +--local function setup_colors() +-- return { +-- bright_bg = utils.get_highlight("Folded").bg, +-- bright_fg = utils.get_highlight("Folded").fg, +-- red = utils.get_highlight("DiagnosticError").fg, +-- dark_red = utils.get_highlight("DiffDelete").bg, +-- green = utils.get_highlight("String").fg, +-- blue = utils.get_highlight("Function").fg, +-- gray = utils.get_highlight("NonText").fg, +-- orange = utils.get_highlight("Constant").fg, +-- purple = utils.get_highlight("Statement").fg, +-- cyan = utils.get_highlight("Special").fg, +-- diag_warn = utils.get_highlight("DiagnosticWarn").fg, +-- diag_error = utils.get_highlight("DiagnosticError").fg, +-- diag_hint = utils.get_highlight("DiagnosticHint").fg, +-- diag_info = utils.get_highlight("DiagnosticInfo").fg, +-- git_del = utils.get_highlight("diffDeleted").fg, +-- git_add = utils.get_highlight("diffAdded").fg, +-- git_change = utils.get_highlight("diffChanged").fg, +-- } +--end +--require('heirline').load_colors(setup_colors()) +-- +--vim.api.nvim_create_augroup("Heirline", { clear = true }) +--vim.api.nvim_create_autocmd("ColorScheme", { +-- callback = function() +-- local colors = setup_colors() +-- utils.on_colorscheme(colors) +-- end, +-- group = "Heirline", +--}) diff --git a/nvim/lua/plugins/heirline.lua b/nvim/lua/plugins/heirline.lua new file mode 100644 index 0000000..007f45a --- /dev/null +++ b/nvim/lua/plugins/heirline.lua @@ -0,0 +1,1124 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +local colors = { + --bg = "#23232e", + bg = nil, + nobg = nil, + white = "#f8f8f2", + darkgray = "#23232e", + gray = "#2d2b3a", + lightgray = "#d6d3ea", + pink = "#f92672", + green = "#50fa7b", + blue = "#39BAE6", + yellow = "#f1fa8c", + orange = "#ffb86c", + purple = "#BF40BF", + violet = "#7F00FF", + red = "#ff5555", + cyan = "#66d9eC", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +require("heirline").load_colors(colors) + +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " ", hl = { bg = colors.bg } } +local Tab = { provider = " " } +local Fill = { provider = "%=", hl = { bg = colors.nobg } } +local LeftSep = { provider = "", hl = { fg = colors.bg } } +local RightSep = { provider = "", hl = { fg = colors.bg } } + +local ViMode = { + init = function(self) + self.mode = vim.fn.mode(1) + if not self.once then + vim.cmd("au ModeChanged *:*o redrawstatus") + end + self.once = true + end, + static = { + mode_names = { + n = "NORMAL ", + no = "N·OPERATOR PENDING ", + nov = "N?", + noV = "N?", + ["no\22"] = "N? ", + niI = "Ni", + niR = "Nr", + niV = "Nv", + nt = "Nt", + v = "VISUAL ", + vs = "Vs", + V = "V·LINE ", + ["\22"] = "V·BLOCK ", + ["\22s"] = "V·BLOCK ", + s = "SELECT ", + S = "S·LINE ", + ["\19"] = "S·BLOCK ", + i = "INSERT ", + ix = "insert x ", + ic = "insert c ", + R = "REPLACE ", + Rc = "Rc", + Rx = "Rx", + Rv = "V·REPLACE ", + Rvc = "Rv", + Rvx = "Rv", + c = "COMMAND ", + cv = "VIM EX ", + ce = "EX ", + r = "PROMPT ", + rm = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + t = "TERMINAL ", + }, + }, + provider = function(self) + return " %2(" .. self.mode_names[self.mode] .. "%)" + end, + hl = function(self) + local color = self:mode_color() + return { fg = color, bold = true } + end, + update = { + "ModeChanged", + }, +} + +-- LSP +local LSPActive = { + condition = conditions.lsp_attached, + update = { "LspAttach", "LspDetach" }, + + provider = function() + local buf_clients = vim.lsp.buf_get_clients() + local buf_client_names = {} + + -- add client + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) + end + end + return "⚙️ " .. table.concat(buf_client_names, "") + end, + hl = { fg = colors.lightgray, bold = false }, +} + +-- Navic +local Navic = { + condition = require("nvim-navic").is_available, + static = { + -- create a type highlight map + type_hl = { + File = "Directory", + Module = "Include", + Namespace = "TSNamespace", + Package = "Include", + Class = "Struct", + Method = "Method", + Property = "TSProperty", + Field = "TSField", + Constructor = "TSConstructor ", + Enum = "TSField", + Interface = "Type", + Function = "Function", + Variable = "TSVariable", + Constant = "Constant", + String = "String", + Number = "Number", + Boolean = "Boolean", + Array = "TSField", + Object = "Type", + Key = "TSKeyword", + Null = "Comment", + EnumMember = "TSField", + Struct = "Struct", + Event = "Keyword", + Operator = "Operator", + TypeParameter = "Type", + }, + }, + init = function(self) + local data = require("nvim-navic").get_data() or {} + local children = {} + -- create a child for each level + for i, d in ipairs(data) do + local child = { + { + provider = d.icon, + hl = self.type_hl[d.type], + }, + { + provider = d.name, + -- highlight icon only or location name as well + -- hl = self.type_hl[d.type], + }, + } + -- add a separator only if needed + if #data > 1 and i < #data then + table.insert(child, { + provider = " > ", + hl = { fg = colors.white }, + }) + end + table.insert(children, child) + end + -- instantiate the new child, overwriting the previous one + self[1] = self:new(children, 1) + end, + hl = { fg = colors.white }, +} + +-- Diagnostics +local Diagnostics = { + + condition = conditions.has_diagnostics, + + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + + update = { "DiagnosticChanged", "BufEnter" }, + + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, + on_click = { + callback = function() + require("trouble").toggle({ mode = "document_diagnostics" }) + -- or + -- vim.diagnostic.setqflist() + end, + name = "heirline_diagnostics", + }, +} + +-- Git +-- For the ones who're not (too) afraid of changes! Uses gitsigns. +local Git = { + condition = conditions.is_git_repo, + + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + --hl = { fg = "orange" }, + hl = { fg = colors.orange, bg = colors.bg }, + { -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + --hl = { bold = true }, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + --provider = "(" + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + --return count > 0 and ("+" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_add" }, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + --return count > 0 and ("-" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_del" }, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + --return count > 0 and ("~" .. count) + return count > 0 and (" 柳" .. count) + end, + --hl = { fg = "git_change" }, + hl = { fg = colors.git.change, bg = colors.bg }, + }, + --{ + -- condition = function(self) + -- return self.has_changes + -- end, + -- provider = ")", + --}, + on_click = { + callback = function() + -- If you want to use Fugitive: + -- vim.cmd("G") + + -- If you prefer Lazygit + -- use vim.defer_fn() if the callback requires + -- opening of a floating window + -- (this also applies to telescope) + vim.defer_fn(function() + vim.cmd("Lazygit") + end, 100) + end, + name = "heirline_git", + }, +} + +-- Debugger +-- Display informations from nvim-dap! +local DAPMessages = { + -- display the dap messages only on the debugged file + condition = function() + local session = require("dap").session() + if session then + local filename = vim.api.nvim_buf_get_name(0) + if session.config then + local progname = session.config.program + return filename == progname + end + end + return false + end, + provider = function() + return " " .. require("dap").status() + end, + hl = { fg = utils.get_highlight("Debug").fg }, + -- Debugger on_click: step-over, step-into, next, previous, stop buttons + -- coming soon! +} + +-- Tests +-- This requires the great ultest. +--local UltTest = { +-- condition = function() +-- return vim .api.nvim_call_function("ultest#is_test_file", {}) ~= 0 +-- end, +-- static = { +-- passed_icon = vim.fn.sign_getdefined("test_pass")[1].text, +-- failed_icon = vim.fn.sign_getdefined("test_fail")[1].text, +-- passed_hl = { fg = utils.get_highlight("UltestPass").fg }, +-- failed_hl = { fg = utils.get_highlight("UltestFail").fg }, +-- }, +-- init = function(self) +-- self.status = vim.api.nvim_call_function("ultest#status", {}) +-- end, +-- +-- -- again, if you'd like icons and numbers to be colored differently, +-- -- just split the component in two +-- { +-- provider = function(self) +-- return self.passed_icon .. self.status.passed .. " " +-- end, +-- hl = function(self) +-- return self.passed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return self.failed_icon .. self.status.failed .. " " +-- end, +-- hl = function(self) +-- return self.failed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return "of " .. self.status.tests - 1 +-- end, +-- }, +--} + +-- FileNameBlock: FileIcon, FileName and friends +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} + +-- FileIcon, FileName, FileFlags and FileNameModifier +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "No Name" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, + hl = { fg = colors.white, bold = false, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" -- ±[+] + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return " " + end + end, + --hl = { fg = colors.orange }, + hl = { fg = colors.orange, bold = true, bg = colors.bg }, + }, +} + +local FileNameModifier = { + hl = function() + if vim.bo.modified then + return { fg = colors.green, bold = false, force = true } + end + end, +} + +-- FileType, FileEncoding and FileFormat +local FileType = { + provider = function() + return vim.bo.filetype + end, + hl = { fg = colors.white, bold = false, bg = colors.bg }, +} + +local FileEncoding = { + Space, + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:lower() + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg, bold = false }, +} + +local FileFormat = { + provider = function() + local fmt = vim.bo.fileformat + --return fmt ~= "unix" and fmt:upper() + return fmt ~= "unix" and fmt:lower() + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- FileSize and FileLastModified +local FileSize = { + provider = function() + -- stackoverflow, compute human readable file size + local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) + fsize = (fsize < 0 and 0) or fsize + if fsize < 1024 then + return fsize .. suffix[1] + end + local i = math.floor((math.log(fsize) / math.log(1024))) + return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileLastModified = { + -- did you know? Vim is full of functions! + provider = function() + local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) + return (ftime > 0) and os.date("%c", ftime) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- Spell +-- Add indicator when spell is set! +local Spell = { + condition = function() + return vim.wo.spell + end, + provider = " 暈", + hl = { bold = true, fg = colors.yellow }, +} + +local help_file_name = { + condition = function() + return vim.bo.filetype == "help" + end, + provider = function() + local filename = vim.api.nvim_buf_get_name(0) + return vim.fn.fnamemodify(filename, ":t") + end, + hl = { fg = colors.blue }, +} + +-- Cursor position: Ruler +local Ruler = { + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + --provider = "%P %(%l/%L%):%c ", + --provider = "%3(%2l%):%c %P ", + --provider = "%7(%l/%3L%):%2c%P ", + --provider = "%3(%P%)", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%7 %p%% Ln %l, Col %c", + --provider = "%9( %P %2l/%L :%2c %)", + --provider = "%9(%2l%2( : %c%)/%L %P %)", + --provider = "%7(%l:%c/%L%) ", + --provider = "%6(%l:%1.5c/%L%) %P ", + --provider = "%6(%l:%1.5c/%L%) ", + --provider = "%3(%l:%1.5c/%L%) ", + --provider = "%7(%l/%3L%):%2c ", + provider = "%7(%l:%c%) ", + --provider = "%l:%c ", + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, + hl = { fg = colors.darkgray, bold = true }, +} + +local cursor_location = { + { provider = "%l/%L|%c ", hl = { bold = true } }, + { + provider = " %P ", + hl = function(self) + local color = self:mode_color() + return { fg = color, bold = true } + end, + }, +} + +local WordCount = { + condition = function() + return conditions.buffer_matches({ + filetype = { + "markdown", + "txt", + "vimwiki", + }, + }) + end, + Space, + { + provider = function() + return "W:" .. vim.fn.wordcount().words + end, + }, +} + +-- Working Directory +local WorkDir = { + provider = function(self) + self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + local cwd = vim.fn.getcwd(0) + self.cwd = vim.fn.fnamemodify(cwd, ":~") + end, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, + + utils.make_flexible_component(1, { + -- evaluates to the full-lenth path + provider = function(self) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. self.cwd .. trail .. " " + end, + }, { + -- evaluates to the shortened path + provider = function(self) + local cwd = vim.fn.pathshorten(self.cwd) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. cwd .. trail .. " " + end, + }, { + -- evaluates to "", hiding the component + provider = "", + }), +} + +-- Snippets Indicator +-- This requires ultisnips +--local Snippets = { +-- -- check that we are in insert or select mode +-- condition = function() +-- return vim.tbl_contains({'s', 'i'}, vim.fn.mode()) +-- end, +-- provider = function() +-- local forward = (vim.fn["UltiSnips#CanJumpForwards"]() == 1) and "" or "" +-- local backward = (vim.fn["UltiSnips#CanJumpBackwards"]() == 1) and " " or "" +-- return backward .. forward +-- end, +-- hl = { fg = "red", bold = true }, +--} + +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifier, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +ViMode = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +LeftSpace = utils.surround({ "", " " }, function(self) + return self:mode_color() +end, { LeftSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +RightSpace = utils.surround( + { "", "" }, + colors.gray, + { RightSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } } +) + +RightSpace2 = utils.surround( + { "█", "" }, + colors.darkgray, + { RightSpace2, hl = { fg = colors.darkgray, force = true } } +) + +RightSpace3 = utils.surround( + { "█", "" }, + utils.get_highlight("statusline").bg, + { RightSpace3, hl = { fg = colors.darkgray, force = true } } +) + +LSPActive = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { Space, LSPActive, hl = { bg = colors.darkgray, force = true } }) + +FileInfoBlock = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { FileInfoBlock, Space, hl = { bg = colors.gray, force = true } }) + +Ruler = utils.surround({ "", "" }, colors.gray, { Ruler, hl = { fg = colors.gray, force = true } }) + +local left = { + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileNameBlock, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Git, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local middle = { + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Navic, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { DAPMessages, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local right = { + { Diagnostics, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { + RightSpace3, + hl = { bg = colors.darkgray, force = true }, + }, + { LSPActive, hl = { bg = colors.darkgray, force = true } }, + { RightSpace2, hl = { bg = colors.gray, force = true } }, + { FileInfoBlock, hl = { bg = colors.gray, force = true } }, + { RightSpace, hl = { fg = colors.gray, force = true } }, + --{ cursor_location, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + --utils.make_flexible_component( + -- 3, + -- { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + -- { provider = "%<" } + --), +} +--local Align = { provider = "%=", hl = { bg = colors.bg } } + +local sections = { left, middle, right } +local DefaultStatusline = { sections } +--LSPActive, Space, LSPMessages, Space, UltTest, Space, FileType, Space, Ruler, Space, ScrollBar + +local InactiveStatusline = { + condition = conditions.is_not_active, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileName, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + + --FileType, + --Space, + --Align, + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, +} + +local TerminalStatusline = { + + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + + --hl = { bg = colors.red }, + + -- Quickly add a condition to the ViMode to only show it when buffer is active! + --{ condition = conditions.is_active, ViMode, Space }, + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + --FileType, + --Space, + --TerminalName, + --Align, +} + +local StatusLine = { + + --hl = function() + -- if conditions.is_active() then + -- return "StatusLine" + -- else + -- return "StatusLineNC" + -- end + --end, + static = { + mode_colors = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + ["\22"] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + ["\19"] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors[mode] + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color } + end, + }, + fallthrough = false, + + SpecialStatusline, + TerminalStatusline, + InactiveStatusline, + DefaultStatusline, +} + +-- WinBar +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) + +On_click = { + -- get the window id of the window in which the component was evaluated + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + -- winid is the window id of the window the component was clicked from + local winid = minwid + -- do something with the window id, e.g.: + local buf = vim.api.nvim_win_get_buf(winid) + -- ... + end, +} + +local CloseButton = { + condition = function(self) + return not vim.bo.modified + end, + -- a small performance improvement: + -- re register the component callback only on layout/buffer changes. + update = { "WinNew", "WinClosed", "BufEnter" }, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + On_click = { + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + vim.api.nvim_win_close(minwid, true) + end, + name = "heirline_winbar_close_button", + }, + }, +} + +local Center = { + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + FileType, + Space, + --TerminalName, + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, colors.nobg, { Space }), + }, + -- A winbar for regular files + utils.surround({ "", "" }, colors.nobg, { FileNameBlock }), +} + +--local WinBar = { Align, Center, Align } +local WinBar = { Space, Center } + +-- TabLine +local TablineBufnr = { + provider = function(self) + return tostring(self.bufnr) .. "." + end, + hl = { fg = colors.white, bold = false }, +} + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "No Name" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { fg = colors.white, bold = self.is_active or self.is_visible, italic = true } + end, +} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+] " + end + end, + hl = { fg = colors.green }, + }, + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return " " + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + -- why not? + --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then + --return { fg = "gray", bg = colors.bg } + else + return "TabLineFill" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = false }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineBufnr, + TablineFileIcon, + TablineFileName, + TablineFileFlags, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + end, + { provider = " " }, + { + provider = " ", + --hl = { fg = "red", bg = colors.bg }, + hl = { fg = colors.red }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +local TablineBufferBlock = utils.surround({ "", "" }, function(self) + --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLineFill").bg + end +end, { Tab, TablineFileNameBlock, TablineCloseButton }) + +local BufferLine = utils.make_buflist( + TablineBufferBlock, + { provider = "⮘ ", hl = { fg = colors.white } }, -- left truncation, optional (defaults to "<") + { provider = " ⮚", hl = { fg = colors.white } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them and here's some + -- free icons ;) +) + +-- TabList +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLineFill" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + --hl = "TabLine", + hl = { fg = colors.red, bg = colors.bg }, +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { + provider = "%=", + }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +-- TabLineOffset +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.api.nvim_buf_get_option(bufnr, "filetype") == "NvimTree" then + self.title = "NvimTree" + return true + end + end, + + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "TablineFill" + end + end, +} + +local TabLine = { + TabLineOffset, + BufferLine, + TabPages, +} + +require("heirline").setup(StatusLine, WinBar, TabLine) + +-- Yep, with heirline we're driving manual! +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +local function get_bufs() + return vim.tbl_filter(function(bufnr) + return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted + end, vim.api.nvim_list_bufs()) +end + +local function goto_buf(index) + local bufs = get_bufs() + if index > #bufs then + index = #bufs + end + vim.api.nvim_win_set_buf(0, bufs[index]) +end + +local function addKey(key, index) + vim.keymap.set("", "<A-" .. key .. ">", function() + goto_buf(index) + end, { noremap = true, silent = true }) +end + +for i = 1, 9 do + addKey(i, i) +end +addKey("0", 10) diff --git a/nvim/lua/plugins/heirline.lua-202210111610.backup b/nvim/lua/plugins/heirline.lua-202210111610.backup new file mode 100644 index 0000000..e1a54e3 --- /dev/null +++ b/nvim/lua/plugins/heirline.lua-202210111610.backup @@ -0,0 +1,1452 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +local colors = { + --bg = "#23232e", + bg = nil, + nobg = nil, + bright_fg = "#ffffff", + bright_bg = "#000000", + white = "#f8f8f2", + --darkgray = "#1c1c29", + --darkgray = "#2d2b3a", + --darkgray = "#181818", + darkgray = "#23232e", + --darkgray = "#404040", + --gray = "#333842", + --gray = "#393547", + --gray = "#333842", + --lightgray = "#888888", + gray = "#2d2b3a", + lightgray = "#d6d3ea", + pink = "#f92672", + green = "#50fa7b", + blue = "#39BAE6", + yellow = "#f1fa8c", + orange = "#ffb86c", + ---purple = "#bd93f9", + ---purple = "#be2ed6", + purple = "#BF40BF", + --purple = "#5D3FD3", + --purple = "#DA70D6", + violet = "#7F00FF", + red = "#ff5555", + cyan = "#66d9eC", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +require("heirline").load_colors(colors) + +local ViMode = { + init = function(self) + self.mode = vim.fn.mode(1) + if not self.once then + vim.cmd("au ModeChanged *:*o redrawstatus") + end + self.once = true + end, + static = { + mode_names = { + n = "NORMAL ", + no = "N·OPERATOR PENDING ", + nov = "N?", + noV = "N?", + ["no\22"] = "N? ", + niI = "Ni", + niR = "Nr", + niV = "Nv", + nt = "Nt", + v = "VISUAL ", + vs = "Vs", + V = "V·LINE ", + ["\22"] = "V·BLOCK ", + ["\22s"] = "V·BLOCK ", + s = "SELECT ", + S = "S·LINE ", + ["\19"] = "S·BLOCK ", + i = "INSERT ", + ix = "insert x ", + ic = "insert c ", + R = "REPLACE ", + Rc = "Rc", + Rx = "Rx", + Rv = "V·REPLACE ", + Rvc = "Rv", + Rvx = "Rv", + c = "COMMAND ", + cv = "VIM EX ", + --ce = "EX ", + r = "PROMPT ", + rm = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + t = "TERMINAL ", + }, + }, + provider = function(self) + return " %2(" .. self.mode_names[self.mode] .. "%)" + end, + hl = function(self) + local color = self:mode_color() + return { fg = color, bold = true } + end, + update = { + "ModeChanged", + }, +} + +-- +-- +-- +-- +--凜兩 +-- LSP + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = {'LspAttach', 'LspDetach'}, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +-- on_click = { +-- callback = function() +-- vim.defer_fn(function() +-- vim.cmd("LspInfo") +-- end, 100) +-- end, +-- name = "heirline_LSP", +-- }, +--} + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = { "LspAttach", "LspDetach" }, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +--} + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- +-- provider = function() +-- local names = vim.tbl_values(vim.tbl_map(function(cl) +-- return cl.name +-- end, vim.lsp.buf_get_clients(0))) +-- +-- return "LSP " .. table.concat(names, " ") .. "" +-- end, +-- hl = { fg = colors.bg }, +--} +local LSPActive = { + condition = conditions.lsp_attached, + update = { "LspAttach", "LspDetach" }, + + -- You can keep it simple, + -- provider = " [LSP]", + + -- Or complicate things a bit and get the servers names + provider = function() + local buf_clients = vim.lsp.buf_get_clients() + local buf_ft = vim.bo.filetype + local buf_client_names = {} + + -- add client + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) + end + end + return "⚙️ " .. table.concat(buf_client_names, "") + --return table.concat(buf_client_names, " ") + --return "⚙️ " .. table.concat(buf_client_names, ", ") .. " " + --return " " .. table.concat(names, " ") .. " " + end, + hl = { fg = colors.lightgray, bold = false }, +} +--local LSPActive = { +-- function(msg) +-- msg = msg or "LS Inactive" +-- local buf_clients = vim.lsp.buf_get_clients() +-- if next(buf_clients) == nil then +-- if type(msg) == "boolean" or #msg == 0 then +-- return "LS Inactive" +-- end +-- return msg +-- end +-- +-- local buf_ft = vim.bo.filetype +-- local buf_client_names = {} +-- +-- -- add client +-- for _, client in pairs(buf_clients) do +-- if client.name ~= "null-ls" then +-- table.insert(buf_client_names, client.name) +-- end +-- end +-- +-- -- add formatter +-- local formatters = require("user.lsp.null-ls.formatters") +-- local supported_formatters = formatters.list_registered(buf_ft) +-- vim.list_extend(buf_client_names, supported_formatters) +-- +-- -- add linter +-- local linters = require("user.lsp.null-ls.linters") +-- local supported_linters = linters.list_registered(buf_ft) +-- vim.list_extend(buf_client_names, supported_linters) +-- +-- return table.concat(buf_client_names, " ") +-- -- return "[" .. table.concat(buf_client_names, ", ") .. "]" +-- end, +-- hl = { fg = colors.bg }, +--} +-- lsp status +-- I personally use it only to display progress messages! +-- See lsp-status/README.md for configuration options. + +-- Note: check "j-hui/fidget.nvim" for a nice statusline-free alternative. +local LSPMessages = { + provider = require("lsp-status").status, + hl = { fg = "gray" }, +} + +-- Nvim Navic +--local Navic = { +-- condition = require("nvim-navic").is_available, +-- provider = require("nvim-navic").get_location, +--} +--local Navic = utils.make_flexible_component(3, Navic, { provider = "" }) + +-- Full nerd (with icon colors)! +local Navic = { + condition = require("nvim-navic").is_available, + static = { + -- create a type highlight map + type_hl = { + File = "Directory", + Module = "Include", + Namespace = "TSNamespace", + Package = "Include", + Class = "Struct", + Method = "Method", + Property = "TSProperty", + Field = "TSField", + Constructor = "TSConstructor ", + Enum = "TSField", + Interface = "Type", + Function = "Function", + Variable = "TSVariable", + Constant = "Constant", + String = "String", + Number = "Number", + Boolean = "Boolean", + Array = "TSField", + Object = "Type", + Key = "TSKeyword", + Null = "Comment", + EnumMember = "TSField", + Struct = "Struct", + Event = "Keyword", + Operator = "Operator", + TypeParameter = "Type", + }, + }, + init = function(self) + local data = require("nvim-navic").get_data() or {} + local children = {} + -- create a child for each level + for i, d in ipairs(data) do + local child = { + { + provider = d.icon, + hl = self.type_hl[d.type], + }, + { + provider = d.name, + -- highlight icon only or location name as well + -- hl = self.type_hl[d.type], + }, + } + -- add a separator only if needed + if #data > 1 and i < #data then + table.insert(child, { + provider = " > ", + hl = { fg = "bright_fg" }, + }) + end + table.insert(children, child) + end + -- instantiate the new child, overwriting the previous one + self[1] = self:new(children, 1) + end, + hl = { fg = "gray" }, +} + +-- Diagnostics +local Diagnostics = { + + condition = conditions.has_diagnostics, + + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + + update = { "DiagnosticChanged", "BufEnter" }, + + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, + --{ + -- provider = "]", + --}, + on_click = { + callback = function() + require("trouble").toggle({ mode = "document_diagnostics" }) + -- or + -- vim.diagnostic.setqflist() + end, + name = "heirline_diagnostics", + }, +} + +-- Git +-- For the ones who're not (too) afraid of changes! Uses gitsigns. +local Git = { + condition = conditions.is_git_repo, + + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + --hl = { fg = "orange" }, + hl = { fg = colors.orange, bg = colors.bg }, + { -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + --hl = { bold = true }, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + --provider = "(" + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + --return count > 0 and ("+" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_add" }, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + --return count > 0 and ("-" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_del" }, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + --return count > 0 and ("~" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_change" }, + hl = { fg = colors.git.change, bg = colors.bg }, + }, + --{ + -- condition = function(self) + -- return self.has_changes + -- end, + -- provider = ")", + --}, + on_click = { + callback = function() + -- If you want to use Fugitive: + -- vim.cmd("G") + + -- If you prefer Lazygit + -- use vim.defer_fn() if the callback requires + -- opening of a floating window + -- (this also applies to telescope) + vim.defer_fn(function() + vim.cmd("Lazygit") + end, 100) + end, + name = "heirline_git", + }, +} + +-- Debugger +-- Display informations from nvim-dap! +local DAPMessages = { + -- display the dap messages only on the debugged file + condition = function() + local session = require("dap").session() + if session then + local filename = vim.api.nvim_buf_get_name(0) + if session.config then + local progname = session.config.program + return filename == progname + end + end + return false + end, + provider = function() + return " " .. require("dap").status() + end, + hl = { fg = utils.get_highlight("Debug").fg }, + -- Debugger on_click: step-over, step-into, next, previous, stop buttons + -- coming soon! +} + +-- Tests +-- This requires the great ultest. +--local UltTest = { +-- condition = function() +-- return vim .api.nvim_call_function("ultest#is_test_file", {}) ~= 0 +-- end, +-- static = { +-- passed_icon = vim.fn.sign_getdefined("test_pass")[1].text, +-- failed_icon = vim.fn.sign_getdefined("test_fail")[1].text, +-- passed_hl = { fg = utils.get_highlight("UltestPass").fg }, +-- failed_hl = { fg = utils.get_highlight("UltestFail").fg }, +-- }, +-- init = function(self) +-- self.status = vim.api.nvim_call_function("ultest#status", {}) +-- end, +-- +-- -- again, if you'd like icons and numbers to be colored differently, +-- -- just split the component in two +-- { +-- provider = function(self) +-- return self.passed_icon .. self.status.passed .. " " +-- end, +-- hl = function(self) +-- return self.passed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return self.failed_icon .. self.status.failed .. " " +-- end, +-- hl = function(self) +-- return self.failed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return "of " .. self.status.tests - 1 +-- end, +-- }, +--} + +-- FileName and Friends + +--local Align = { provider = "%=" } +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " ", hl = { bg = colors.bg } } +local Tab = { provider = " " } +local Fill = { provider = "%=", hl = { bg = colors.nobg } } +local LeftSep = { provider = "", hl = { fg = colors.bg } } +local RightSep = { provider = "", hl = { fg = colors.bg } } + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} +-- We can now define some children separately and add them later +-- + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "No Name" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + --±[+] + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return " " + end + end, + --hl = { fg = colors.orange }, + hl = { fg = colors.orange, bold = true, bg = colors.bg }, + }, +} +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + return { fg = colors.green, bold = false, force = true } + end + end, +} + +-- FileType, FileEncoding and FileFormat +local FileType = { + provider = function() + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +--local FileEncoding = { +-- provider = function() +-- local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' +-- return enc ~= "utf-8" and enc:upper() +-- end, +-- hl = { bg = colors.bg }, +--} +local FileEncoding = { + Space, + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:lower() + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg, bold = false }, +} + +local FileFormat = { + provider = function() + local fmt = vim.bo.fileformat + return fmt ~= "unix" and fmt:upper() + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- FileSize and FileLastModified +local FileSize = { + provider = function() + -- stackoverflow, compute human readable file size + local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) + fsize = (fsize < 0 and 0) or fsize + if fsize < 1024 then + return fsize .. suffix[1] + end + local i = math.floor((math.log(fsize) / math.log(1024))) + return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileLastModified = { + -- did you know? Vim is full of functions! + provider = function() + local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) + return (ftime > 0) and os.date("%c", ftime) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- Spell +-- Add indicator when spell is set! +local Spell = { + condition = function() + return vim.wo.spell + end, + provider = "SPELL ", + hl = { bold = true, fg = "orange" }, +} + +-- Cursor position: Ruler and ScrollBar +-- We're getting minimalists here! +local Ruler = { + -- We're getting minimalists here! + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + --provider = "%P %(%l/%L%):%c ", + --provider = "%3(%2l%):%c %P ", + --provider = "%7(%l/%3L%):%2c%P ", + --provider = "%3(%P%)", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%7 %p%% Ln %l, Col %c", + --provider = "%9( %P %2l/%L :%2c %)", + --provider = "%9(%2l%2( : %c%)/%L %P %)", + --provider = "%7(%l:%c/%L%) ", + --provider = "%6(%l:%1.5c/%L%) %P ", + provider = "%3(%l:%1.5c/%L%) ", + --provider = "%6(%l:%1.5c/%L%) ", + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +local Total = { + provider = "%L", + hl = { fg = utils.get_highlight("Statusline").fg, bold = false }, +} + +local WordCount = { + condition = function() + return conditions.buffer_matches({ + filetype = { + "markdown", + "txt", + "vimwiki", + }, + }) + end, + Space, + { + provider = function() + return "W:" .. vim.fn.wordcount().words + end, + }, +} + +local Position = { + Space, + { provider = "%l:%c" }, + hl = { bg = colors.bg }, +} + +local Percentage = { + Space, + { provider = "%P" }, + hl = { bg = colors.bg }, +} +-- Working Directory +local WorkDir = { + provider = function(self) + self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + local cwd = vim.fn.getcwd(0) + self.cwd = vim.fn.fnamemodify(cwd, ":~") + end, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, + + utils.make_flexible_component(1, { + -- evaluates to the full-lenth path + provider = function(self) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. self.cwd .. trail .. " " + end, + }, { + -- evaluates to the shortened path + provider = function(self) + local cwd = vim.fn.pathshorten(self.cwd) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. cwd .. trail .. " " + end, + }, { + -- evaluates to "", hiding the component + provider = "", + }), +} + +-- Terminal Name +-- Special handling of the built-in terminal bufname. See conditional statuslines below to see an example of dedicated statusline for terminals! + +--local TerminalName = { +-- -- we could add a condition to check that buftype == 'terminal' +-- -- or we could do that later (see #conditional-statuslines below) +-- provider = function() +-- local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") +-- return " " .. tname +-- end, +-- hl = { bold = true, bg = colors.bg }, +--} + +-- Snippets Indicator +-- This requires ultisnips +--local Snippets = { +-- -- check that we are in insert or select mode +-- condition = function() +-- return vim.tbl_contains({'s', 'i'}, vim.fn.mode()) +-- end, +-- provider = function() +-- local forward = (vim.fn["UltiSnips#CanJumpForwards"]() == 1) and "" or "" +-- local backward = (vim.fn["UltiSnips#CanJumpBackwards"]() == 1) and " " or "" +-- return backward .. forward +-- end, +-- hl = { fg = "red", bold = true }, +--} + +-- let's add the children to our FileNameBlock component +--FileNameBlock = utils.insert( +-- FileNameBlock, +--FileEncoding, +--Space, +--FileIcon, +--FileType, +--FileLastModified, +--FileSize, +--FileFormat, +--FileNameModifer, +-- unpack(FileFlags), +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) +--FileNameBlock = utils.insert( +-- FileNameBlock, +-- FileIcon, +-- utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier +-- unpack(FileFlags), -- A small optimisation, since their parent does nothing +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) + +local Surrr = { + utils.surround({ "", "" }, "red", { + utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), + { provider = "Normal" }, + }), +} +--ViMode = utils.surround({ "", "" }, "bright_bg", { ViMode, Snippets }) +--ViMode = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +--ViMode = utils.surround({ "◥", "" }, function(self) return self:mode_color() end, { +-- utils.surround({ "█", "" }, function(self) return self:mode_color() end, utils.surround({ "", "" }, function(self) return self:mode_color() end, { {provider = "normal" }, ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } )), +-- { provider = "heyya" }, +-- }) +-- Statusline +--BackgroundStatusline = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { BackgroundStatusline, hl = { bg = utils.get_highlight("statusline").bg, force = true } }) +-- +local Surrr = { + utils.surround({ "", "" }, "gray", { + FileInfoBlock, + hl = { bg = colors.gray }, + utils.surround({ "", "" }, "gray", { + Percentage, + utils.surround({ "", "" }, function(self) + return self:mode_color() + end, { Space, Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }), + }), + }), +} + +ViMode = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +LeftSpace = utils.surround({ "", " " }, function(self) + return self:mode_color() +end, { LeftSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +-- +RightSpace = utils.surround( + { "", "" }, + colors.gray, + { RightSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } } +) + +RightSpace2 = utils.surround( + { "█", "" }, + colors.darkgray, + { RightSpace2, hl = { fg = colors.darkgray, force = true } } +) + +RightSpace3 = utils.surround( + { "█", "" }, + utils.get_highlight("statusline").bg, + { RightSpace3, hl = { fg = colors.darkgray, force = true } } +) +--RightSpace = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +---- +-- +--Percentage = utils.surround({ "", " " }, "red", { Percentage, hl = { bg = colors.red, force = true } }) +-- + +LSPActive = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { Space, LSPActive, hl = { bg = colors.darkgray, force = true } }) + +FileInfoBlock = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { FileInfoBlock, Space, hl = { bg = colors.gray, force = true } }) + +Ruler = utils.surround({ "", "" }, colors.gray, { Space, Ruler, hl = { fg = colors.gray, force = true } }) + +local align = { provider = "%=" } +local left = { + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileNameBlock, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Git, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local middle = { + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Navic, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { DAPMessages, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local right = { + { Diagnostics, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { + RightSpace3, + hl = { bg = colors.darkgray, force = true }, + }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { LSPActive, hl = { bg = colors.darkgray, force = true } }, + --{ FileEncoding, hl = { bg = colors.orange, force = true } }, + { RightSpace2, hl = { bg = colors.gray, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileInfoBlock, hl = { bg = colors.gray, force = true } }, + --{ Space, hl = { bg = colors.red, force = true } }, + --{ FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ WordCount, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = colors.gray, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, +} + +local sections = { left, middle, right } +local DefaultStatusline = { sections } + +--local NewSpace = { provider = "", hl = { bg = utils.get_highlight("statusline").bg } } +--local statusline = { +--Space, +--Space, +--Git, +--Space, +--Diagnostics, +--Align, +--Navic, +--DAPMessages, +--Align, +--Space, +--FileInfoBlock, +--Space, +--WordCount, +--Ruler, +--LSPActive, Space, LSPMessages, Space, UltTest, Space, FileType, Space, Ruler, Space, ScrollBar +--} + +local InactiveStatusline = { + condition = conditions.is_not_active, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileName, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + + --FileType, + --Space, + --Align, + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + + --FileType, Space, HelpFileName, Align +} + +local TerminalStatusline = { + + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + + --hl = { bg = colors.red }, + + -- Quickly add a condition to the ViMode to only show it when buffer is active! + --{ condition = conditions.is_active, ViMode, Space }, + + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + --FileType, + --Space, + --TerminalName, + --Align, +} + +local StatusLine = { + + --hl = function() + -- if conditions.is_active() then + -- return "StatusLine" + -- else + -- return "StatusLineNC" + -- end + --end, + static = { + mode_colors = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + ["\22"] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + ["\19"] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + --mode_colors_map = { + -- n = colors.blue, + -- i = colors.green, + -- v = colors.purple, + -- V = colors.violet, + -- [""] = colors.red, + -- c = colors.yellow, + -- s = colors.orange, + -- S = colors.orange, + -- [""] = colors.purple, + -- R = colors.orange, + -- r = colors.orange, + -- ["!"] = colors.red, + -- t = colors.red, + }, + --mode_color = function(self) + -- local mode = conditions.is_active() and vim.fn.mode() or "n" + -- return self.mode_colors_map[mode] + --end, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors[mode] + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color } + end, + }, + fallthrough = false, + + SpecialStatusline, + TerminalStatusline, + InactiveStatusline, + DefaultStatusline, +} + +-- WinBar + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) + +on_click = { + -- get the window id of the window in which the component was evaluated + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + -- winid is the window id of the window the component was clicked from + local winid = minwid + -- do something with the window id, e.g.: + local buf = vim.api.nvim_win_get_buf(winid) + -- ... + end, +} + +local CloseButton = { + condition = function(self) + return not vim.bo.modified + end, + -- a small performance improvement: + -- re register the component callback only on layout/buffer changes. + update = { "WinNew", "WinClosed", "BufEnter" }, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + vim.api.nvim_win_close(minwid, true) + end, + name = "heirline_winbar_close_button", + }, + }, +} + +local active_middle_segment = { --{{{ + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + provider = "%f", + hl = function(self) + local color = self:mode_color() -- here! + return { fg = color } + end, + -- self.filename will be defined later, just keep looking at the example! + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + FileType, + Space, + --TerminalName, + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, colors.nobg, { hl = { fg = "gray", force = true }, FileNameBlock }), + }, +} + +--local WinBar = { +-- Fill, +-- active_middle_segment, +-- Fill, +--} +local WinBar = { + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + FileType, + Space, + --TerminalName, + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, colors.nobg, { hl = { fg = "gray", force = true }, FileNameBlock }), + }, + -- A winbar for regular files + utils.surround({ "", "" }, colors.nobg, FileNameBlock), +} + +-- TabLine +-- + +local TablineBufnr = { + provider = function(self) + return tostring(self.bufnr) .. "." + end, + --hl = "Comment", + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "No Name" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+] " + end + end, + hl = { fg = colors.green }, + }, + --+ + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return " " + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + -- why not? + --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then + --return { fg = "gray", bg = colors.bg } + else + return "TabLineFill" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = false }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineBufnr, + --FileIcon, -- turns out the version defined in #crash-course-part-ii-filename-and-friends can be reutilized as is here! + TablineFileIcon, + TablineFileName, + TablineFileFlags, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + end, + { provider = " " }, + { + provider = " ", + --hl = { fg = "red", bg = colors.bg }, + hl = { fg = "red" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +local TablineBufferBlock = utils.surround({ "", "" }, function(self) + --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLineFill").bg + end +end, { Tab, TablineFileNameBlock, TablineCloseButton }) + +local BufferLine = utils.make_buflist( + TablineBufferBlock, + --{ provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + --{ provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +-- TabList +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + --hl = "TabLine", + hl = { fg = colors.red, bg = colors.bg }, +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +-- TabLineOffset +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local TabLine = { + --hl = { bg = colors.bg }, + fallthrough = false, + TabLineOffset, + BufferLine, + TabPages, +} + +require("heirline").setup(StatusLine, WinBar, TabLine) +--require("heirline").setup(StatusLine, TabLine) + +-- Yep, with heirline we're driving manual! +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +--local function get_bufs() +-- return vim.tbl_filter(function(bufnr) +-- return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted +-- end, vim.api.nvim_list_bufs()) +--end +-- +--local function goto_buf(index) +-- local bufs = get_bufs() +-- if index > #bufs then +-- index = #bufs +-- end +-- vim.api.nvim_win_set_buf(0, bufs[index]) +--end +-- +--local function addKey(key, index) +-- vim.keymap.set("", "<A-" .. key .. ">", function() +-- goto_buf(index) +-- end, { noremap = true, silent = true }) +--end +-- +--for i = 1, 9 do +-- addKey(i, i) +--end +--addKey("0", 10) diff --git a/nvim/lua/plugins/heirlinenew.lua b/nvim/lua/plugins/heirlinenew.lua new file mode 100644 index 0000000..64a33b2 --- /dev/null +++ b/nvim/lua/plugins/heirlinenew.lua @@ -0,0 +1,1342 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +local colors = { + --bg = "#23232e", + bg = nil, + nobg = nil, + bright_fg = "#ffffff", + bright_bg = "#000000", + white = "#f8f8f2", + gray = "#23232e", + pink = "#f92672", + green = "#50fa7b", + blue = "#39BAE6", + yellow = "#f1fa8c", + orange = "#ffb86c", + purple = "#bd93f9", + red = "#ff5555", + cyan = "#66d9eC", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +require("heirline").load_colors(colors) + +--local function setup_colors() +-- return { +-- bright_bg = utils.get_highlight("Folded").bg, +-- bright_fg = utils.get_highlight("Folded").fg, +-- red = utils.get_highlight("DiagnosticError").fg, +-- dark_red = utils.get_highlight("DiffDelete").bg, +-- green = utils.get_highlight("String").fg, +-- blue = utils.get_highlight("Function").fg, +-- gray = utils.get_highlight("NonText").fg, +-- orange = utils.get_highlight("Constant").fg, +-- purple = utils.get_highlight("Statement").fg, +-- cyan = utils.get_highlight("Special").fg, +-- diag_warn = utils.get_highlight("DiagnosticWarn").fg, +-- diag_error = utils.get_highlight("DiagnosticError").fg, +-- diag_hint = utils.get_highlight("DiagnosticHint").fg, +-- diag_info = utils.get_highlight("DiagnosticInfo").fg, +-- git_del = utils.get_highlight("diffDeleted").fg, +-- git_add = utils.get_highlight("diffAdded").fg, +-- git_change = utils.get_highlight("diffChanged").fg, +-- } +--end +--require('heirline').load_colors(setup_colors()) +-- +--vim.api.nvim_create_augroup("Heirline", { clear = true }) +--vim.api.nvim_create_autocmd("ColorScheme", { +-- callback = function() +-- local colors = setup_colors() +-- utils.on_colorscheme(colors) +-- end, +-- group = "Heirline", +--}) + +local ViMode = { + static = { + mode_names = { -- change the strings if you like it vvvvverbose! + ["n"] = "NORMAL ", + ["no"] = "N·OPERATOR PENDING ", + ["v"] = "VISUAL ", + ["V"] = "V·LINE ", + [""] = "V·BLOCK ", + ["s"] = "SELECT ", + ["S"] = "S·LINE ", + [""] = "S·BLOCK ", + ["i"] = "INSERT ", + ["R"] = "REPLACE ", + ["Rv"] = "V·REPLACE ", + ["c"] = "COMMAND ", + ["cv"] = "VIM EX ", + ["ce"] = "EX ", + ["r"] = "PROMPT ", + ["rm"] = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + ["t"] = "TERMINAL ", + }, + }, + provider = function(self) + return " %2(" .. self.mode_names[vim.fn.mode(1)] .. "%)" + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color, fg = colors.bg, bold = true } + end, +} + +-- LSP + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = {'LspAttach', 'LspDetach'}, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +-- on_click = { +-- callback = function() +-- vim.defer_fn(function() +-- vim.cmd("LspInfo") +-- end, 100) +-- end, +-- name = "heirline_LSP", +-- }, +--} + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = { "LspAttach", "LspDetach" }, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +--} + +local LSPActive = { + condition = conditions.lsp_attached, + + provider = function() + local names = vim.tbl_values(vim.tbl_map(function(cl) + return cl.name + end, vim.lsp.buf_get_clients(0))) + + return "LSP [" .. table.concat(names, " ") .. "]" + end, + hl = { fg = colors.green }, +} +-- lsp status +-- I personally use it only to display progress messages! +-- See lsp-status/README.md for configuration options. + +-- Note: check "j-hui/fidget.nvim" for a nice statusline-free alternative. +local LSPMessages = { + provider = require("lsp-status").status, + hl = { fg = "gray" }, +} + +-- Nvim Navic +--local Navic = { +-- condition = require("nvim-navic").is_available, +-- provider = require("nvim-navic").get_location, +--} +--local Navic = utils.make_flexible_component(3, Navic, { provider = "" }) + +-- Full nerd (with icon colors)! +local Navic = { + condition = require("nvim-navic").is_available, + static = { + -- create a type highlight map + type_hl = { + File = "Directory", + Module = "Include", + Namespace = "TSNamespace", + Package = "Include", + Class = "Struct", + Method = "Method", + Property = "TSProperty", + Field = "TSField", + Constructor = "TSConstructor ", + Enum = "TSField", + Interface = "Type", + Function = "Function", + Variable = "TSVariable", + Constant = "Constant", + String = "String", + Number = "Number", + Boolean = "Boolean", + Array = "TSField", + Object = "Type", + Key = "TSKeyword", + Null = "Comment", + EnumMember = "TSField", + Struct = "Struct", + Event = "Keyword", + Operator = "Operator", + TypeParameter = "Type", + }, + }, + init = function(self) + local data = require("nvim-navic").get_data() or {} + local children = {} + -- create a child for each level + for i, d in ipairs(data) do + local child = { + { + provider = d.icon, + hl = self.type_hl[d.type], + }, + { + provider = d.name, + -- highlight icon only or location name as well + -- hl = self.type_hl[d.type], + }, + } + -- add a separator only if needed + if #data > 1 and i < #data then + table.insert(child, { + provider = " > ", + hl = { fg = "bright_fg" }, + }) + end + table.insert(children, child) + end + -- instantiate the new child, overwriting the previous one + self[1] = self:new(children, 1) + end, + hl = { fg = "gray" }, +} + +-- Diagnostics +local Diagnostics = { + + condition = conditions.has_diagnostics, + + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + + update = { "DiagnosticChanged", "BufEnter" }, + + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, + --{ + -- provider = "]", + --}, + on_click = { + callback = function() + require("trouble").toggle({ mode = "document_diagnostics" }) + -- or + -- vim.diagnostic.setqflist() + end, + name = "heirline_diagnostics", + }, +} + +-- Git +-- For the ones who're not (too) afraid of changes! Uses gitsigns. +local Git = { + condition = conditions.is_git_repo, + + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + --hl = { fg = "orange" }, + hl = { fg = colors.orange, bg = colors.bg }, + { -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + --hl = { bold = true }, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + --provider = "(" + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + --return count > 0 and ("+" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_add" }, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + --return count > 0 and ("-" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_del" }, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + --return count > 0 and ("~" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_change" }, + hl = { fg = colors.git.change, bg = colors.bg }, + }, + --{ + -- condition = function(self) + -- return self.has_changes + -- end, + -- provider = ")", + --}, + on_click = { + callback = function() + -- If you want to use Fugitive: + -- vim.cmd("G") + + -- If you prefer Lazygit + -- use vim.defer_fn() if the callback requires + -- opening of a floating window + -- (this also applies to telescope) + vim.defer_fn(function() + vim.cmd("Lazygit") + end, 100) + end, + name = "heirline_git", + }, +} + +-- Debugger +-- Display informations from nvim-dap! +local DAPMessages = { + -- display the dap messages only on the debugged file + condition = function() + local session = require("dap").session() + if session then + local filename = vim.api.nvim_buf_get_name(0) + if session.config then + local progname = session.config.program + return filename == progname + end + end + return false + end, + provider = function() + return " " .. require("dap").status() + end, + hl = { fg = utils.get_highlight("Debug").fg }, + -- Debugger on_click: step-over, step-into, next, previous, stop buttons + -- coming soon! +} + +-- Tests +-- This requires the great ultest. +--local UltTest = { +-- condition = function() +-- return vim .api.nvim_call_function("ultest#is_test_file", {}) ~= 0 +-- end, +-- static = { +-- passed_icon = vim.fn.sign_getdefined("test_pass")[1].text, +-- failed_icon = vim.fn.sign_getdefined("test_fail")[1].text, +-- passed_hl = { fg = utils.get_highlight("UltestPass").fg }, +-- failed_hl = { fg = utils.get_highlight("UltestFail").fg }, +-- }, +-- init = function(self) +-- self.status = vim.api.nvim_call_function("ultest#status", {}) +-- end, +-- +-- -- again, if you'd like icons and numbers to be colored differently, +-- -- just split the component in two +-- { +-- provider = function(self) +-- return self.passed_icon .. self.status.passed .. " " +-- end, +-- hl = function(self) +-- return self.passed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return self.failed_icon .. self.status.failed .. " " +-- end, +-- hl = function(self) +-- return self.failed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return "of " .. self.status.tests - 1 +-- end, +-- }, +--} + +-- FileName and Friends + +--local Align = { provider = "%=" } +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " ", hl = { bg = colors.bg } } +local Tab = { provider = " " } +local Fill = { provider = "%=", hl = { bg = colors.nobg } } +local LeftSep = { provider = "", hl = { fg = colors.bg } } +local RightSep = { provider = "", hl = { fg = colors.bg } } + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} +-- We can now define some children separately and add them later +-- + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "No Name" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + --±[+] + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return " " + end + end, + --hl = { fg = colors.orange }, + hl = { fg = colors.orange, bold = true, bg = colors.bg }, + }, +} +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + return { fg = colors.green, bold = false, force = true } + end + end, +} + +-- FileType, FileEncoding and FileFormat +local FileType = { + provider = function() + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +--local FileEncoding = { +-- provider = function() +-- local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' +-- return enc ~= "utf-8" and enc:upper() +-- end, +-- hl = { bg = colors.bg }, +--} +local FileEncoding = { + Space, + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:lower() + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg, bold = false }, +} + +local FileFormat = { + provider = function() + local fmt = vim.bo.fileformat + return fmt ~= "unix" and fmt:upper() + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- FileSize and FileLastModified +local FileSize = { + provider = function() + -- stackoverflow, compute human readable file size + local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) + fsize = (fsize < 0 and 0) or fsize + if fsize < 1024 then + return fsize .. suffix[1] + end + local i = math.floor((math.log(fsize) / math.log(1024))) + return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileLastModified = { + -- did you know? Vim is full of functions! + provider = function() + local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) + return (ftime > 0) and os.date("%c", ftime) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- Spell +-- Add indicator when spell is set! +local Spell = { + condition = function() + return vim.wo.spell + end, + provider = "SPELL ", + hl = { bold = true, fg = "orange" }, +} + +-- Cursor position: Ruler and ScrollBar +-- We're getting minimalists here! +local Ruler = { + -- We're getting minimalists here! + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + --provider = "%P %(%l/%L%):%c ", + --provider = "%3(%2l%):%c %P ", + --provider = "%7(%l/%3L%):%2c%P ", + --provider = "%3(%P%)", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%7 %p%% Ln %l, Col %c", + --provider = "%9( %P %2l/%L :%2c %)", + --provider = "%9(%2l%2( : %c%)/%L %P %)", + --provider = "%7(%l:%c/%L%) ", + --provider = "%6(%l:%1.5c/%L%) %P ", + provider = "%6(%l:%1.5c/%L%) ", + hl = { fg = utils.get_highlight("Statusline").fg, bold = false }, +} + +local WordCount = { + condition = function() + return conditions.buffer_matches({ + filetype = { + "markdown", + "txt", + "vimwiki", + }, + }) + end, + Space, + { + provider = function() + return "W:" .. vim.fn.wordcount().words + end, + }, +} + +local Position = { + Space, + { provider = "%l:%c" }, + hl = { bg = colors.bg }, +} + +local Percentage = { + Space, + { provider = "%P" }, + hl = { bg = colors.bg }, +} +-- Working Directory +local WorkDir = { + provider = function(self) + self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + local cwd = vim.fn.getcwd(0) + self.cwd = vim.fn.fnamemodify(cwd, ":~") + end, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, + + utils.make_flexible_component(1, { + -- evaluates to the full-lenth path + provider = function(self) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. self.cwd .. trail .. " " + end, + }, { + -- evaluates to the shortened path + provider = function(self) + local cwd = vim.fn.pathshorten(self.cwd) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. cwd .. trail .. " " + end, + }, { + -- evaluates to "", hiding the component + provider = "", + }), +} + +-- Terminal Name +-- Special handling of the built-in terminal bufname. See conditional statuslines below to see an example of dedicated statusline for terminals! + +local TerminalName = { + -- we could add a condition to check that buftype == 'terminal' + -- or we could do that later (see #conditional-statuslines below) + provider = function() + local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") + return " " .. tname + end, + hl = { bold = true, bg = colors.bg }, +} + +-- Snippets Indicator +-- This requires ultisnips +--local Snippets = { +-- -- check that we are in insert or select mode +-- condition = function() +-- return vim.tbl_contains({'s', 'i'}, vim.fn.mode()) +-- end, +-- provider = function() +-- local forward = (vim.fn["UltiSnips#CanJumpForwards"]() == 1) and "" or "" +-- local backward = (vim.fn["UltiSnips#CanJumpBackwards"]() == 1) and " " or "" +-- return backward .. forward +-- end, +-- hl = { fg = "red", bold = true }, +--} + +-- let's add the children to our FileNameBlock component +--FileNameBlock = utils.insert( +-- FileNameBlock, +--FileEncoding, +--Space, +--FileIcon, +--FileType, +--FileLastModified, +--FileSize, +--FileFormat, +--FileNameModifer, +-- unpack(FileFlags), +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) +--FileNameBlock = utils.insert( +-- FileNameBlock, +-- FileIcon, +-- utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier +-- unpack(FileFlags), -- A small optimisation, since their parent does nothing +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) + +local Surrr = { + utils.surround({ "", "" }, "red", { + utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), + { provider = "Normal" }, + }), +} +--ViMode = utils.surround({ "", "" }, "bright_bg", { ViMode, Snippets }) +--ViMode = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +--ViMode = utils.surround({ "◥", "" }, function(self) return self:mode_color() end, { +-- utils.surround({ "█", "" }, function(self) return self:mode_color() end, utils.surround({ "", "" }, function(self) return self:mode_color() end, { {provider = "normal" }, ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } )), +-- { provider = "heyya" }, +-- }) +-- Statusline +--BackgroundStatusline = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { BackgroundStatusline, hl = { bg = utils.get_highlight("statusline").bg, force = true } }) +-- +local Surrr = { + utils.surround({ "", "" }, "gray", { + FileInfoBlock, + hl = { bg = colors.gray }, + utils.surround({ "", "" }, "gray", { + Percentage, + utils.surround({ "", "" }, function(self) + return self:mode_color() + end, { Space, Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }), + }), + }), +} + +ViMode = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +LeftSpace = utils.surround({ "", " " }, function(self) + return self:mode_color() +end, { LeftSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +-- +RightSpace = utils.surround( + { "", "" }, + colors.red, + { RightSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } } +) + +RightSpace2 = utils.surround({ "", "" }, colors.orange, { RightSpace2, hl = { bg = colors.red, force = true } }) +--RightSpace = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +---- +-- +--Percentage = utils.surround({ "", " " }, "red", { Percentage, hl = { bg = colors.red, force = true } }) +-- + +LSPActive = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { Space, LSPActive, hl = { bg = colors.orange, force = true } }) + +FileInfoBlock = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { FileInfoBlock, Space, hl = { bg = colors.red, force = true } }) + +Ruler = utils.surround({ "", "" }, colors.red, { Space, Ruler, hl = { fg = colors.red, force = true } }) + +local align = { provider = "%=" } +local left = { + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileNameBlock, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Git, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local middle = { + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Navic, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { DAPMessages, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local right = { + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Diagnostics, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { LSPActive, hl = { bg = colors.orange, force = true } }, + --{ FileEncoding, hl = { bg = colors.orange, force = true } }, + { RightSpace2, hl = { fg = colors.orange, bg = colors.red, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileInfoBlock, hl = { bg = colors.red, force = true } }, + --{ Space, hl = { bg = colors.red, force = true } }, + --{ FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ WordCount, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = colors.red, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, +} + +local sections = { left, align, middle, align, right } +local DefaultStatusline = { sections } + +--local NewSpace = { provider = "", hl = { bg = utils.get_highlight("statusline").bg } } +--local statusline = { +--Space, +--Space, +--Git, +--Space, +--Diagnostics, +--Align, +--Navic, +--DAPMessages, +--Align, +--Space, +--FileInfoBlock, +--Space, +--WordCount, +--Ruler, +--LSPActive, Space, LSPMessages, Space, UltTest, Space, FileType, Space, Ruler, Space, ScrollBar +--} + +--local InactiveStatusline = { +-- condition = conditions.is_not_active, +-- FileType, +-- Space, +-- FileName, +-- Align, +--} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + + FileType, + Space, + Align, + --FileType, Space, HelpFileName, Align +} + +local TerminalStatusline = { + + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + + hl = { bg = "dark_red" }, + + -- Quickly add a condition to the ViMode to only show it when buffer is active! + { condition = conditions.is_active, ViMode, Space }, + FileType, + Space, + TerminalName, + Align, +} + +local StatusLine = { + + --hl = function() + -- if conditions.is_active() then + -- return "StatusLine" + -- else + -- return "StatusLineNC" + -- end + --end, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + --mode_colors_map = { + -- n = colors.blue, + -- i = colors.green, + -- v = colors.purple, + -- V = colors.violet, + -- [""] = colors.red, + -- c = colors.yellow, + -- s = colors.orange, + -- S = colors.orange, + -- [""] = colors.purple, + -- R = colors.orange, + -- r = colors.orange, + -- ["!"] = colors.red, + -- t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color } + end, + }, + fallthrough = false, + + SpecialStatusline, + TerminalStatusline, + --InactiveStatusline, + DefaultStatusline, +} + +-- WinBar + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) + +on_click = { + -- get the window id of the window in which the component was evaluated + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + -- winid is the window id of the window the component was clicked from + local winid = minwid + -- do something with the window id, e.g.: + local buf = vim.api.nvim_win_get_buf(winid) + -- ... + end, +} + +local CloseButton = { + condition = function(self) + return not vim.bo.modified + end, + -- a small performance improvement: + -- re register the component callback only on layout/buffer changes. + update = { "WinNew", "WinClosed", "BufEnter" }, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + vim.api.nvim_win_close(minwid, true) + end, + name = "heirline_winbar_close_button", + }, + }, +} + +local active_middle_segment = { --{{{ + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + provider = "%f", + hl = function(self) + local color = self:mode_color() -- here! + return { fg = color } + end, + -- self.filename will be defined later, just keep looking at the example! + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, "dark_red", { + FileType, + Space, + TerminalName, + }), + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), + }, +} + +--local WinBar = { +-- Fill, +-- active_middle_segment, +-- Fill, +--} +local WinBar = { + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, "dark_red", { + FileType, + Space, + TerminalName, + }), + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), + }, + -- A winbar for regular files + utils.surround({ "", "" }, "bright_bg", FileNameBlock), +} + +-- TabLine +-- + +local TablineBufnr = { + provider = function(self) + return tostring(self.bufnr) .. "." + end, + --hl = "Comment", + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "No Name" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+] " + end + end, + hl = { fg = colors.green }, + }, + --+ + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return " " + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + -- why not? + --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then + --return { fg = "gray", bg = colors.bg } + else + return "TabLineFill" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = false }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineBufnr, + --FileIcon, -- turns out the version defined in #crash-course-part-ii-filename-and-friends can be reutilized as is here! + TablineFileIcon, + TablineFileName, + TablineFileFlags, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + end, + { provider = " " }, + { + provider = " ", + --hl = { fg = "red", bg = colors.bg }, + hl = { fg = "red" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +local TablineBufferBlock = utils.surround({ "", "" }, function(self) + --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLineFill").bg + end +end, { Tab, TablineFileNameBlock, TablineCloseButton }) + +local BufferLine = utils.make_buflist( + TablineBufferBlock, + --{ provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + --{ provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +-- TabList +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + --hl = "TabLine", + hl = { fg = colors.red, bg = colors.bg }, +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +-- TabLineOffset +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local TabLine = { + --hl = { bg = colors.bg }, + fallthrough = false, + TabLineOffset, + BufferLine, + TabPages, +} + +require("heirline").setup(StatusLine, WinBar, TabLine) +--require("heirline").setup(StatusLine, TabLine) + +-- Yep, with heirline we're driving manual! +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +--local function get_bufs() +-- return vim.tbl_filter(function(bufnr) +-- return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted +-- end, vim.api.nvim_list_bufs()) +--end +-- +--local function goto_buf(index) +-- local bufs = get_bufs() +-- if index > #bufs then +-- index = #bufs +-- end +-- vim.api.nvim_win_set_buf(0, bufs[index]) +--end +-- +--local function addKey(key, index) +-- vim.keymap.set("", "<A-" .. key .. ">", function() +-- goto_buf(index) +-- end, { noremap = true, silent = true }) +--end +-- +--for i = 1, 9 do +-- addKey(i, i) +--end +--addKey("0", 10) diff --git a/nvim/lua/plugins/linecolor.lua b/nvim/lua/plugins/linecolor.lua new file mode 100644 index 0000000..37550dd --- /dev/null +++ b/nvim/lua/plugins/linecolor.lua @@ -0,0 +1,112 @@ +--local M = {} +--M.theme = function() +-- -- I know I could just set bg = nil but I'm leaving this here in case I want custom colors in the future +-- local colors = { +-- nobg = nil, +-- blue = "#87b0f9", +-- mauve = "#cba6f7", +-- red = "#f38ba8", +-- green = "#a6e3a1", +-- peach = "#fab387", +-- white = "#c6d0f5", +-- gray = "#a1a8c9", +-- black = "#1e1e2e", +-- } +-- return { +-- inactive = { +-- a = { fg = colors.blue, bg = colors.nobg, gui = "bold" }, +-- b = { fg = colors.white, bg = colors.black }, +-- c = { fg = colors.gray, bg = colors.nobg }, +-- }, +-- visual = { +-- a = { fg = colors.black, bg = colors.mauve, gui = "bold" }, +-- b = { fg = colors.mauve, bg = colors.nobg }, +-- c = { fg = colors.white, bg = colors.nobg }, +-- }, +-- replace = { +-- a = { fg = colors.black, bg = colors.red, gui = "bold" }, +-- b = { fg = colors.red, bg = colors.nobg }, +-- c = { fg = colors.white, bg = colors.nobg }, +-- }, +-- normal = { +-- a = { fg = colors.black, bg = colors.blue, gui = "bold" }, +-- b = { fg = colors.black, bg = colors.green }, +-- c = { fg = colors.white, bg = colors.black }, +-- }, +-- insert = { +-- a = { fg = colors.black, bg = colors.green, gui = "bold" }, +-- b = { fg = colors.teal, bg = colors.nobg }, +-- c = { fg = colors.white, bg = colors.nobg }, +-- }, +-- command = { +-- a = { fg = colors.black, bg = colors.peach, gui = "bold" }, +-- b = { fg = colors.peach, bg = colors.nobg }, +-- c = { fg = colors.white, bg = colors.nobg }, +-- }, +-- modified = { +-- a = { fg = colors.black, bg = colors.peach, gui = "bold" }, +-- b = { fg = colors.peach, bg = colors.peach }, +-- c = { fg = colors.white, bg = colors.peach }, +-- }, +-- } +--end +--return M +local M = {} +M.theme = function() + --local colors = { + -- darkgray = "#16161d", + -- gray = "#727169", + -- innerbg = nil, + -- outerbg = "#16161D", + -- normal = "#7e9cd8", + -- insert = "#98bb6c", + -- visual = "#ffa066", + -- replace = "#e46876", + -- command = "#e6c384", + --} + local colors = { + darkgray = "#16161d", + gray = "#727169", + innerbg = nil, + outerbg = "#16161D", + normal = "#39BAE6", + insert = "#AAD94C", + visual = "#FA8D3F", + replace = "#F07171", + command = "#F2AE49", + } + return { + inactive = { + a = { fg = colors.gray, bg = colors.outerbg, gui = "bold" }, + b = { fg = colors.gray, bg = colors.outerbg }, + c = { fg = colors.gray, bg = colors.innerbg }, + }, + visual = { + a = { fg = colors.darkgray, bg = colors.visual, gui = "bold" }, + b = { fg = colors.gray, bg = colors.outerbg }, + c = { fg = colors.gray, bg = colors.innerbg }, + }, + replace = { + a = { fg = colors.darkgray, bg = colors.replace, gui = "bold" }, + b = { fg = colors.gray, bg = colors.outerbg }, + c = { fg = colors.gray, bg = colors.innerbg }, + }, + normal = { + a = { fg = colors.darkgray, bg = colors.normal, gui = "bold" }, + b = { fg = colors.gray, bg = colors.outerbg }, + c = { fg = colors.gray, bg = colors.innerbg }, + y = { fg = colors.gray, bg = colors.outerbg }, + }, + insert = { + a = { fg = colors.darkgray, bg = colors.insert, gui = "bold" }, + b = { fg = colors.gray, bg = colors.outerbg }, + c = { fg = colors.gray, bg = colors.innerbg }, + }, + command = { + a = { fg = colors.darkgray, bg = colors.command, gui = "bold" }, + b = { fg = colors.gray, bg = colors.outerbg }, + c = { fg = colors.gray, bg = colors.innerbg }, + }, + } +end +return M diff --git a/nvim/lua/plugins/lsp-22.10.12-21:29-bak-22.10.12-23:45-bak.lua b/nvim/lua/plugins/lsp-22.10.12-21:29-bak-22.10.12-23:45-bak.lua new file mode 100644 index 0000000..dd25d9a --- /dev/null +++ b/nvim/lua/plugins/lsp-22.10.12-21:29-bak-22.10.12-23:45-bak.lua @@ -0,0 +1,301 @@ +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({ + single_file_support = true, + on_attach = function(client, bufnr) + print('hello') + lspconfig.util.default_config.on_attach(client, bufnr) + end +}) + +vim.api.nvim_create_autocmd('User', { + pattern = 'LspAttached', + desc = 'LSP actions', + callback = function() + local bufmap = function(mode, lhs, rhs) + local opts = {buffer = true} + vim.keymap.set(mode, lhs, rhs, opts) + end + + -- Displays hover information about the symbol under the cursor + bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>') + + -- Jump to the definition + bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>') + + -- Jump to declaration + bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>') + + -- Lists all the implementations for the symbol under the cursor + bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>') + + -- Jumps to the definition of the type symbol + bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>') + + -- Lists all the references + bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>') + + -- Displays a function's signature information + bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>') + + -- Renames all references to the symbol under the cursor + bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>') + + -- Selects a code action available at the current cursor position + bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>') + bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>') + + -- Show diagnostics in a floating window + bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>') + + -- Move to the previous diagnostic + bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>') + + -- Move to the next diagnostic + bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>') + end +}) + +-- +---Snippets +-- +require('luasnip.loaders.from_vscode').lazy_load() + +-- +--- Autocompletion/nvim-cmp +-- +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} -- Suggested values for completeopt +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + +}) + +snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end +}, + +sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, +}, + +window = { + documentation = cmp.config.window.bordered() +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'} +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, +}, + +mapping = { + ['<CR>'] = cmp.mapping.confirm({select = true}), +} +['<Up>'] = cmp.mapping.select_prev_item(select_opts), +['<Down>'] = cmp.mapping.select_next_item(select_opts), + +['<C-p>'] = cmp.mapping.select_prev_item(select_opts), +['<C-n>'] = cmp.mapping.select_next_item(select_opts), +['<C-u>'] = cmp.mapping.scroll_docs(-4), +['<C-f>'] = cmp.mapping.scroll_docs(4), +['<C-e>'] = cmp.mapping.abort(), +['<CR>'] = cmp.mapping.confirm({select = true}), +['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end +end, {'i', 's'}), +['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end +end, {'i', 's'}), + +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} + +require('luasnip.loaders.from_vscode').lazy_load() + +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + }, + window = { + documentation = cmp.config.window.bordered() + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, + }, + mapping = { + ['<Up>'] = cmp.mapping.select_prev_item(select_opts), + ['<Down>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-p>'] = cmp.mapping.select_prev_item(select_opts), + ['<C-n>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-u>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + + ['<C-e>'] = cmp.mapping.abort(), + ['<CR>'] = cmp.mapping.confirm({select = true}), + + ['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, {'i', 's'}), + + ['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, {'i', 's'}), + + ['<Tab>'] = cmp.mapping(function(fallback) + local col = vim.fn.col('.') - 1 + + if cmp.visible() then + cmp.select_next_item(select_opts) + elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + fallback() + else + cmp.complete() + end + end, {'i', 's'}), + + ['<S-Tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item(select_opts) + else + fallback() + end + end, {'i', 's'}), + }, +}) + + +vim.diagnostic.config({ + virtual_text = false, + severity_sort = true, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + {border = 'rounded'} +) + +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + {border = 'rounded'} +) + +require('mason').setup() +require('mason-lspconfig').setup() + + +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({}) + + + + + + + + diff --git a/nvim/lua/plugins/lsp-22.10.12-21:29-bak.lua b/nvim/lua/plugins/lsp-22.10.12-21:29-bak.lua new file mode 100644 index 0000000..dd25d9a --- /dev/null +++ b/nvim/lua/plugins/lsp-22.10.12-21:29-bak.lua @@ -0,0 +1,301 @@ +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({ + single_file_support = true, + on_attach = function(client, bufnr) + print('hello') + lspconfig.util.default_config.on_attach(client, bufnr) + end +}) + +vim.api.nvim_create_autocmd('User', { + pattern = 'LspAttached', + desc = 'LSP actions', + callback = function() + local bufmap = function(mode, lhs, rhs) + local opts = {buffer = true} + vim.keymap.set(mode, lhs, rhs, opts) + end + + -- Displays hover information about the symbol under the cursor + bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>') + + -- Jump to the definition + bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>') + + -- Jump to declaration + bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>') + + -- Lists all the implementations for the symbol under the cursor + bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>') + + -- Jumps to the definition of the type symbol + bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>') + + -- Lists all the references + bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>') + + -- Displays a function's signature information + bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>') + + -- Renames all references to the symbol under the cursor + bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>') + + -- Selects a code action available at the current cursor position + bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>') + bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>') + + -- Show diagnostics in a floating window + bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>') + + -- Move to the previous diagnostic + bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>') + + -- Move to the next diagnostic + bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>') + end +}) + +-- +---Snippets +-- +require('luasnip.loaders.from_vscode').lazy_load() + +-- +--- Autocompletion/nvim-cmp +-- +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} -- Suggested values for completeopt +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + +}) + +snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end +}, + +sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, +}, + +window = { + documentation = cmp.config.window.bordered() +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'} +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, +}, + +mapping = { + ['<CR>'] = cmp.mapping.confirm({select = true}), +} +['<Up>'] = cmp.mapping.select_prev_item(select_opts), +['<Down>'] = cmp.mapping.select_next_item(select_opts), + +['<C-p>'] = cmp.mapping.select_prev_item(select_opts), +['<C-n>'] = cmp.mapping.select_next_item(select_opts), +['<C-u>'] = cmp.mapping.scroll_docs(-4), +['<C-f>'] = cmp.mapping.scroll_docs(4), +['<C-e>'] = cmp.mapping.abort(), +['<CR>'] = cmp.mapping.confirm({select = true}), +['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end +end, {'i', 's'}), +['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end +end, {'i', 's'}), + +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} + +require('luasnip.loaders.from_vscode').lazy_load() + +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + }, + window = { + documentation = cmp.config.window.bordered() + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, + }, + mapping = { + ['<Up>'] = cmp.mapping.select_prev_item(select_opts), + ['<Down>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-p>'] = cmp.mapping.select_prev_item(select_opts), + ['<C-n>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-u>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + + ['<C-e>'] = cmp.mapping.abort(), + ['<CR>'] = cmp.mapping.confirm({select = true}), + + ['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, {'i', 's'}), + + ['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, {'i', 's'}), + + ['<Tab>'] = cmp.mapping(function(fallback) + local col = vim.fn.col('.') - 1 + + if cmp.visible() then + cmp.select_next_item(select_opts) + elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + fallback() + else + cmp.complete() + end + end, {'i', 's'}), + + ['<S-Tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item(select_opts) + else + fallback() + end + end, {'i', 's'}), + }, +}) + + +vim.diagnostic.config({ + virtual_text = false, + severity_sort = true, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + {border = 'rounded'} +) + +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + {border = 'rounded'} +) + +require('mason').setup() +require('mason-lspconfig').setup() + + +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({}) + + + + + + + + diff --git a/nvim/lua/plugins/lsp-colors.lua b/nvim/lua/plugins/lsp-colors.lua new file mode 100644 index 0000000..1398123 --- /dev/null +++ b/nvim/lua/plugins/lsp-colors.lua @@ -0,0 +1,9 @@ +local status, colors = pcall(require, "lsp-colors") +if (not status) then return end + +colors.setup { + Error = "#db4b4b", + Warning = "#e0af68", + Information = "#0db9d7", + Hint = "#10B981" +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..59bb3f4 --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,231 @@ +local fn = vim.fn +local keymap = vim.keymap + +local utils = require("utils") + +local custom_attach = function(client, bufnr) + -- Mappings. + local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.buffer = bufnr + keymap.set(mode, l, r, opts) + end + + map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) + map("n", "<C-]>", vim.lsp.buf.definition) + map("n", "K", vim.lsp.buf.hover) + map("n", "<C-k>", vim.lsp.buf.signature_help) + map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) + map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) + map("n", "[d", vim.diagnostic.goto_prev, { desc = "previous diagnostic" }) + map("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic" }) + map("n", "<space>q", function() + vim.diagnostic.setqflist({ open = true }) + end, { desc = "put diagnostic to qf" }) +-- map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) +-- map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) +-- map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) +-- map("n", "<space>wl", function() +-- inspect(vim.lsp.buf.list_workspace_folders()) +-- end, { desc = "list workspace folder" }) + + -- Set some key bindings conditional on server capabilities + if client.server_capabilities.documentFormattingProvider then + map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" }) + end + + vim.api.nvim_create_autocmd("CursorHold", { + buffer = bufnr, + callback = function() + local float_opts = { + focusable = false, + close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, + border = "rounded", + source = "always", -- show source in diagnostic popup window + prefix = " ", + } + + if not vim.b.diagnostics_pos then + vim.b.diagnostics_pos = { nil, nil } + end + + local cursor_pos = vim.api.nvim_win_get_cursor(0) + if + (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) + and #vim.diagnostic.get() > 0 + then + vim.diagnostic.open_float(nil, float_opts) + end + + vim.b.diagnostics_pos = cursor_pos + end, + }) + + -- The below command will highlight the current variable and its usages in the buffer. + if client.server_capabilities.documentHighlightProvider then + vim.cmd([[ + hi! link LspReferenceRead Visual + hi! link LspReferenceText Visual + hi! link LspReferenceWrite Visual + augroup lsp_document_highlight + autocmd! * <buffer> + autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() + autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() + augroup END + ]]) + end + + if vim.g.logging_level == "debug" then + local msg = string.format("Language server %s started!", client.name) + vim.notify(msg, vim.log.levels.DEBUG, { title = "Server?" }) + end +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) +capabilities.textDocument.completion.completionItem.snippetSupport = true + +local lspconfig = require("lspconfig") + +if utils.executable("pylsp") then + lspconfig.pylsp.setup({ + settings = { + pylsp = { + plugins = { + pylint = { enabled = true, executable = "pylint" }, + pyflakes = { enabled = false }, + pycodestyle = { enabled = false }, + jedi_completion = { fuzzy = true }, + pyls_isort = { enabled = true }, + pylsp_mypy = { enabled = true }, + }, + }, + }, + flags = { + debounce_text_changes = 200, + }, + capabilities = capabilities, + }) +else + vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Server?" }) +end + +-- if utils.executable('pyright') then +-- lspconfig.pyright.setup{ +-- on_attach = custom_attach, +-- capabilities = capabilities +-- } +-- else +-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Server?'}) +-- end + +if utils.executable("clangd") then + lspconfig.clangd.setup({ + on_attach = custom_attach, + capabilities = capabilities, + filetypes = { "c", "cpp", "cc" }, + flags = { + debounce_text_changes = 500, + }, + }) +else + vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Server?" }) +end + +-- set up vim-language-server +if utils.executable("vim-language-server") then + lspconfig.vimls.setup({ + on_attach = custom_attach, + flags = { + debounce_text_changes = 500, + }, + capabilities = capabilities, + }) +else + vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Server?" }) +end + +-- set up bash-language-server +if utils.executable("bash-language-server") then + lspconfig.bashls.setup({ + on_attach = custom_attach, + capabilities = capabilities, + }) +end + +if utils.executable("lua-language-server") then + lspconfig.sumneko_lua.setup({ + on_attach = custom_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files, + library = { + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), + }, + maxPreload = 2000, + preloadFileSize = 50000, + }, + }, + }, + capabilities = capabilities, + }) +end + +--lspconfig.sumneko_lua.setup({ +-- single_file_support = true, +-- on_attach = function(client, bufnr) +-- print('hello') +-- lspconfig.util.default_config.on_attach(client, bufnr) +-- end +--}) + +-- Global config for diagnostic +vim.diagnostic.config({ + underline = false, + virtual_text = false, + signs = true, + severity_sort = true, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = false, + virtual_text = false, + signs = true, + update_in_insert = false, +}) + +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + {border = 'rounded'} +) + +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + {border = 'rounded'} +) + + +--local signs = { Error = " ", Warn = " ", Info = " ", Hint = " " } +local signs = { Error = "✘", Warn = "▲", Info = " ", Hint = "⚑" } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end + diff --git a/nvim/lua/plugins/lspOld.lsp b/nvim/lua/plugins/lspOld.lsp new file mode 100644 index 0000000..206ea57 --- /dev/null +++ b/nvim/lua/plugins/lspOld.lsp @@ -0,0 +1,531 @@ +-- lspconfig + nvim-cmp + lspsaga +-- Dependencies +-- nvim-lspconfig +-- nvim-cmp +-- cmp-buffer +-- cmp-path +-- cmp_luasnip +-- cmp-nvim-lsp +-- LuaSnip +-- friendly-snippets +local fn = vim.fn +local api = vim.api +local keymap = vim.keymap +local lsp = vim.lsp + +local utils = require("utils") + +local custom_attach = function(client, bufnr) + -- Mappings. + local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.buffer = bufnr + keymap.set(mode, l, r, opts) + end + + +local lsp_defaults = { + flags = { + debounce_text_changes = 150, -- Amount of miliseconds neovim will wait to send the next document update notification. + }, + + -- The data on this option is send to the server, to announce what features the editor can support. + capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds("User", { pattern = "LspAttached" }) + end, +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +--- +-- LSP Servers +--- + +if utils.executable("pylsp") then + lspconfig.pylsp.setup { + on_attach = custom_attach, + settings = { + pylsp = { + plugins = { + pylint = { enabled = true, executable = "pylint" }, + pyflakes = { enabled = false }, + pycodestyle = { enabled = false }, + jedi_completion = { fuzzy = true }, + pyls_isort = { enabled = true }, + pylsp_mypy = { enabled = true }, + }, + }, + }, + flags = { + debounce_text_changes = 200, + }, + capabilities = capabilities, + } +else + vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" }) +end + +-- if utils.executable('pyright') then +-- lspconfig.pyright.setup{ +-- on_attach = custom_attach, +-- capabilities = capabilities +-- } +-- else +-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) +-- end + +if utils.executable("clangd") then + lspconfig.clangd.setup { + on_attach = custom_attach, + capabilities = capabilities, + filetypes = { "c", "cpp", "cc" }, + flags = { + debounce_text_changes = 500, + }, + } +else + vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Nvim-config" }) +end + +-- set up vim-language-server +if utils.executable("vim-language-server") then + lspconfig.vimls.setup { + on_attach = custom_attach, + flags = { + debounce_text_changes = 500, + }, + capabilities = capabilities, + } +else + vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" }) +end + +-- set up bash-language-server +if utils.executable("bash-language-server") then + lspconfig.bashls.setup { + on_attach = custom_attach, + capabilities = capabilities, + } +end + +if utils.executable("lua-language-server") then + -- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings . + lspconfig.sumneko_lua.setup { + on_attach = custom_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files, + -- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace . + -- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua . + library = { + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), + }, + maxPreload = 2000, + preloadFileSize = 50000, + }, + }, + }, + capabilities = capabilities, + } +end +-- Lua +lspconfig.sumneko_lua.setup({ + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + single_file_support = true, + on_attach = function(client, bufnr) + print('hello') + lspconfig.util.default_config.on_attach(client, bufnr) + end +}) + +lspconfig.sumneko_lua.setup({ +on_attach = custom_attach, +settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, +}, +}) + + lspconfig.sumneko_lua.setup { + on_attach = custom_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files, + -- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace . + -- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua . + library = { + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), + }, + maxPreload = 2000, + preloadFileSize = 50000, + }, + }, + }, + capabilities = capabilities, + } + +require'lspconfig'.sumneko_lua.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, +} + + + +require'lspconfig'.sumneko_lua.setup{} + + +**Default values:** + - `cmd` : + { "lua-language-server" } + - `filetypes` : + - `log_level` : + ```lua + 2 + ``` + - `root_dir` : + ```lua + root_pattern(".luarc.json", ".luacheckrc", ".stylua.toml", "stylua.toml", "selene.toml", ".git") + ``` + - `settings` : + ```lua + { + Lua = { + telemetry = { + enable = false + } + } + } + - `single_file_support` : + true + + + + + + + + + + + + + + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.ccls.setup{} +``` + + +**Default values:** + - `cmd` : + ```lua + { "ccls" } + ``` + - `filetypes` : + ```lua + { "c", "cpp", "objc", "objcpp" } + ``` + - `offset_encoding` : + ```lua + "utf-32" + ``` + - `root_dir` : + ```lua + root_pattern('compile_commands.json', '.ccls', '.git') + ``` + - `single_file_support` : + ```lua + false + ``` + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.clangd.setup{} +``` +**Commands:** +- ClangdSwitchSourceHeader: Switch between source/header + +**Default values:** + - `capabilities` : + ```lua + default capabilities, with offsetEncoding utf-8 + ``` + - `cmd` : + ```lua + { "clangd" } + ``` + - `filetypes` : + ```lua + { "c", "cpp", "objc", "objcpp", "cuda", "proto" } + ``` + - `root_dir` : + ```lua + root_pattern( + '.clangd', + '.clang-tidy', + '.clang-format', + 'compile_commands.json', + 'compile_flags.txt', + 'configure.ac', + '.git' + ) + + ``` + - `single_file_support` : + ```lua + true + ``` + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.pyright.setup{} +``` +**Commands:** +- PyrightOrganizeImports: Organize Imports + +**Default values:** + - `cmd` : + ```lua + { "pyright-langserver", "--stdio" } + ``` + - `filetypes` : + ```lua + { "python" } + ``` + - `root_dir` : + ```lua + see source file + ``` + - `settings` : + ```lua + { + python = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "workspace", + useLibraryCodeForTypes = true + } + } + } + ``` + - `single_file_support` : + ```lua + true + ``` + +## rls + +https://github.com/rust-lang/rls + +rls, a language server for Rust + +See https://github.com/rust-lang/rls#setup to setup rls itself. +See https://github.com/rust-lang/rls#configuration for rls-specific settings. +All settings listed on the rls configuration section of the readme +must be set under settings.rust as follows: + +```lua +nvim_lsp.rls.setup { + settings = { + rust = { + unstable_features = true, + build_on_save = false, + all_features = true, + }, + }, +} +``` + +If you want to use rls for a particular build, eg nightly, set cmd as follows: + +```lua +cmd = {"rustup", "run", "nightly", "rls"} +``` + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.rls.setup{} +``` + + +**Default values:** + - `cmd` : + ```lua + { "rls" } + ``` + - `filetypes` : + ```lua + { "rust" } + ``` + - `root_dir` : + ```lua + root_pattern("Cargo.toml") + ``` + + +## rust_analyzer + +https://github.com/rust-analyzer/rust-analyzer + +rust-analyzer (aka rls 2.0), a language server for Rust + +See [docs](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#settings) for extra settings. + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.rust_analyzer.setup{} +``` +**Commands:** +- CargoReload: Reload current cargo workspace + +**Default values:** + - `cmd` : + ```lua + { "rust-analyzer" } + ``` + - `filetypes` : + ```lua + { "rust" } + ``` + - `root_dir` : + ```lua + root_pattern("Cargo.toml", "rust-project.json") + ``` + - `settings` : + ```lua + { + ["rust-analyzer"] = {} + } + ``` + +## rust_analyzer + +https://github.com/rust-analyzer/rust-analyzer + +rust-analyzer (aka rls 2.0), a language server for Rust + +See [docs](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#settings) for extra settings. + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.rust_analyzer.setup{} +``` +**Commands:** +- CargoReload: Reload current cargo workspace + +**Default values:** + - `cmd` : + ```lua + { "rust-analyzer" } + ``` + - `filetypes` : + ```lua + { "rust" } + ``` + - `root_dir` : + ```lua + root_pattern("Cargo.toml", "rust-project.json") + ``` + - `settings` : + ```lua + { + ["rust-analyzer"] = {} + } + ``` + + diff --git a/nvim/lua/plugins/lspconfig.lua b/nvim/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..a130dcd --- /dev/null +++ b/nvim/lua/plugins/lspconfig.lua @@ -0,0 +1,148 @@ +--vim.lsp.set_log_level("debug") + +local status, nvim_lsp = pcall(require, "lspconfig") +if not status then + return +end + +local protocol = require("vim.lsp.protocol") + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + local function buf_set_option(...) + vim.api.nvim_buf_set_option(bufnr, ...) + end + + --Enable completion triggered by <c-x><c-o> + buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") + + -- Mappings. + local opts = { noremap = true, silent = true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) -- most of the lsp server don't implement textDocument/Declaration, so gD is useless for now. + --buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) + buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) + --buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) + + -- add rust specific keymappings + if client.name == "rust_analyzer" then + buf_set_keymap("n", "<leader>rr", "<cmd>RustRunnables<CR>", opts) + buf_set_keymap("n", "<leader>ra", "<cmd>RustHoverAction<CR>", opts) + end + + -- formatting + if client.server_capabilities.documentFormattingProvider then + vim.api.nvim_create_autocmd("BufWritePre", { + group = vim.api.nvim_create_augroup("Format", { clear = true }), + buffer = bufnr, + callback = function() + vim.lsp.buf.format() + end, + }) + end +end + +protocol.CompletionItemKind = { + -- "", -- Text + -- "", -- Method + -- "", -- Function + -- "", -- Constructor + -- "", -- Field + -- "", -- Variable + -- "", -- Class + -- "ﰮ", -- Interface + -- "", -- Module + -- "", -- Property + -- "", -- Unit + -- "", -- Value + -- "", -- Enum + -- "", -- Keyword + -- "", -- Snippet + -- "", -- Color + -- "", -- File + -- "", -- Reference + -- "", -- Folder + -- "", -- EnumMember + -- "", -- Constant + -- "", -- Struct + -- "", -- Event + -- "ﬦ", -- Operator + -- "", -- TypeParameter + File = { icon = "", hl = "TSURI" }, + Module = { icon = "", hl = "TSNamespace" }, + Namespace = { icon = "", hl = "TSNamespace" }, + Package = { icon = "", hl = "TSNamespace" }, + Class = { icon = "ﴯ", hl = "TSType" }, + Method = { icon = "", hl = "TSMethod" }, + Property = { icon = "", hl = "TSMethod" }, + Field = { icon = "", hl = "TSField" }, + Constructor = { icon = "", hl = "TSConstructor" }, + Enum = { icon = "", hl = "TSType" }, + Interface = { icon = "", hl = "TSType" }, + Function = { icon = "", hl = "TSFunction" }, + Variable = { icon = "", hl = "TSConstant" }, + Constant = { icon = "", hl = "TSConstant" }, + String = { icon = "ﮜ", hl = "TSString" }, + Number = { icon = "", hl = "TSNumber" }, + Boolean = { icon = "ﮒ", hl = "TSBoolean" }, + Array = { icon = "", hl = "TSConstant" }, + Object = { icon = "⦿", hl = "TSType" }, + Key = { icon = "", hl = "TSType" }, + Null = { icon = "ﳠ", hl = "TSType" }, + EnumMember = { icon = "", hl = "TSField" }, + Struct = { icon = "ﴯ", hl = "TSType" }, + Event = { icon = "🗲", hl = "TSType" }, + Operator = { icon = "+", hl = "TSOperator" }, + TypeParameter = { icon = "𝙏", hl = "TSParameter" }, +} + +-- Set up completion using nvim_cmp with LSP source +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + +nvim_lsp.flow.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +nvim_lsp.sumneko_lua.setup({ + on_attach = on_attach, + settings = { + Lua = { + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + }, + }, +}) + +-- Diagnostic symbols in the sign column (gutter) +--local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +--local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end +-- +vim.diagnostic.config({ + virtual_text = { + prefix = "●", + }, + update_in_insert = true, + float = { + source = "always", -- Or "if_many" + }, +}) diff --git a/nvim/lua/plugins/lspkind.lua b/nvim/lua/plugins/lspkind.lua new file mode 100644 index 0000000..72ca5c2 --- /dev/null +++ b/nvim/lua/plugins/lspkind.lua @@ -0,0 +1,47 @@ +local status, lspkind = pcall(require, "lspkind") +if (not status) then return end + +lspkind.init({ + -- enables text annotations + -- + -- default: true + mode = 'symbol', + + -- default symbol map + -- can be either 'default' (requires nerd-fonts font) or + -- 'codicons' for codicon preset (requires vscode-codicons font) + -- + -- default: 'default' + preset = 'codicons', + + -- override preset symbols + -- + -- default: {} + symbol_map = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "ﰠ", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "塞", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "פּ", + Event = "", + Operator = "", + TypeParameter = "" + }, +}) diff --git a/nvim/lua/plugins/lspsaga.lua b/nvim/lua/plugins/lspsaga.lua new file mode 100644 index 0000000..ceb1099 --- /dev/null +++ b/nvim/lua/plugins/lspsaga.lua @@ -0,0 +1,61 @@ +local status, saga = pcall(require, "lspsaga") +if not status then + return +end + +saga.init_lsp_saga({ + -- when cursor in saga window you config these to move + move_in_saga = { prev = "k", next = "j" }, + diagnostic_header = { " ", " ", " ", " " }, + scroll_in_preview = { + scroll_down = "<C-d>", + scroll_up = "<C-u>", + }, + code_action_icon = "ﯦ ", + -- Same as nvim-lightbulb but async + code_action_lightbulb = { + sign = false, + virtual_text = true, + }, + finder_icons = { + def = " ", + ref = " ", + link = " ", + }, + finder_action_keys = { + open = "<CR>", + "o", + vsplit = "gv", + split = "gs", + tabe = "t", + quit = "gq", + scroll_down = "<C-f>", + scroll_up = "<C-b>", + }, + + -- Show symbols in winbar must be neovim 0.8.0, + -- Close it until neovim 0.8.0 become stable + symbol_in_winbar = { + in_custom = false, + --enable = enable_winbar, + separator = " ", + show_file = true, + click_support = false, + }, +}) + + -- Mappings. +local map = vim.api.nvim_set_keymap +local opts = { noremap = true, silent = true } + +map("n", "gd", "<Cmd>Lspsaga lsp_finder<CR>", opts) -- Press "o" to open the reference location +map("n", "gp", "<Cmd>Lspsaga peek_definition<CR>", opts) +map("n", "K", "<Cmd>Lspsaga hover_doc<CR>", opts) +map("n", "gk", "<Cmd>Lspsaga diagnostic_jump_prev<CR>", opts) +map("n", "gj", "<Cmd>Lspsaga diagnostic_jump_next<CR>", opts) +map("n", "gs", "<Cmd>Lspsaga signature_help<CR>", opts) -- Default is <C-k> +map("n", "go", "<Cmd>Lspsaga show_line_diagnostics<CR>", opts) +map("n", "gr", "<Cmd>Lspsaga rename<CR>", opts) +map("n", "ga", "<Cmd>Lspsaga code_action<CR>", opts) +map("n", "[d", "<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts) +map("n", "]d", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts) diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua new file mode 100644 index 0000000..9d86e21 --- /dev/null +++ b/nvim/lua/plugins/lualine.lua @@ -0,0 +1,423 @@ +local lualine_status_ok, lualine = pcall(require, "lualine") +if not lualine_status_ok then + print("lualine.nvim is etiher broken or is not installed.") + return +end + +--local colors = require('tokyonight.colors').setup() +--local colors = { +--bg_dark = "#1f2335", +--bg = "#24283b", +--fg = "#c0caf5", +--fg_gutter = "#3b4261", +--green = "#a6e3a1", +--red = "#f38ba8", +--} + +--local colors = { +-- gray = '#23232e', +-- lightgray = '#5f6a8e', +-- orange = '#ffb86c', +-- purple = '#bd93f9', +-- red = '#ff5555', +-- yellow = '#f1fa8c', +-- green = '#50fa7b', +-- white = '#f8f8f2', +-- black = '#282a36', +--} +local colors = { + nobg = nil, + blue = "#87b0f9", + mauve = "#cba6f7", + red = "#f38ba8", + green = "#a6e3a1", + peach = "#fab387", + white = "#c6d0f5", + gray = "#a1a8c9", + black = "#1e1e2e", + innerbg = nil, + outerbg = "#16161D", +} +--require("lualine").setup({ +-- Your lua part of config goes here +require("lualine").setup({ + options = { + icons_enabled = true, + --theme = "auto", + theme = require("plugins.linecolor").theme(), + --theme = { + -- We are going to use lualine_c an lualine_x as left and + -- right section. Both are highlighte by c theme . So we + -- are just setting default looks o statusline + --normal = { c = { fg = colors.fg, bg = colors.bg } }, + --inactive = { c = { fg = colors.fg, bg = colors.bg } }, + --}, + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + --component_separators = { left = '|', right = '|'}, + --section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = true, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + }, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { + "branch", + { + "diff", + colored = true, + diff_color = { + added = "DiffAdd", + modified = "DiffChange", + removed = "DiffDelete", + }, + }, + { + "diagnostics", + + sources = { "nvim_lsp" }, + sections = { "error", "warn", "info" }, + + diagnostics_color = { + error = "DiagnosticError", + warn = "DiagnosticWarn", + info = "DiagnosticInfo", + }, + colored = true, + update_in_insert = false, + always_visible = false, + }, + }, + --lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { + --{"filetype", padding={right=0}, icon_only = true, component_separators = {left = "", right = ""}}, + --{"filename", padding={left=0}, color = {gui = "bold,italic"}}, + --{ "filetype", + -- icon_only = true, + --}, + { + "filename", + --color = {gui = "bold,italic", fg = '#ffaa88', bg = 'nil' }, + --component_separators = {left = "", right = ""}, + }, + }, + lualine_x = { "encoding", "fileformat", "filetype" }, + --lualine_x = { + -- {"encoding", color = { bg = colors.black }, component_separators = {left = "", right = ""}}, + -- {"fileformat", color = { bg = colors.black }, component_separators = {left = "", right = ""}}, + -- {"filetype", color = { bg = colors.black }, component_separators = {left = "", right = ""}}, + --}, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + -- tabline = {}, + tabline = { + --lualine_a = { "mode" }, + --lualine_a = {custom_fname}, + lualine_a = { + { + "buffers", + show_filename_only = false, + show_modified_status = true, + mode = 4, + buffers_color = { + active = { bg = colors.nobg, fg = colors.black }, -- color for active buffer + --inactive = { bg = colors.white, fg = colors.fg_gutter }, -- color for inactive buffer + --active = { bg = colors.bg, fg = colors.white }, -- color for active buffer + --inactive = { bg = colors.bg_dark, fg = colors.fg_gutter }, -- color for inactive buffer + ----color = function() + ---- return { bg = vim.bo.modified and '#aa3355' or '#33aa88' } + ----end, + }, + symbols = { + modified = " ●", -- Text to show when the buffer is modified + alternate_file = "", -- Text to show to identify the alternate file + --directory = "", -- Text to show when the buffer is a directory + }, + max_length = vim.o.columns * 5 / 6, + --{{function() + -- local bg = 'hi! lualine_buffers_color' -- not modified + -- if vim.bo.modified then bg = '#c70039' -- unsaved + -- elseif not vim.bo.readonly then bg = 'hi! lualine_buffers_color' end -- readonly + -- vim.cmd('hi! lualine_buffers_color guibg='..bg) + --end, + --color = 'hi! lualine_buffers_color', + --}}, + }, + }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + --lualine_z = { "tabs" }, + }, + --tabline = { + -- lualine_a = { "mode" }, + -- lualine_b = { "buffers" }, + -- lualine_c = { "branch" }, + -- --lualine_c = { "branch", "diff", "diagnostics" }, + -- lualine_x = {}, + -- lualine_y = {}, + -- lualine_z = { "tabs" }, + --}, + --winbar = { + -- lualine_a = {}, + -- lualine_b = {}, + -- lualine_c = {'filename'}, + -- lualine_x = {}, + -- lualine_y = {}, + -- lualine_z = {} + --}, + --inactive_winbar = { + -- lualine_a = {}, + -- lualine_b = {}, + -- lualine_c = {}, + -- lualine_x = {}, + -- lualine_y = {}, + -- lualine_z = {} + --}, + winbar = {}, + inactive_winbar = {}, + --extensions = {}, + extensions = { "quickfix" }, +}) +--require("lualine").statusline() +--require("lualine").tabline() +--if not lualine_status_ok then +-- print("lualine.nvim is etiher broken or is not installed.") +-- return +--end +--local lualine_status_ok, lualine = pcall(require, "lualine") +--if not lualine_status_ok then +-- print("lualine.nvim is etiher broken or is not installed.") +-- return +--end +--local utils = require("heirline.utils") + +--local M = {} + +-- stylua: ignore start +--M.colours = {--{{{ +---- Color table for highlights +---- stylua: ignore +--local colors = { +-- bg = '#2E3440', +-- fg = '#E5E9F0', +-- yellow = '#EBCB8B', +-- cyan = '#88C0D0', +-- darkblue = '#5E81AC', +-- green = '#A3BE8C', +-- orange = '#D08770', +-- violet = '#B48EAD', +-- magenta = '#B48EAD', +-- blue = '#81A1C1', +-- red = '#BF616A', +--} +-- +--local conditions = { +-- buffer_not_empty = function() +-- return vim.fn.empty(vim.fn.expand("%:t")) ~= 1 +-- end, +-- hide_in_width = function() +-- return vim.fn.winwidth(0) > 80 +-- end, +-- check_git_workspace = function() +-- local filepath = vim.fn.expand("%:p:h") +-- local gitdir = vim.fn.finddir(".git", filepath .. ";") +-- return gitdir and #gitdir > 0 and #gitdir < #filepath +-- end, +--} + +-- Config +--local config = { +--require('lualine').setup { +-- options = { +-- -- Disable sections and component separators +-- component_separators = "", +-- section_separators = "", +-- theme = { +-- -- We are going to use lualine_c an lualine_x as left and +-- -- right section. Both are highlighte by c theme . So we +-- -- are just setting default looks o statusline +-- normal = { c = { fg = colors.fg, bg = colors.bg } }, +-- inactive = { c = { fg = colors.fg, bg = colors.bg } }, +-- }, +-- disabled_filetypes = { "NvimTree" }, +-- }, +-- sections = { +-- -- these are to remove the defaults +-- lualine_a = {}, +-- lualine_b = {}, +-- lualine_y = {}, +-- lualine_z = {}, +-- -- These will be filled later +-- lualine_c = {}, +-- lualine_x = {}, +-- }, +-- inactive_sections = { +-- -- these are to remove the defaults +-- lualine_a = {}, +-- lualine_b = {}, +-- lualine_y = {}, +-- lualine_z = {}, +-- lualine_c = {}, +-- lualine_x = {}, +-- }, +--} +-- +---- Inserts a component in lualine_c at left section +--local function ins_left(component) +-- table.insert(lualine.sections.lualine_c, component) +--end +-- +---- Inserts a component in lualine_x ot right section +--local function ins_right(component) +-- table.insert(lualine.sections.lualine_x, component) +--end +-- +--ins_left({ +-- function() +-- return "▊" +-- end, +-- color = { fg = colors.green }, -- Sets highlighting of component +-- padding = { left = 0, right = 1 }, -- We don't need space before this +--}) +-- +--ins_left({ +-- -- mode component +-- function() +-- return "" +-- end, +-- color = function() +-- -- auto change color according to neovims mode +-- local mode_color = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.violet, +-- ["�"] = colors.blue, +-- V = colors.blue, +-- c = colors.magenta, +-- no = colors.red, +-- s = colors.orange, +-- S = colors.orange, +-- ic = colors.yellow, +-- R = colors.violet, +-- Rv = colors.violet, +-- cv = colors.red, +-- ce = colors.red, +-- r = colors.cyan, +-- rm = colors.cyan, +-- ["r?"] = colors.cyan, +-- ["!"] = colors.red, +-- t = colors.red, +-- } +-- return { fg = mode_color[vim.fn.mode()] } +-- end, +-- padding = { right = 1 }, +--}) +-- +--ins_left({ +-- -- mode component +-- "mode", +-- color = function() +-- -- auto change color according to neovims mode +-- local mode_color = { +-- n = colors.red, +-- i = colors.green, +-- v = colors.violet, +-- ["�"] = colors.blue, +-- V = colors.blue, +-- c = colors.magenta, +-- no = colors.red, +-- s = colors.orange, +-- S = colors.orange, +-- ic = colors.yellow, +-- R = colors.violet, +-- Rv = colors.violet, +-- cv = colors.red, +-- ce = colors.red, +-- r = colors.cyan, +-- rm = colors.cyan, +-- ["r?"] = colors.cyan, +-- ["!"] = colors.red, +-- t = colors.red, +-- } +-- return { fg = mode_color[vim.fn.mode()] } +-- end, +-- padding = { right = 1 }, +--}) +-- +--ins_left({ +-- "branch", +-- icon = "", +-- color = { fg = colors.violet, gui = "bold" }, +--}) +-- +--ins_left({ +-- "filename", +-- cond = conditions.buffer_not_empty, +-- color = { fg = colors.aqua, gui = "bold" }, +--}) +-- +--ins_left({ +-- -- filesize component +-- "filesize", +-- cond = conditions.buffer_not_empty, +--}) +-- +---- Add components to right sections +--ins_right({ +-- "o:encoding", -- option component same as &encoding in viml +-- fmt = string.lower, -- I'm not sure why it's upper case either ;) +-- cond = conditions.hide_in_width, +-- color = { fg = colors.yellow }, +--}) +-- +--ins_right({ +-- "fileformat", +-- fmt = string.upper, +-- icons_enabled = true, -- I think icons are cool but Eviline doesn't have them. sigh +-- color = { fg = colors.fg, gui = "bold" }, +--}) +-- +--ins_right({ +-- "filetype", +--}) +-- +--ins_right({ "progress", color = { fg = colors.fg, gui = "bold" } }) +-- +--ins_right({ +-- "location", +--}) +-- +--ins_right({ +-- function() +-- return "▊" +-- end, +-- color = { fg = colors.green }, +-- padding = { left = 1 }, +--}) +--return M +-- Now don't forget to initialize lualine +--require("lualine").setup(config) +--require"lualine".setup(config) +--lualine.setup(config) diff --git a/nvim/lua/plugins/mason.lua b/nvim/lua/plugins/mason.lua new file mode 100644 index 0000000..69c61ba --- /dev/null +++ b/nvim/lua/plugins/mason.lua @@ -0,0 +1,27 @@ +local status, mason = pcall(require, "mason") +if (not status) then return end +local status2, lspconfig = pcall(require, "mason-lspconfig") +if (not status2) then return end + +mason.setup({ + +}) + +lspconfig.setup { + ensure_installed = { "sumneko_lua" }, +} +local keymap = vim.api.nvim_set_keymap +local opts = { noremap = true } + + +keymap('n', 'gd', ':lua vim.lsp.buf.definition()<cr>', opts) +keymap('n', 'gD', ':lua vim.lsp.buf.declaration()<cr>', opts) +keymap('n', 'gi', ':lua vim.lsp.buf.implementation()<cr>', opts) +keymap('n', 'gw', ':lua vim.lsp.buf.document_symbol()<cr>', opts) +keymap('n', 'gw', ':lua vim.lsp.buf.workspace_symbol()<cr>', opts) +keymap('n', 'gr', ':lua vim.lsp.buf.references()<cr>', opts) +keymap('n', 'gt', ':lua vim.lsp.buf.type_definition()<cr>', opts) +keymap('n', 'K', ':lua vim.lsp.buf.hover()<cr>', opts) +keymap('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<cr>', opts) +keymap('n', '<leader>af', ':lua vim.lsp.buf.code_action()<cr>', opts) +keymap('n', '<leader>rn', ':lua vim.lsp.buf.rename()<cr>', opts) diff --git a/nvim/lua/plugins/neoscroll.lua b/nvim/lua/plugins/neoscroll.lua new file mode 100644 index 0000000..d122584 --- /dev/null +++ b/nvim/lua/plugins/neoscroll.lua @@ -0,0 +1,21 @@ +require("neoscroll").setup({ + easing_function = "quadratic", +}) + +local t = {} +-- Syntax: t[keys] = {function, {function arguments}} +-- Use the "sine" easing function +t["<C-u>"] = { "scroll", { "-vim.wo.scroll", "true", "20", [['cubic']] } } +t["<C-d>"] = { "scroll", { "vim.wo.scroll", "true", "20", [['cubic']] } } +-- Use the "circular" easing function +t["<C-b>"] = { "scroll", { "-vim.api.nvim_win_get_height(0)", "true", "50", [['cubic']] } } +t["<C-f>"] = { "scroll", { "vim.api.nvim_win_get_height(0)", "true", "50", [['cubic']] } } +-- Pass "nil" to disable the easing animation (constant scrolling speed) +t["<C-y>"] = { "scroll", { "-0.10", "false", "100", nil } } +t["<C-e>"] = { "scroll", { "0.10", "false", "100", nil } } +-- When no easing function is provided the default easing function (in this case "quadratic") will be used +t["zt"] = { "zt", { "10" } } +t["zz"] = { "zz", { "10" } } +t["zb"] = { "zb", { "10" } } + +require("neoscroll.config").set_mappings(t) diff --git a/nvim/lua/plugins/null-ls.lua b/nvim/lua/plugins/null-ls.lua new file mode 100644 index 0000000..7fc4377 --- /dev/null +++ b/nvim/lua/plugins/null-ls.lua @@ -0,0 +1,26 @@ +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting +local formatting = null_ls.builtins.formatting +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics +local diagnostics = null_ls.builtins.diagnostics + +--null_ls.setup({ +-- debug = false, +-- sources = { +-- formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }), +-- formatting.black.with({ extra_args = { "--fast" } }), +-- formatting.stylua, +-- -- diagnostics.flake8 +-- }, +--}) +require("null-ls").setup({ + sources = { + require("null-ls").builtins.formatting.stylua, + require("null-ls").builtins.diagnostics.eslint, + require("null-ls").builtins.completion.spell, + }, +}) diff --git a/nvim/lua/plugins/nvim-tree.lua b/nvim/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..f362659 --- /dev/null +++ b/nvim/lua/plugins/nvim-tree.lua @@ -0,0 +1,68 @@ +local status_ok, nvim_tree = pcall(require, "nvim-tree") +if not status_ok then + return +end + +local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") +if not config_status_ok then + return +end + +local tree_cb = nvim_tree_config.nvim_tree_callback + +nvim_tree.setup({ + update_focused_file = { + enable = true, + update_cwd = true, + }, + renderer = { + root_folder_modifier = ":t", + icons = { + glyphs = { + default = "", + symlink = "", + folder = { + arrow_open = "", + arrow_closed = "", + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + symlink_open = "", + }, + git = { + unstaged = "", + staged = "S", + unmerged = "", + renamed = "➜", + untracked = "U", + deleted = "", + ignored = "◌", + }, + }, + }, + }, + diagnostics = { + enable = true, + show_on_dirs = true, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + view = { + width = 30, + --height = 30, + side = "right", + mappings = { + list = { + { key = { "l", "<CR>", "o" }, cb = tree_cb("edit") }, + { key = "h", cb = tree_cb("close_node") }, + { key = "v", cb = tree_cb("vsplit") }, + }, + }, + }, +}) diff --git a/nvim/lua/plugins/prettier.lua b/nvim/lua/plugins/prettier.lua new file mode 100644 index 0000000..05d4665 --- /dev/null +++ b/nvim/lua/plugins/prettier.lua @@ -0,0 +1,19 @@ +local status, prettier = pcall(require, "prettier") +if (not status) then return end + +prettier.setup { + bin = 'prettierd', + filetypes = { + "c", + "lua", + "vim", + --"css", + --"javascript", + --"javascriptreact", + --"typescript", + --"typescriptreact", + --"json", + --"scss", + "less" + } +} diff --git a/nvim/lua/plugins/tabline.lua b/nvim/lua/plugins/tabline.lua new file mode 100644 index 0000000..4e1c506 --- /dev/null +++ b/nvim/lua/plugins/tabline.lua @@ -0,0 +1,22 @@ +require("tabline").setup({ + -- Defaults configuration options + enable = true, + options = { + -- If lualine is installed tabline will use separators configured in lualine by default. + -- These options can be used to override those settings. + section_separators = { "", "" }, + component_separators = { "", "" }, + max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 + show_tabs_always = true, -- this shows tabs only when there are more than one tab or if the first tab is named + show_devicons = true, -- this shows devicons in buffer section + show_bufnr = true, -- this appends [bufnr] to buffer section, + show_filename_only = false, -- shows base filename only instead of relative path in filename + modified_icon = "+", -- change the default modified icon + modified_italic = true, -- set to true by default; this determines whether the filename turns italic if modified + show_tabs_only = false, -- this shows only tabs instead of tabs + buffers + }, +}) +vim.cmd([[ + set guioptions-=e " Use showtabline in gui vim + set sessionoptions+=tabpages,globals " store tabpages and globals in session +]]) diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..dcf6b9e --- /dev/null +++ b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,177 @@ +local status_ok, telescope = pcall(require, "telescope") +if not status_ok then + return +end +local actions = require("telescope.actions") +local builtin = require("telescope.builtin") + +local function telescope_buffer_dir() + return vim.fn.expand("%:p:h") +end + +telescope.load_extension("fzf") +telescope.load_extension("file_browser") +require("telescope").load_extension("file_browser") +local fb_actions = require("telescope").extensions.file_browser.actions +--telescope.load_extension('media_files') + +telescope.setup({ + defaults = { + -- + prompt_prefix = " ", + selection_caret = " ", + path_display = { "smart" }, + -- + mappings = { + i = { + ["<C-n>"] = actions.cycle_history_next, + ["<C-p>"] = actions.cycle_history_prev, + + ["<C-j>"] = actions.move_selection_next, + ["<C-k>"] = actions.move_selection_previous, + + ["<C-c>"] = actions.close, + + ["<Down>"] = actions.move_selection_next, + ["<Up>"] = actions.move_selection_previous, + + ["<CR>"] = actions.select_default, + ["<C-x>"] = actions.select_horizontal, + ["<C-y>"] = actions.select_vertical, + ["<C-t>"] = actions.select_tab, + + ["<C-u>"] = actions.preview_scrolling_up, + ["<C-d>"] = actions.preview_scrolling_down, + + ["<PageUp>"] = actions.results_scrolling_up, + ["<PageDown>"] = actions.results_scrolling_down, + + ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse, + ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better, + ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, + ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, + ["<C-l>"] = actions.complete_tag, + ["<C-_>"] = actions.which_key, -- keys from pressing <C-/> + }, + + n = { + ["<esc>"] = actions.close, + ["<CR>"] = actions.select_default, + ["<C-x>"] = actions.select_horizontal, + ["<C-v>"] = actions.select_vertical, + ["<C-t>"] = actions.select_tab, + + ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse, + ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better, + ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, + ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, + + ["j"] = actions.move_selection_next, + ["k"] = actions.move_selection_previous, + ["H"] = actions.move_to_top, + ["M"] = actions.move_to_middle, + ["L"] = actions.move_to_bottom, + + ["<Down>"] = actions.move_selection_next, + ["<Up>"] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, + + ["<C-u>"] = actions.preview_scrolling_up, + ["<C-d>"] = actions.preview_scrolling_down, + + ["<PageUp>"] = actions.results_scrolling_up, + ["<PageDown>"] = actions.results_scrolling_down, + + ["?"] = actions.which_key, + ["cd"] = function(prompt_bufnr) + local selection = require("telescope.actions.state").get_selected_entry() + local dir = vim.fn.fnamemodify(selection.path, ":p:h") + require("telescope.actions").close(prompt_bufnr) + -- Depending on what you want put `cd`, `lcd`, `tcd` + vim.cmd(string.format("silent lcd %s", dir)) + end, + }, + }, + }, + pickers = { + -- Default configuration for builtin pickers goes here: + -- picker_name = { + -- picker_config_key = value, + -- ... + -- } + -- Now the picker_config_key will be applied every time you call this + -- builtin picker + }, + extensions = { + file_browser = { + theme = "dropdown", + -- disables netrw and use telescope-file-browser in its place + hijack_netrw = true, + mappings = { + -- your custom insert mode mappings + ["i"] = { + ["<C-w>"] = function() + vim.cmd("normal vbd") + end, + }, + ["n"] = { + -- your custom normal mode mappings + ["N"] = fb_actions.create, + ["h"] = fb_actions.goto_parent_dir, + ["/"] = function() + vim.cmd("startinsert") + end, + }, + }, + }, + + media_files = { + -- filetypes whitelist + -- defaults to {"png", "jpg", "mp4", "webm", "pdf"} + filetypes = { "png", "webp", "jpg", "jpeg" }, + find_cmd = "rg", -- find command (defaults to `fd`) + }, + -- Your extension configuration goes here: + -- extension_name = { + -- extension_config_key = value, + -- } + -- please take a look at the readme of the extension you want to configure + }, +}) + +telescope.load_extension("file_browser") + +vim.keymap.set("n", ";f", function() + builtin.find_files({ + no_ignore = false, + hidden = true, + }) +end) +vim.keymap.set("n", ";r", function() + builtin.live_grep() +end) +vim.keymap.set("n", "\\\\", function() + builtin.buffers() +end) +vim.keymap.set("n", ";t", function() + builtin.help_tags() +end) +vim.keymap.set("n", ";;", function() + builtin.resume() +end) +vim.keymap.set("n", ";e", function() + builtin.diagnostics() +end) +vim.keymap.set("n", "sf", function() + telescope.extensions.file_browser.file_browser({ + path = "%:p:h", + cwd = telescope_buffer_dir(), + respect_gitignore = false, + hidden = true, + grouped = true, + previewer = false, + initial_mode = "normal", + layout_config = { height = 40 }, + }) +end) diff --git a/nvim/lua/plugins/toggleterm.lua b/nvim/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..912729a --- /dev/null +++ b/nvim/lua/plugins/toggleterm.lua @@ -0,0 +1,90 @@ +local status_ok, toggleterm = pcall(require, "toggleterm") +if not status_ok then + return +end + +toggleterm.setup({ + size = function(term) + if term.direction == "horizontal" then + return 12 + elseif term.direction == "vertical" then + return vim.o.columns * 0.3 + end + end, + --size = 20, + open_mapping = [[<leader>to]], + hide_numbers = true, + shade_filetypes = {}, + shade_terminals = false, + shading_factor = 1, + start_in_insert = true, + insert_mappings = true, + persist_size = true, + direction = "float", + --direction = "vertical", + --direction = "horizontal", + close_on_exit = true, + shell = vim.o.shell, + highlights = { + -- highlights which map to a highlight group name and a table of it's values + -- NOTE: this is only a subset of values, any group placed here will be set for the terminal window split + Normal = { + background = "#000000", + }, + }, + float_opts = { + width = 70, + height = 15, + winblend = 3, + border = "curved", + --winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + }, + }, +}) + +function _G.set_terminal_keymaps() + local opts = { noremap = true } + --local opts = {buffer = 0} + vim.api.nvim_buf_set_keymap(0, "t", "<esc>", [[<C-\><C-n>]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "jj", [[<C-\><C-n>]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "<C-h>", [[<C-\><C-n><C-W>h]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "<C-j>", [[<C-\><C-n><C-W>j]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "<C-k>", [[<C-\><C-n><C-W>k]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "<C-l>", [[<C-\><C-n><C-W>l]], opts) +end + +vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()") + +local Terminal = require("toggleterm.terminal").Terminal +local lazygit = Terminal:new({ cmd = "lazygit", hidden = true }) + +function _LAZYGIT_TOGGLE() + lazygit:toggle() +end + +local node = Terminal:new({ cmd = "node", hidden = true }) + +function _NODE_TOGGLE() + node:toggle() +end + +local ncdu = Terminal:new({ cmd = "ncdu", hidden = true }) + +function _NCDU_TOGGLE() + ncdu:toggle() +end + +local htop = Terminal:new({ cmd = "htop", hidden = true }) + +function _HTOP_TOGGLE() + htop:toggle() +end + +local python = Terminal:new({ cmd = "python", hidden = true }) + +function _PYTHON_TOGGLE() + python:toggle() +end diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..261e262 --- /dev/null +++ b/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,39 @@ +local status, treesitter = pcall(require, "nvim-treesitter.configs") +if (not status) then return end + +treesitter.setup { + highlight = { + enable = true, + disable = {}, + }, + indent = { + enable = true, + disable = {}, + --disable = { "python", "css" } + }, + --ensure_installed = { + -- "c", + -- "zsh", + -- "lua" + -- --"rust", + -- --"php", + -- --"json", + -- --"yaml", + -- --"swift", + -- --"css", + -- --"html", + -- --"toml", + -- --"tsx", + --}, + ensure_installed = "all", -- one of "all" or a list of languages + --ignore_install = { "" }, -- List of parsers to ignore installing + + autotag = { + enable = true, + }, +} +--vim.opt.foldmethod = "expr" +--vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + +--local parser_config = require "nvim-treesitter.parsers".get_parser_configs() +--parser_config.tsx.filetype_to_parsername = { "javascript", "typescript.tsx" } diff --git a/nvim/lua/plugins/web-devicons.lua b/nvim/lua/plugins/web-devicons.lua new file mode 100644 index 0000000..b8396bc --- /dev/null +++ b/nvim/lua/plugins/web-devicons.lua @@ -0,0 +1,12 @@ +local status, icons = pcall(require, "nvim-web-devicons") +if (not status) then return end + +icons.setup { + -- your personnal icons can go here (to override) + -- DevIcon will be appended to `name` + override = { + }, + -- globally enable default icons (default to false) + -- will get overriden by `get_icons` option + default = true +} diff --git a/nvim/lua/plugins/winbar.lua b/nvim/lua/plugins/winbar.lua new file mode 100644 index 0000000..1573828 --- /dev/null +++ b/nvim/lua/plugins/winbar.lua @@ -0,0 +1,35 @@ +require("winbar").setup({ + enabled = true, + + show_file_path = true, + show_symbols = true, + + colors = { + path = "", -- You can customize colors like #c946fd + file_name = "", + symbols = "", + }, + + icons = { + file_icon_default = "", + seperator = ">", + editor_state = "●", + lock_icon = "", + }, + + exclude_filetype = { + "help", + "startify", + "dashboard", + "packer", + "neogitstatus", + "NvimTree", + "Trouble", + "alpha", + "lir", + "Outline", + "spectre_panel", + "toggleterm", + "qf", + }, +}) diff --git a/nvim/lua/plugins/zen-mode.lua b/nvim/lua/plugins/zen-mode.lua new file mode 100644 index 0000000..7e52854 --- /dev/null +++ b/nvim/lua/plugins/zen-mode.lua @@ -0,0 +1,7 @@ +local status, zenMode = pcall(require, "zen-mode") +if (not status) then return end + +zenMode.setup { +} + +vim.keymap.set('n', '<C-w>o', '<cmd>ZenMode<cr>', { silent = true }) |
