diff options
| author | srdusr <trevorgray@srdusr.com> | 2022-10-13 23:52:54 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2022-10-13 23:52:54 +0200 |
| commit | 86628d459cabd0c29f0cdbb699e2e18807b958ed (patch) | |
| tree | 512801524e303fd9485496ed0f1dcd52d62cb38b /lua | |
| parent | c349d1f7998d97f60d3a3945ce8da166b33bf1c8 (diff) | |
| download | dotfiles-86628d459cabd0c29f0cdbb699e2e18807b958ed.tar.gz dotfiles-86628d459cabd0c29f0cdbb699e2e18807b958ed.zip | |
Removed unnecessary files/lines
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/keys.lua | 35 | ||||
| -rw-r--r-- | lua/opts.lua | 5 | ||||
| -rw-r--r-- | lua/pack.lua | 128 | ||||
| -rw-r--r-- | lua/plugins/bufferline.lua | 323 | ||||
| -rw-r--r-- | lua/plugins/bufferline.lua-202209041657.backup | 322 | ||||
| -rw-r--r-- | lua/plugins/cmp.lua | 10 | ||||
| -rw-r--r-- | lua/plugins/heirline.backup.lua | 733 | ||||
| -rw-r--r-- | lua/plugins/heirline.backup2.lua | 1921 | ||||
| -rw-r--r-- | lua/plugins/heirline.lua | 119 | ||||
| -rw-r--r-- | lua/plugins/heirline.lua-202210111610.backup | 1452 | ||||
| -rw-r--r-- | lua/plugins/heirlinenew.lua | 1342 | ||||
| -rw-r--r-- | lua/plugins/lsp.lua | 145 | ||||
| -rw-r--r-- | lua/plugins/lspOld.lsp | 531 | ||||
| -rw-r--r-- | lua/plugins/lspconfig.lua | 148 | ||||
| -rw-r--r-- | lua/plugins/lspsaga.lua | 286 |
15 files changed, 561 insertions, 6939 deletions
diff --git a/lua/keys.lua b/lua/keys.lua index 1995976..29b59c4 100644 --- a/lua/keys.lua +++ b/lua/keys.lua @@ -22,7 +22,7 @@ vim.g.mapleader = ";" map("i", "jj", "<esc>", opts) -- save quickly -map("n", ";w", ":w<CR>", d("Save buffer")) +--map("n", ";w", ":w<CR>", d("Save buffer")) --Easier split navigations, just ctrl-j instead of ctrl-w then j map("n", "<C-J>", "<C-W><C-J>", opts) @@ -42,6 +42,35 @@ map("n", "<leader>d", ":bd<cr>", opts) map("n", "<A-k>", ':let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>', opts) map("n", "<A-j>", ':let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>', opts) +map("n", "<leader><C-l>", "<Cmd>!clear<CR>", opts) +vim.cmd([[ + inoremap <A-h> <left> + inoremap <A-j> <down> + inoremap <A-k> <up> + inoremap <A-l> <right> +]]) + +vim.cmd([[ + cnoremap <A-h> <left> + cnoremap <A-j> <down> + cnoremap <A-k> <up> + cnoremap <A-l> <right> +]]) + +--vim.cmd([[ +-- cnoremap <C-A> <Home> +-- cnoremap <C-F> <Right> +-- cnoremap <C-B> <Left> +-- cnoremap <C-E> <End> +--]]) + +vim.cmd([[ + snoremap <A-h> <left> + snoremap <A-j> <down> + snoremap <A-k> <up> + snoremap <A-l> <right> +]]) + -- move block easily map("n", "<", "<<", d("Decrease indent")) map("n", ">", ">>", d("Increase indent")) @@ -144,6 +173,10 @@ endfunction nnoremap <S-h> :call ToggleHiddenAll()<CR> ]]) +vim.cmd([[ + map <leader>s :up \| saveas! %:p:r-<C-R>=strftime("%y.%m.%d-%H:%M")<CR>-bak.<C-R>=expand("%:e")<CR> \| 3sleep \| e #<CR> +]]) + -------------- Telescope -------------- --Telescope find_files cwd=.. map("n", "<leader>fc", "<cmd>lua require('telescope.builtin').commands()<cr>", opts) diff --git a/lua/opts.lua b/lua/opts.lua index 06e15fd..b52bcc8 100644 --- a/lua/opts.lua +++ b/lua/opts.lua @@ -34,7 +34,7 @@ vim.opt.inccommand = "split" -- vim.opt.ttyfast = true -- Faster redrawing. vim.opt.lazyredraw = true -- Only redraw when necessary vim.opt.keywordprg = ":help" -- :help options ---vim.opt.ruler = true -- +vim.opt.ruler = true -- vim.opt.errorbells = false -- vim.opt.list = true -- Show non-printable characters. vim.opt.showmatch = true -- @@ -124,7 +124,8 @@ vim.opt.pumheight = 10 -- pop up menu height -- Better Completion vim.opt.complete = { ".", "w", "b", "u", "t" } -- -vim.opt.completeopt = { "longest,menuone,preview" } -- +--vim.opt.completeopt = { "longest,menuone,preview" } -- +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} --vim.opt.completeopt = { "menuone", "noselect" } -- mostly just for cmp --vim.opt.completeopt = { "menu", "menuone", "noselect" } -- diff --git a/lua/pack.lua b/lua/pack.lua index b864872..48db169 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -44,6 +44,84 @@ packer.init({ return packer.startup(function(use) use("wbthomason/packer.nvim") -- Have packer manage itself + use("nvim-lua/plenary.nvim") -- Useful lua functions used ny lots of plugins + --use("jose-elias-alvarez/null-ls.nvim") + + -- lsp + use { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "neovim/nvim-lspconfig", + } + require("mason").setup() + local mason_lspconfig = require("mason-lspconfig") + mason_lspconfig.setup({ + ensure_installed = { + "pylsp", + "pyright", + "clangd", + "vim-language-server", + "bash-language-server", + "lua-language-server", + "sumneko_lua", + } + }) + use { "j-hui/fidget.nvim", + config = function() + require("fidget").setup() + end + } + use { "folke/trouble.nvim", + config = function() + require("trouble").setup() + end + } + use({ + "https://git.sr.ht/~whynothugo/lsp_lines.nvim", -- See also: https://github.com/Maan2003/lsp_lines.nvim + config = function() + require("lsp_lines").setup() + + -- disable virtual_text since it's redundant due to lsp_lines. + vim.diagnostic.config({ + virtual_text = false, + }) + end, + }) + use { "simrat39/symbols-outline.nvim", + config = function() + require("symbols-outline").setup({ + auto_close = true, + }) + end + } + use { "kosayoda/nvim-lightbulb", requires = { "antoinemadec/FixCursorHold.nvim" } } + use "folke/lsp-colors.nvim" + use "mfussenegger/nvim-lint" + use "weilbith/nvim-code-action-menu" + use "simrat39/rust-tools.nvim" + use { "saecki/crates.nvim", + requires = { "nvim-lua/plenary.nvim" }, + config = function() + require("crates").setup() + end, + } + use "lvimuser/lsp-inlayhints.nvim" -- rust-tools already provides this feature, but gopls doesn't + + -- null-ls + use { "jose-elias-alvarez/null-ls.nvim", + config = function() + require("null-ls").setup({ + sources = { + require("null-ls").builtins.diagnostics.checkmake, -- https://github.com/mrtazz/checkmake + } + }) + end + } + use({ + "SmiteshP/nvim-navic", + requires = "neovim/nvim-lspconfig", + }) + -- nvimlsp plugins --use({ -- "williamboman/mason.nvim", @@ -54,30 +132,24 @@ return packer.startup(function(use) -- }) -- end, --}) - use("williamboman/mason.nvim") - use("williamboman/mason-lspconfig.nvim") - use("neovim/nvim-lspconfig") - use("williamboman/nvim-lsp-installer") - use("glepnir/lspsaga.nvim") - use("nvim-lua/lsp-status.nvim") - --use({ - -- "glepnir/lspsaga.nvim", - -- branch = "main", - -- config = function() - -- local saga = require("lspsaga") - - -- saga.init_lsp_saga({ - -- -- your configuration - -- }) - -- end, - --}) - -- use("nvim-lua/popup.nvim") - use("nvim-lua/plenary.nvim") -- Useful lua functions used ny lots of plugins - use("jose-elias-alvarez/null-ls.nvim") + --use("williamboman/mason.nvim") + --use("williamboman/mason-lspconfig.nvim") + --use("neovim/nvim-lspconfig") + --use("williamboman/nvim-lsp-installer") + --use("glepnir/lspsaga.nvim") + --use("nvim-lua/lsp-status.nvim") use({ - "SmiteshP/nvim-navic", - requires = "neovim/nvim-lspconfig", + "glepnir/lspsaga.nvim", + branch = "main", + config = function() + local saga = require("lspsaga") + + saga.init_lsp_saga({ + -- your configuration + }) + end, }) + -- use("nvim-lua/popup.nvim") --use("SmiteshP/nvim-gps") -- autocomplete plugins use("hrsh7th/nvim-cmp") @@ -130,10 +202,10 @@ return packer.startup(function(use) use({ "nvim-telescope/telescope-symbols.nvim", after = "telescope.nvim" }) -- statusline plugins --use("nvim-lualine/lualine.nvim") - use({ - "nvim-lualine/lualine.nvim", - requires = { "kyazdani42/nvim-web-devicons", opt = true }, - }) + --use({ + -- "nvim-lualine/lualine.nvim", + -- requires = { "kyazdani42/nvim-web-devicons", opt = true }, + --}) --use({ -- "folke/trouble.nvim", -- requires = "kyazdani42/nvim-web-devicons", @@ -179,7 +251,6 @@ return packer.startup(function(use) -- UI use("karb94/neoscroll.nvim") use("folke/which-key.nvim") - use("folke/lsp-colors.nvim") use("MunifTanjim/prettier.nvim") -- Prettier plugin for Neovim's built-in LSP client use("norcalli/nvim-colorizer.lua") use("folke/zen-mode.nvim") @@ -201,16 +272,13 @@ return packer.startup(function(use) --use("lukas-reineke/indent-blankline.nvim") use("kyazdani42/nvim-web-devicons") -- Colorschemes - use("Mofiqul/vscode.nvim") use("gruvbox-community/gruvbox") use("srcery-colors/srcery-vim") use("tomasr/molokai") use("ayu-theme/ayu-vim") --use("sjl/badwolf") use("joshdick/onedark.vim") - use("folke/tokyonight.nvim") use("everblush/everblush.nvim") - use("sainnhe/edge") use("EdenEast/nightfox.nvim") use("bluz71/vim-nightfly-guicolors") --use({ "shaunsingh/oxocarbon.nvim", run = "./install.sh" }) diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua deleted file mode 100644 index 6488f29..0000000 --- a/lua/plugins/bufferline.lua +++ /dev/null @@ -1,323 +0,0 @@ -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/lua/plugins/bufferline.lua-202209041657.backup b/lua/plugins/bufferline.lua-202209041657.backup deleted file mode 100644 index 1d45e5f..0000000 --- a/lua/plugins/bufferline.lua-202209041657.backup +++ /dev/null @@ -1,322 +0,0 @@ -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/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index 39c08d7..93bc5b2 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -30,7 +30,7 @@ local kind_icons = { Function = "", Constructor = "⚙️", Field = "", - Variable = "", + Variable = "", Class = "ﴯ", Interface = "", Module = "", @@ -112,10 +112,10 @@ cmp.setup({ }, }) -vim.cmd([[ - set completeopt=menuone,noinsert,noselect - highlight! default link CmpItemKind CmpItemMenuDefault -]]) +--vim.cmd([[ +-- set completeopt=menuone,noinsert,noselect +-- highlight! default link CmpItemKind CmpItemMenuDefault +--]]) cmp.setup.cmdline("/", { mapping = cmp.mapping.preset.cmdline(), diff --git a/lua/plugins/heirline.backup.lua b/lua/plugins/heirline.backup.lua deleted file mode 100644 index d65de92..0000000 --- a/lua/plugins/heirline.backup.lua +++ /dev/null @@ -1,733 +0,0 @@ -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/lua/plugins/heirline.backup2.lua b/lua/plugins/heirline.backup2.lua deleted file mode 100644 index 9f5c4ca..0000000 --- a/lua/plugins/heirline.backup2.lua +++ /dev/null @@ -1,1921 +0,0 @@ -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/lua/plugins/heirline.lua b/lua/plugins/heirline.lua index ae2bf41..78408dc 100644 --- a/lua/plugins/heirline.lua +++ b/lua/plugins/heirline.lua @@ -6,6 +6,7 @@ local colors = { bg = nil, nobg = nil, white = "#f8f8f2", + black = "#000000", darkgray = "#23232e", gray = "#2d2b3a", lightgray = "#d6d3ea", @@ -87,7 +88,7 @@ local ViMode = { }, }, provider = function(self) - return " %2(" .. self.mode_names[self.mode] .. "%)" + return " %2(" .. self.mode_names[self.mode] .. "%) " end, hl = function(self) local color = self:mode_color() @@ -527,7 +528,7 @@ local help_file_name = { } -- Cursor position: Ruler -local Ruler = { +--local Ruler = { -- %l = current line number -- %L = number of lines in the buffer -- %c = column number @@ -545,22 +546,38 @@ local Ruler = { --provider = "%6(%l:%1.5c/%L%) ", --provider = "%3(%l:%1.5c/%L%) ", --provider = "%7(%l/%3L%):%2c ", - provider = "%7(%l:%c%) ", +-- provider = "%7(%l:%c%) ", --provider = "%l:%c ", --hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, - hl = { fg = colors.darkgray, bold = true }, -} - +-- hl = { fg = colors.darkgray, bold = true }, +--} +local leftruler = { Space, Align } +local rightruler = { Align, Space } 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, - }, + --{ provider = "", hl = { fg = utils.get_highlight("StatusLine").bg, bold = true } }, +-- { provider = "%<%-05.10(%l:%c%)", hl = { fg = colors.darkgray, bold = true } }, +-- { provider = " ", hl = { fg = colors.darkgray, bold = true } }, + --{ provider = "%P %=%<%(%l,%c)" }, + --{ provider = " %w%-8.(%l,%c%)%>" }, + { provider = " %1(%4l:%-3(%c%) %)%*", hl = { fg = colors.black, bold = true } }, } +local Ruler = { cursor_location } + + --utils.make_flexible_component( + -- 3, + -- { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + -- { provider = "%<" } + --), +--local cursor_location = { +-- { provider = "%7(%l:%c%) ", hl = { bold = true } }, +-- { +-- provider = " ", +-- hl = function(self) +-- local color = self:mode_color() +-- return { fg = color, bold = true } +-- end, +-- }, +--} local WordCount = { condition = function() @@ -787,14 +804,14 @@ local StatusLine = { v = colors.purple, V = colors.purple, ["\22"] = colors.purple, - c = colors.red, + c = colors.orange, s = colors.purple, S = colors.purple, ["\19"] = colors.purple, - R = colors.orange, - r = colors.orange, - ["!"] = colors.red, - t = colors.red, + R = colors.red, + r = colors.red, + ["!"] = colors.orange, + t = colors.orange, }, mode_color = function(self) local mode = conditions.is_active() and vim.fn.mode() or "n" @@ -813,7 +830,57 @@ local StatusLine = { DefaultStatusline, } --- WinBar + +-- +--- WinBar +-- +local WinbarFileNameBlock = { + -- 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 = { bg = colors.bg }, +} + +--local WinbarFileName = { +-- 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() +-- return { fg = colors.gray, italic = true } +-- end, +--} +local WinbarFileName = { + 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.gray, bold = false, bg = colors.bg }, +} + +WinbarFileNameBlock = utils.insert( + WinbarFileNameBlock, + FileIcon, + utils.insert(WinbarFileName), -- 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 +) + vim.api.nvim_create_autocmd("User", { pattern = "HeirlineInitWinbar", callback = function(args) @@ -888,7 +955,8 @@ local Center = { condition = function() return not conditions.is_active() end, - utils.surround({ "", "" }, colors.nobg, { Space }), + --utils.surround({ "", "" }, colors.nobg, { FileIcon, { WinbarFileName, hl = { fg = colors.gray } }, FileFlags } ), + utils.surround({ "", "" }, colors.nobg, { WinbarFileNameBlock } ), }, -- A winbar for regular files utils.surround({ "", "" }, colors.nobg, { FileNameBlock }), @@ -897,6 +965,7 @@ local Center = { --local WinBar = { Align, Center, Align } local WinBar = { Space, Center } + -- TabLine local TablineBufnr = { provider = function(self) @@ -1020,12 +1089,10 @@ 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 ;) + { 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 ;) ) - -- TabList local Tabpage = { provider = function(self) diff --git a/lua/plugins/heirline.lua-202210111610.backup b/lua/plugins/heirline.lua-202210111610.backup deleted file mode 100644 index e1a54e3..0000000 --- a/lua/plugins/heirline.lua-202210111610.backup +++ /dev/null @@ -1,1452 +0,0 @@ -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/lua/plugins/heirlinenew.lua b/lua/plugins/heirlinenew.lua deleted file mode 100644 index 64a33b2..0000000 --- a/lua/plugins/heirlinenew.lua +++ /dev/null @@ -1,1342 +0,0 @@ -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/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 5e7a680..3570a98 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -1,43 +1,69 @@ + 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) + -- Enable completion triggered by <c-x><c-o> + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + +local status, saga = pcall(require, "lspsaga") +if not status then + return +end + -- Mappings. local map = function(mode, l, r, opts) opts = opts or {} opts.silent = true + opts.noremap = 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" }) +--map("n", "gd", "<Cmd>Lspsaga lsp_finder<CR>") -- Press "o" to open the reference location +--map("n", "gp", "<Cmd>Lspsaga peek_definition<CR>") +-- --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", "<leader>rn", vim.lsp.buf.rename, { desc = "varialble 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", "<leader>q", function() +-- vim.diagnostic.setqflist({ open = true }) +-- end, { desc = "put diagnostic to qf" }) +-- --map.('n', '<space>q', vim.diagnostic.setloclist) +-- map("n", "ga", vim.lsp.buf.code_action, { desc = "LSP code action" }) +-- map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) +-- map("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) +-- map("n", "<leader>wl", function() +-- print(vim.inspect(vim.lsp.buf.list_workspace_folders())) +-- end, { desc = "list workspace folder" }) +-- map("n", "gs", "vim.lsp.buf.document_symbol()<cr>") +-- map("n", "gw", "vim.lsp.buf.workspace_symbol()<cr>", { desc = "list workspace folder" }) +-- --map("n", "gs", ":lua vim.lsp.buf.document_symbol()<cr>") +-- map("n", "gt", ":lua vim.lsp.buf.type_definition()<cr>") +-- map("n", "gD", ":lua vim.lsp.buf.declaration()<cr>") -- most lsp servers don't implement textDocument/Declaration, so gD is useless for now. +-- map("n", "gi", ":lua vim.lsp.buf.implementation()<cr>") +-- map("n", "go", ":lua vim.diagnostic.open_float()<cr>") +-- map("n", "gk", "<Cmd>Lspsaga diagnostic_jump_prev<CR>") +-- map("n", "gj", "<Cmd>Lspsaga diagnostic_jump_next<CR>") -- 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 - api.nvim_create_autocmd("CursorHold", { + -- add rust specific keymappings + if client.name == "rust_analyzer" then + map("n", "<leader>rr", "<cmd>RustRunnables<CR>") + map("n", "<leader>ra", "<cmd>RustHoverAction<CR>") + end + + -- Diagnostic position + vim.api.nvim_create_autocmd("CursorHold", { buffer = bufnr, callback = function() local float_opts = { @@ -52,7 +78,7 @@ local custom_attach = function(client, bufnr) vim.b.diagnostics_pos = { nil, nil } end - local cursor_pos = api.nvim_win_get_cursor(0) + 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 @@ -64,7 +90,7 @@ local custom_attach = function(client, bufnr) end, }) - -- The blow command will highlight the current variable and its usages in the buffer. + -- 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 @@ -80,19 +106,19 @@ local custom_attach = function(client, bufnr) 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 = "Nvim-config" }) + vim.notify(msg, vim.log.levels.DEBUG, { title = "Server?" }) end end -local capabilities = lsp.protocol.make_client_capabilities() +local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.offsetEncoding = { "utf-16" } local lspconfig = require("lspconfig") if utils.executable("pylsp") then lspconfig.pylsp.setup({ - on_attach = custom_attach, settings = { pylsp = { plugins = { @@ -111,7 +137,7 @@ if utils.executable("pylsp") then capabilities = capabilities, }) else - vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" }) + vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Server?" }) end -- if utils.executable('pyright') then @@ -120,7 +146,7 @@ end -- capabilities = capabilities -- } -- else --- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) +-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Server?'}) -- end if utils.executable("clangd") then @@ -133,7 +159,7 @@ if utils.executable("clangd") then }, }) else - vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Nvim-config" }) + vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Server?" }) end -- set up vim-language-server @@ -146,7 +172,7 @@ if utils.executable("vim-language-server") then capabilities = capabilities, }) else - vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" }) + vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Server?" }) end -- set up bash-language-server @@ -158,7 +184,6 @@ if utils.executable("bash-language-server") then 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 = { @@ -173,8 +198,6 @@ if utils.executable("lua-language-server") then }, 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"), @@ -188,40 +211,58 @@ if utils.executable("lua-language-server") then }) end --- Change diagnostic signs. ---fn.sign_define("DiagnosticSignError", { text = "✗", texthl = "DiagnosticSignError" }) ---fn.sign_define("DiagnosticSignWarn", { text = "!", texthl = "DiagnosticSignWarn" }) ---fn.sign_define("DiagnosticSignInformation", { text = "", texthl = "DiagnosticSignInfo" }) ---fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) +--lspconfig.sumneko_lua.setup({ +-- single_file_support = true, +-- on_attach = function(client, bufnr) +-- print('hello') +-- lspconfig.util.default_config.on_attach(client, bufnr) +-- end +--}) +require('lspconfig')['rust_analyzer'].setup{ + on_attach = custom_attach, + flags = { + debounce_text_changes = 500, + }, --- global config for diagnostic + -- Server-specific settings... + settings = { + ["rust-analyzer"] = {} + } +} +-- Global config for diagnostic vim.diagnostic.config({ underline = false, - virtual_text = false, + virtual_text = true, signs = true, severity_sort = true, + float = { + focusable = true, -- + style = "minimal", -- + --border = "rounded", + border = "shadow", + source = "always", + header = "", + prefix = "", + }, }) -lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, { +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.buf.definition +--vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) + +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 = "⚑" } +--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 - ---sign({name = 'DiagnosticSignError', text = '✘'}) ---sign({name = 'DiagnosticSignWarn', text = '▲'}) ---sign({name = 'DiagnosticSignHint', text = '⚑'}) ---sign({name = 'DiagnosticSignInfo', text = ''}) - --- Change border of documentation hover window, See https://github.com/neovim/neovim/pull/13998. -lsp.handlers["textDocument/hover"] = lsp.with(vim.lsp.handlers.hover, { - border = "rounded", -}) diff --git a/lua/plugins/lspOld.lsp b/lua/plugins/lspOld.lsp deleted file mode 100644 index 206ea57..0000000 --- a/lua/plugins/lspOld.lsp +++ /dev/null @@ -1,531 +0,0 @@ --- 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/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua deleted file mode 100644 index a130dcd..0000000 --- a/lua/plugins/lspconfig.lua +++ /dev/null @@ -1,148 +0,0 @@ ---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/lua/plugins/lspsaga.lua b/lua/plugins/lspsaga.lua index ceb1099..1d03666 100644 --- a/lua/plugins/lspsaga.lua +++ b/lua/plugins/lspsaga.lua @@ -1,61 +1,245 @@ -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 = { +require "lspsaga".init_lsp_saga { + --border_style = "single", + saga_winblend = 20, + -- float_term = { + -- winblend = 25, + -- shadow_background = false, + -- }, + move_in_saga = { next = '<C-n>', prev = '<C-p>' }, + --move_in_saga = { prev = "k", next = "j" }, + 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, - }, -}) + diagnostic_header = { " ", " ", " ", " " }, + -- add bracket or something with diagnostic source, just have 2 elements + -- use emoji lightbulb in default + code_action_icon = "", + --code_action_icon = "ﯦ ", + -- if true can press number to execute the codeaction in codeaction window + code_action_num_shortcut = true, + -- same as nvim-lightbulb but async + code_action_lightbulb = { + enable = false, + sign = false, + sign_priority = 20, -- + virtual_text = true, + }, + finder_icons = { + def = " ", + ref = " ", + link = " ", + }, + -- preview lines of lsp_finder and definition preview + max_preview_lines = 5, + definition_action_keys = { + edit = '<CR>', + vsplit = '<C-y>', + split = '<C-x>', + tabe = '<C-t>', + quit = '<ESC>', + }, + -- definition_preview_quit = '<ESC>', + -- finder_preview_hl_ns = 8, + finder_action_keys = { + open = "o", + vsplit = "v", + split = "s", + tabe = "t", + quit = "<ESC>", + scroll_down = "<C-j>", + scroll_up = "<C-k>", -- quit can be a table + }, + code_action_keys = { + quit = "<ESC>", + exec = "l", + }, + rename_action_quit = "<ESC>", + rename_in_select = true, + symbol_in_winbar = { + enable = true, + in_custom = false, + --in_custom = true, + separator = ' ', + --show_file = false, + show_file = true, + click_support = false, + }, + show_outline = { + win_position = 'right', + --set special filetype win that outline window split.like NvimTree neotree + -- defx, db_ui + min_with = '', + win_width = 40, + auto_enter = false, + auto_preview = true, + virt_text = 'x', + jump_key = 'l', + -- auto refresh when change buffer + auto_refresh = true, + }, + custom_kind = { + File = { " " }, + Module = { " " }, + Namespace = { "ﱕ " }, + Package = { " " }, + Class = { "ﴯ " }, + Method = { "" }, + Property = { "ﰠ " }, + Field = { "ﰠ " }, + Constructor = { " " }, + Enum = { " " }, + Interface = { " " }, + Function = { " " }, + Variable = { " " }, + Constant = { " " }, + String = { " " }, + Number = { " " }, + Boolean = { " " }, + Array = { " " }, + Object = { " " }, + Key = { "- " }, + Null = { " " }, + EnumMember = { " " }, + Struct = { " " }, + Event = { " " }, + Operator = { " " }, + TypeParameter = { " " }, + TypeAlias = { " " }, + Parameter = { " " }, + StaticMethod = { " " }, + Macro = { "廓" }, + }, +} -- 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", "gd", "<CMD>Lspsaga peek_definition<CR>", opts) +--map("n", "gp", "<Cmd>Lspsaga peek_definition<CR>", opts) +map("n", "gi", "<CMD>Lspsaga lsp_finder<CR>", opts) +--map("n", "gh", "<CMD>Lspsaga hover_doc<CR>", opts) +map("n", "gs", "<CMD>Lspsaga signature_help<CR>", opts) +map("n", "ga", "<CMD>Lspsaga code_action<CR>", opts) +map("v", "ga", "<CMD><C-u>Lspsaga range_code_action<CR>", opts) +map("n", "gl", "<CMD>Lspsaga show_line_diagnostics<CR>", opts) +map("n", "go", "<CMD>Lspsaga open_floaterm fish<CR>", opts) +map("n", ";D", "<CMD>Lspsaga show_cursor_diagnostics<CR>", opts) +map("n", "<gr>", "<CMD>Lspsaga rename<CR>", opts) +map("n", "gk", "<CMD>Lspsaga diagnostic_jump_prev<CR>", opts) +map("n", "gj", "<CMD>Lspsaga diagnostic_jump_next<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) +map("t", "<ESC>", "<CMD>Lspsaga close_floaterm<CR>", opts) + + + + +-- vim.keymap.set("n", "<C-f>", function() require "lspsaga.action".smart_scroll_with_saga(1) end, opts) +-- vim.keymap.set("n", "<C-b>", function() require "lspsaga.action".smart_scroll_with_saga(-1) end, opts) + + + +vim.api.nvim_set_hl(0, "LspSagaHoverBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaTermBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspFloatWinBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaAutoPrew", { bg = "NONE", fg = "#BBE73D", }) +vim.api.nvim_set_hl(0, "LspSagaAutoPreview", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaBorderTitle", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaCodeActionBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaCodeActionContent", { bg = "NONE", fg = "#000000", }) +vim.api.nvim_set_hl(0, "LspSagaCodeActionTitle", { bg = "NONE", fg = "#000000", }) +vim.api.nvim_set_hl(0, "LspSagaCodeActionTrunCateLine", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "DefinitionBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "DefinitionArror", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "DefinitionSearch", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "DefinitionFile", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticSource", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticQuickFix", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticMap", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticLineCol", { bg = "NONE", fg = "#929292", }) + +vim.api.nvim_set_hl(0, "LspSagaDiagnosticBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticHeader", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticError", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticWarn", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticInfo", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticHint", { bg = "NONE", fg = "#929292", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticSource", { bg = "NONE", fg = "#C53B82", }) +vim.api.nvim_set_hl(0, "LspSagaDiagnosticTruncateLine", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaErrorTrunCateLine", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaFinderSelection", { bg = "NONE", fg = "#888888", }) +vim.api.nvim_set_hl(0, "LspSagaHintTrunCateLine", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaHoverTrunCateLine", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaInfoTrunCateLine", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaLightBulb", { bg = "NONE", fg = "#BBE73D", }) +vim.api.nvim_set_hl(0, "LspSagaLspFinderBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaRenameBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaRenameMatch", { bg = "NONE", fg = "#C53B82", }) +vim.api.nvim_set_hl(0, "LspSagaShTrunCateLine", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaSignatureHelpBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "LspSagaTrunCatgeLine", { bg = "NONE", fg = "#353535", }) + +vim.api.nvim_set_hl(0, "TargetFileName", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "FinderParam", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "FinderVirtText", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "DefinitionsIcon", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "Definitions", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "ReferencesIcon", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "References", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "DefinitionCount", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "ReferencesCount", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "FinderPreviewSearch", { bg = "NONE", fg = "#888888", }) +vim.api.nvim_set_hl(0, "FinderSpinnerBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "FinderSpinnerTitle", { bg = "NONE", fg = "#C53B82", }) +vim.api.nvim_set_hl(0, "FinderSpinner", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "DefinitionPreviewTitle", { bg = "NONE", fg = "#666666", }) +vim.api.nvim_set_hl(0, "SagaShadow", { bg = "NONE", fg = "#000000", }) +-- +---- Outline +vim.api.nvim_set_hl(0, "LSOutlinePreviewBorder", { bg = "NONE", fg = "#353535", }) +vim.api.nvim_set_hl(0, "OutlineIndentEvn", { bg = "NONE", fg = "#ffffff", }) +vim.api.nvim_set_hl(0, "OutlineIndentOdd", { bg = "NONE", fg = "#ffffff", }) +vim.api.nvim_set_hl(0, "OutlineFoldPrefix", { bg = "NONE", fg = "#000000", }) +vim.api.nvim_set_hl(0, "OutlineDetail", { bg = "NONE", fg = "#383838", }) +-- +vim.api.nvim_set_hl(0, "LSOutLineFile", { bg = "NONE", fg = "#AF87D7" }) +vim.api.nvim_set_hl(0, "LSOutLineModule", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineNamespace", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLinePackage", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineClass", { bg = "NONE", fg = "#BBE73D", bold = true, italic = true }) +vim.api.nvim_set_hl(0, "LSOutLineMethod", { bg = "NONE", fg = "#C53B82", italic = true }) +vim.api.nvim_set_hl(0, "LSOutLineProperty", { bg = "NONE", fg = "#6A5A9D" }) +vim.api.nvim_set_hl(0, "LSOutLineField", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineConstructor", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineEnum", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineInterface", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineFunction", { bg = "NONE", fg = "#C53B82", bold = true, italic = true }) +vim.api.nvim_set_hl(0, "LSOutLineVariable", { bg = "NONE", fg = "#696969" }) +vim.api.nvim_set_hl(0, "LSOutLineConstant", { bg = "NONE", fg = "#C53B82" }) +vim.api.nvim_set_hl(0, "LSOutLineString", { bg = "NONE", fg = "#444444" }) +vim.api.nvim_set_hl(0, "LSOutLineNumber", { bg = "NONE", fg = "#AFC460" }) +vim.api.nvim_set_hl(0, "LSOutLineBoolean", { bg = "NONE", fg = "#C53B82" }) +vim.api.nvim_set_hl(0, "LSOutLineArray", { bg = "NONE", fg = "#614F97" }) +vim.api.nvim_set_hl(0, "LSOutLineObject", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineKey", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineNull", { bg = "NONE", fg = "#C53B82" }) +vim.api.nvim_set_hl(0, "LSOutLineEnummember", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineStruct", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineEvent", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineOperator", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineTypeparameter", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineTypealias", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineParameter", { bg = "NONE", fg = "#8567A3" }) +vim.api.nvim_set_hl(0, "LSOutLineStaticmethod", { bg = "NONE", fg = "#666666" }) +vim.api.nvim_set_hl(0, "LSOutLineMacro", { bg = "NONE", fg = "#666666" }) + + +-- vim.api.nvim_create_autocmd("BufEnter", { +-- callback = function () +-- if #vim.api.nvim_list_wins() == 1 and vim.bo.filetype == "lspsagaoutline" then +-- vim.cmd "quit" +-- end +-- end +-- }) |
