From 1616a0741806e74aaf85f6b3539de374c3ca3249 Mon Sep 17 00:00:00 2001 From: Michaël Ball Date: Fri, 19 Jul 2024 14:16:35 +0100 Subject: Refactor neovim config --- neovim/.config/nvim/init.lua | 3 +- neovim/.config/nvim/lua/config/colourscheme.lua | 2 +- neovim/.config/nvim/lua/plugins/galaxyline.lua | 136 ++++++++++------ neovim/.config/nvim/lua/plugins/lspsaga.lua | 3 +- neovim/.config/nvim/lua/plugins/nvim_lspconfig.lua | 173 ++++++++++++--------- neovim/.config/nvim/lua/settings.lua | 6 +- 6 files changed, 194 insertions(+), 129 deletions(-) (limited to 'neovim/.config/nvim') diff --git a/neovim/.config/nvim/init.lua b/neovim/.config/nvim/init.lua index 9f86514..b3979ea 100644 --- a/neovim/.config/nvim/init.lua +++ b/neovim/.config/nvim/init.lua @@ -1,2 +1,3 @@ -require('settings') require('config.lazy') +require('settings') +require('config.colourscheme') diff --git a/neovim/.config/nvim/lua/config/colourscheme.lua b/neovim/.config/nvim/lua/config/colourscheme.lua index d5ffa34..edba16f 100644 --- a/neovim/.config/nvim/lua/config/colourscheme.lua +++ b/neovim/.config/nvim/lua/config/colourscheme.lua @@ -1,5 +1,5 @@ local colorscheme = "xcode" -vim.o.background = "light" -- or "light" for light mode +vim.o.background = "light" local ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) if not ok then vim.notify("colorscheme " .. colorscheme .. " not found!") diff --git a/neovim/.config/nvim/lua/plugins/galaxyline.lua b/neovim/.config/nvim/lua/plugins/galaxyline.lua index 9f58157..f2edff6 100644 --- a/neovim/.config/nvim/lua/plugins/galaxyline.lua +++ b/neovim/.config/nvim/lua/plugins/galaxyline.lua @@ -10,11 +10,33 @@ return { 'arzg/vim-colors-xcode', lazy = false, priority = 1000, - config = function() - vim.cmd[[colorscheme xcode]] - end + config = function () + local colorscheme_rules_augroup = vim.api.nvim_create_augroup('Colors', {}) + vim.api.nvim_create_autocmd( { 'ColorScheme' }, { + pattern = { '*' }, + group = colorscheme_rules_augroup, + callback = function() + vim.api.nvim_set_hl(0, 'WinSeparator', { link='VertSplit', force=1, default=1 }) + end, + }) + end, + dependencies = { + { + 'f-person/auto-dark-mode.nvim', + opts = { + update_interval = 1000, + set_dark_mode = function () + vim.api.nvim_set_option('background', 'dark') + end, + set_light_mode = function () + vim.api.nvim_set_option('background', 'light') + end + } + } + }, }, }, + event = 'VimEnter', config = function() local gl = require('galaxyline') local colors = { @@ -31,50 +53,66 @@ return { local condition = require('galaxyline.condition') local gls = gl.section local lsp = require('galaxyline.provider_lsp') - gl.short_line_list = {'nerdtree', 'NeogitStatus', 'vim-plug', 'lspsagaoutline'} + gl.short_line_list = { 'nerdtree', 'NeogitStatus', 'vim-plug', 'lspsagaoutline', 'neo-tree' } gls.left[1] = { RainbowBlue = { - provider = function() return '▊ ' end, - highlight = {colors.blue, 'StatusLine'} + provider = function() + return '▊ ' + end, + highlight = { colors.blue, 'StatusLine' } }, } gls.left[2] = { ViMode = { provider = function() -- auto change color according the vim mode - local mode_color = {n = colors.red, i = colors.green,v=colors.blue, - ['^V'] = colors.blue,V=colors.blue, - c = colors.magenta,no = colors.red,s = colors.orange, - S=colors.orange,['^S'] = colors.orange, - ic = colors.yellow,R = colors.violet,Rv = colors.violet, - cv = colors.red,ce=colors.red, r = colors.cyan, - rm = colors.cyan, ['r?'] = colors.cyan, - ['!'] = colors.red,t = colors.red} - vim.api.nvim_command('hi GalaxyViMode guifg='..mode_color[vim.fn.mode()]) + local mode_color = { + n = colors.red, + i = colors.green, + v = colors.blue, + ['^V'] = colors.blue, + V = colors.blue, + c = colors.magenta, + no = colors.red, + s = colors.orange, + S = colors.orange, + ['^S'] = colors.orange, + ic = colors.yellow, + R = colors.violet, + Rv = colors.violet, + cv = colors.red, + ce = colors.red, + r = colors.cyan, + rm = colors.cyan, + ['r?'] = colors.cyan, + ['!'] = colors.red, + t = colors.red + } + vim.api.nvim_command('hi GalaxyViMode guifg=' .. mode_color[vim.fn.mode()]) return ' ' end, - highlight = {colors.red, 'StatusLine', 'bold'}, - }, + highlight = { colors.red, 'StatusLine', 'bold' }, + }, } gls.left[3] = { FileSize = { provider = 'FileSize', condition = condition.buffer_not_empty, - highlight = {'StatusLine', 'StatusLine'}, + highlight = { 'StatusLine', 'StatusLine' }, } } - gls.left[4] ={ + gls.left[4] = { FileIcon = { provider = 'FileIcon', condition = function() - if vim.g.GtkGuiLoaded ~= nil and condition.buffer_not_empty() then - return true - end - return false + if vim.g.GtkGuiLoaded ~= nil and condition.buffer_not_empty() then + return true + end + return false end, - highlight = {require('galaxyline.provider_fileinfo').get_file_icon_color, 'StatusLine'}, + highlight = { require('galaxyline.provider_fileinfo').get_file_icon_color, 'StatusLine' }, }, } @@ -82,7 +120,7 @@ return { FileName = { provider = 'FileName', condition = condition.buffer_not_empty, - highlight = {colors.magenta, 'StatusLine', 'bold'} + highlight = { colors.magenta, 'StatusLine', 'bold' } } } @@ -90,8 +128,8 @@ return { LineInfo = { provider = 'LineColumn', separator = ' ', - separator_highlight = {'NONE', 'StatusLine'}, - highlight = {'NONE', 'StatusLine'}, + separator_highlight = { 'NONE', 'StatusLine' }, + highlight = { 'NONE', 'StatusLine' }, }, } @@ -99,8 +137,8 @@ return { PerCent = { provider = 'LinePercent', separator = ' ', - separator_highlight = {'NONE', 'StatusLine'}, - highlight = {'NONE', 'StatusLine', 'bold'}, + separator_highlight = { 'NONE', 'StatusLine' }, + highlight = { 'NONE', 'StatusLine', 'bold' }, } } @@ -108,14 +146,14 @@ return { DiagnosticError = { provider = 'DiagnosticError', icon = '  ', - highlight = {colors.red, 'StatusLine'} + highlight = { colors.red, 'StatusLine' } } } gls.left[9] = { DiagnosticWarn = { provider = 'DiagnosticWarn', icon = '  ', - highlight = {colors.yellow, 'StatusLine'}, + highlight = { colors.yellow, 'StatusLine' }, } } @@ -123,7 +161,7 @@ return { DiagnosticHint = { provider = 'DiagnosticHint', icon = '  ', - highlight = {colors.cyan, 'StatusLine'}, + highlight = { colors.cyan, 'StatusLine' }, } } @@ -131,15 +169,15 @@ return { DiagnosticInfo = { provider = 'DiagnosticInfo', icon = '  ', - highlight = {colors.blue, 'StatusLine'}, + highlight = { colors.blue, 'StatusLine' }, } } gls.mid[1] = { ShowLspClient = { provider = 'GetLspClient', - condition = function () - local tbl = {['dashboard'] = true,['']=true} + condition = function() + local tbl = { ['dashboard'] = true, [''] = true } if tbl[vim.bo.filetype] then return false elseif lsp.get_lsp_client() == 'No Active Lsp' then @@ -148,7 +186,7 @@ return { return true end, icon = '⚙ LSP:', - highlight = {colors.cyan, 'StatusLine','bold'} + highlight = { colors.cyan, 'StatusLine', 'bold' } } } @@ -157,8 +195,8 @@ return { provider = function() return '  ' end, condition = condition.check_git_workspace, separator = ' ', - separator_highlight = {'NONE', 'StatusLine'}, - highlight = {colors.violet, 'StatusLine', 'bold'}, + separator_highlight = { 'NONE', 'StatusLine' }, + highlight = { colors.violet, 'StatusLine', 'bold' }, } } @@ -166,7 +204,7 @@ return { GitBranch = { provider = 'GitBranch', condition = condition.check_git_workspace, - highlight = {colors.violet, 'StatusLine', 'bold'}, + highlight = { colors.violet, 'StatusLine', 'bold' }, } } @@ -175,7 +213,7 @@ return { provider = 'DiffAdd', condition = condition.hide_in_width, icon = ' +', - highlight = {colors.green, 'StatusLine'}, + highlight = { colors.green, 'StatusLine' }, } } gls.right[4] = { @@ -183,7 +221,7 @@ return { provider = 'DiffModified', condition = condition.hide_in_width, icon = ' ±', - highlight = {colors.orange, 'StatusLine'}, + highlight = { colors.orange, 'StatusLine' }, } } gls.right[5] = { @@ -191,14 +229,14 @@ return { provider = 'DiffRemove', condition = condition.hide_in_width, icon = ' -', - highlight = {colors.red, 'StatusLine'}, + highlight = { colors.red, 'StatusLine' }, } } gls.right[6] = { RainbowBlue = { provider = function() return ' ▊' end, - highlight = {colors.blue, 'StatusLine'} + highlight = { colors.blue, 'StatusLine' } }, } @@ -206,23 +244,23 @@ return { BufferType = { provider = 'FileTypeName', separator = ' ', - separator_highlight = {'NONE', 'StatusLine'}, - highlight = {colors.blue, 'StatusLine', 'bold'} + separator_highlight = { 'NONE', 'StatusLine' }, + highlight = { colors.blue, 'StatusLine', 'bold' } } } gls.short_line_left[2] = { SFileName = { - provider = 'SFileName', + provider = 'SFileName', condition = condition.buffer_not_empty, - highlight = {'StatusLine', 'StatusLine', 'bold'} + highlight = { 'StatusLine', 'StatusLine', 'bold' } } } gls.short_line_right[1] = { BufferIcon = { - provider= 'BufferIcon', - highlight = {'StatusLine', 'StatusLine'}, + provider = 'BufferIcon', + highlight = { 'StatusLine', 'StatusLine' }, } } end, diff --git a/neovim/.config/nvim/lua/plugins/lspsaga.lua b/neovim/.config/nvim/lua/plugins/lspsaga.lua index 1fe1194..f9414e8 100644 --- a/neovim/.config/nvim/lua/plugins/lspsaga.lua +++ b/neovim/.config/nvim/lua/plugins/lspsaga.lua @@ -1,8 +1,7 @@ return { { 'nvimdev/lspsaga.nvim', - lazy = false, - priority = 500, + event = 'LspAttach', dependencies = { 'nvim-tree/nvim-web-devicons', }, diff --git a/neovim/.config/nvim/lua/plugins/nvim_lspconfig.lua b/neovim/.config/nvim/lua/plugins/nvim_lspconfig.lua index f03db19..3d02f49 100644 --- a/neovim/.config/nvim/lua/plugins/nvim_lspconfig.lua +++ b/neovim/.config/nvim/lua/plugins/nvim_lspconfig.lua @@ -1,80 +1,111 @@ return { - { - 'neovim/nvim-lspconfig', - lazy = false, - priority = 800, - config = function() - local nvim_lsp = require('lspconfig') - local capabilities = require('cmp_nvim_lsp').default_capabilities() - -- Use a loop to conveniently call 'setup' on multiple servers and - -- map buffer local keybindings when the language server attaches - local servers = { "bashls", "clangd", "cssls", "gopls", "html", "jsonls", "pylsp", "rust_analyzer", "yamlls" } - for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup { - capabilities = capabilities, - flags = { - debounce_text_changes = 150, - } - } - end + { + 'neovim/nvim-lspconfig', + lazy = false, + priority = 800, + config = function() + local nvim_lsp = require('lspconfig') + local capabilities = require('cmp_nvim_lsp').default_capabilities() + -- Use a loop to conveniently call 'setup' on multiple servers and + -- map buffer local keybindings when the language server attaches + local servers = { "bashls", "clangd", "cssls", "gopls", "html", "jsonls", "rust_analyzer", "yamlls" } + for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + } + } + end - require'lspconfig'.lua_ls.setup { - on_init = function(client) - local path = client.workspace_folders[1].name - if vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc') then - return - end + require 'lspconfig'.lua_ls.setup { + on_init = function(client) + local path = client.workspace_folders[1].name + if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then + return + end - client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { - runtime = { - -- Tell the language server which version of Lua you're using - -- (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT' - }, - -- Make the server aware of Neovim runtime files - workspace = { - checkThirdParty = false, - library = { - vim.env.VIMRUNTIME - -- Depending on the usage, you might want to add additional paths here. - -- "${3rd}/luv/library" - -- "${3rd}/busted/library", - } - -- or pull in all of 'runtimepath'. NOTE: this is a lot slower - -- library = vim.api.nvim_get_runtime_file("", true) + client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT' + }, + -- Make the server aware of Neovim runtime files + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME + -- Depending on the usage, you might want to add additional paths here. + -- "${3rd}/luv/library" + -- "${3rd}/busted/library", + } + -- or pull in all of 'runtimepath'. NOTE: this is a lot slower + -- library = vim.api.nvim_get_runtime_file("", true) + } + }) + end, + settings = { + Lua = { + format = { + enable = true, + defaultConfig = { + indent_style = "space", + indent_size = "2", + } + }, + }, + + }, + capabilities = capabilities, } - }) - end, - settings = { - Lua = {} - }, - capabilities = capabilities, - } - require'lspconfig'.tsserver.setup { - filetypes = { 'typescript', 'typescriptreact', 'typescript.tsx' }, - capabilities = capabilities, - flags = { - debounce_text_changes = 150, - }, - } + require 'lspconfig'.tsserver.setup { + filetypes = { 'typescript', 'typescriptreact', 'typescript.tsx' }, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, + } + + require 'lspconfig'.pylsp.setup { + settings = { + pylsp = { + plugins = { + black = { + enabled = false, + }, + ruff = { + enabled = true, + formatEnabled = true, + extendSelect = { 'I' }, + format = { 'I' }, + } + } + } + }, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, + } - -- Use LspAttach autocommand to only map the following keys - -- after the language server attaches to the current buffer - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('UserLspConfig', {}), - callback = function(ev) - -- Enable completion triggered by - vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + -- Use LspAttach autocommand to only map the following keys + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' - local opts = { buffer = ev.buf } - vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', { noremap = true }) - vim.keymap.set('x', 'f', 'lua vim.lsp.buf.range_formatting()', {}) - vim.keymap.set('n', 'f', function() - vim.lsp.buf.format { async = true } - end, opts) + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', { noremap = true }) + vim.keymap.set('v', 'f', vim.lsp.buf.format, { noremap = true, silent = true }) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, + }) end, - }) - end, - }, + }, } diff --git a/neovim/.config/nvim/lua/settings.lua b/neovim/.config/nvim/lua/settings.lua index c3807e2..98d9a01 100644 --- a/neovim/.config/nvim/lua/settings.lua +++ b/neovim/.config/nvim/lua/settings.lua @@ -25,7 +25,6 @@ vim.opt.linebreak = true vim.opt.showbreak = '↪ ' vim.opt.breakindent = true vim.opt.termguicolors = true -vim.opt.background = 'light' vim.cmd[[ syntax on filetype on @@ -39,14 +38,11 @@ vim.opt.updatetime = 300 vim.opt.shortmess:append 'c' vim.opt.signcolumn = 'yes' -vim.keymap.set("", "", "tabprevious", { noremap=true }) -vim.keymap.set("", "", "tabnext", { noremap=true }) - -- Autocommands local indent_rules_augroup = vim.api.nvim_create_augroup('Indents', {}) vim.api.nvim_create_autocmd( { 'FileType' }, { - pattern = { 'make', 'sh' }, + pattern = { 'make', 'sh', 'zsh' }, group = indent_rules_augroup, callback = function() vim.opt_local.tabstop = 8 -- cgit v1.2.3