From e59bb0ba04b9bad6b9d3f423c6390b0ec8644a3f Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Wed, 11 Jan 2023 14:37:38 +0100 Subject: [PATCH] nvim/vim: add lsp to lualine --- files/nvim/.config/nvim/init.lua | 2 +- .../.config/nvim/lua/plugins/lualine-conf.lua | 89 +++++++++---------- files/tmux/.tmux.conf | 12 +-- 3 files changed, 47 insertions(+), 56 deletions(-) diff --git a/files/nvim/.config/nvim/init.lua b/files/nvim/.config/nvim/init.lua index 155221a..8c7ad58 100644 --- a/files/nvim/.config/nvim/init.lua +++ b/files/nvim/.config/nvim/init.lua @@ -4,7 +4,7 @@ -- -- Rollback possible with packer.nvim -- Always create a snapshot BEFORE upgrading, so we can rollback if we find sth --- `:PackerSnapshot --` +-- `:PackerSnapshot YEAR-MONTH-DAY -- Location: ~/.cache/nvim/packer.nvim -- This must be loaded first diff --git a/files/nvim/.config/nvim/lua/plugins/lualine-conf.lua b/files/nvim/.config/nvim/lua/plugins/lualine-conf.lua index 92e63be..390c26c 100644 --- a/files/nvim/.config/nvim/lua/plugins/lualine-conf.lua +++ b/files/nvim/.config/nvim/lua/plugins/lualine-conf.lua @@ -1,6 +1,41 @@ -- startup breadcrumbs require 'nvim-navic'.setup({}) +local function showTrailing() + local space = vim.fn.search([[\s\+$]], 'nwc') + return space ~= 0 and "TW:" .. space or "" +end + +local function showWordcount() + if vim.bo.filetype == "markdown" or vim.bo.filetype == "tex" then + if vim.fn.wordcount().visual_words == 1 then + return tostring(vim.fn.wordcount().visual_words) .. " word" + elseif not (vim.fn.wordcount().visual_words == nil) then + return tostring(vim.fn.wordcount().visual_words) .. " words" + else + return tostring(vim.fn.wordcount().words) .. " words" + end + else + return "" + end +end + +local function showLsp() + local msg = 'No Lsp' + local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype') + local clients = vim.lsp.get_active_clients() + if next(clients) == nil then + return msg + end + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return " " .. client.name + end + end + return " " .. msg +end + -- used as mode-module -- https://github.com/nvim-lualine/lualine.nvim/issues/614 local mode_map = { @@ -46,37 +81,9 @@ require('lualine').setup({ -- lualine comes with 'everforest' theme theme = 'everforest', }, - -- tabline = { - -- lualine_a = { - -- -- function() - -- -- return mode_map[vim.api.nvim_get_mode().mode] or "__" - -- -- end - -- function() - -- return '裡' - -- end, - -- }, - -- lualine_b = { - -- { - -- 'tabs', - -- mode = 2, - -- max_length = vim.o.columns / 2 - -- } - -- }, - -- lualine_c = { - -- - -- }, - -- lualine_x = { - -- -- 'lsp_progress' -- noice already shows this.. better - -- }, - -- lualine_y = { - -- require('nvim-navic').get_location - -- }, - -- lualine_z = { - -- } - -- }, - -- all sections from left to right sections = { lualine_a = { + -- mode icon function() return mode_map[vim.api.nvim_get_mode().mode] or "__" end @@ -88,6 +95,7 @@ require('lualine').setup({ { 'filename', path = 1, + shorting_target = 80, }, }, lualine_x = { @@ -104,29 +112,12 @@ require('lualine').setup({ 'encoding', 'fileformat', 'filetype', + { showLsp } }, lualine_z = { - -- show wordcount in md and tex file - -- show precise count when selecting - function() - if vim.bo.filetype == "markdown" or vim.bo.filetype == "tex" then - if vim.fn.wordcount().visual_words == 1 then - return tostring(vim.fn.wordcount().visual_words) .. " word" - elseif not (vim.fn.wordcount().visual_words == nil) then - return tostring(vim.fn.wordcount().visual_words) .. " words" - else - return tostring(vim.fn.wordcount().words) .. " words" - end - else - return "" - end - end, + { showWordcount }, 'location', - -- Show trailing whitespace - function() - local space = vim.fn.search([[\s\+$]], 'nwc') - return space ~= 0 and "TW:" .. space or "" - end, + { showTrailing }, }, }, }) diff --git a/files/tmux/.tmux.conf b/files/tmux/.tmux.conf index 42a1eaf..c1c00a0 100644 --- a/files/tmux/.tmux.conf +++ b/files/tmux/.tmux.conf @@ -80,17 +80,17 @@ set-option -g set-titles-string "#H: #W" set -g status-position top set -g status-justify "left" set -g status "on" -set -g message-command-style "fg=#829181,bg=#FDF6E3" +set -g message-command-style "fg=#829181,bg=#f4f0d9" set -g pane-active-border-style "fg=#93b259" -set -g status-style "none,bg=#FDF6E3" -set -g message-style "fg=#829181,bg=#FDF6E3" +set -g status-style "none,bg=#f4f0d9" +set -g message-style "fg=#829181,bg=#f4f0d9" set -g pane-border-style "fg=#e9e8d2" set -g status-right-length "100" set -g status-left-length "100" -setw -g window-status-activity-style "none,fg=#93b259,bg=#FDF6E3" -setw -g window-status-style "none,fg=#939f91,bg=#FDF6E3" +setw -g window-status-activity-style "none,fg=#93b259,bg=#f4f0d9" +setw -g window-status-style "none,fg=#939f91,bg=#f4f0d9" set -g status-left "" # show battery only on laptop -if-shell "[ `hostname` = 'itomori' ]" 'set -g status-right "#[fg=#939f91,bg=#FDF6E3] #H @ #S | #(cat /sys/class/power_supply/BAT1/capacity)% | %H:%M"' 'set -g status-right "#[fg=#939f91,bg=#FFF9E8] #H @ #S | %H:%M"' +if-shell "[ `hostname` = 'itomori' ]" 'set -g status-right "#[fg=#939f91,bg=#f4f0d9] #H @ #S | #(cat /sys/class/power_supply/BAT1/capacity)% | %H:%M"' 'set -g status-right "#[fg=#939f91,bg=#f4f0d9] #H @ #S | %H:%M"' setw -g window-status-format "#I:#W" setw -g window-status-current-format "#[fg=#93b259,bold]#I:#W*"