From 3be3b6eacef103c8183f50986b30f7023c4c4a95 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 15 Apr 2023 21:02:08 +0200 Subject: [PATCH] feat: switched to lazy.nvim, cleaned up plugins --- init.lua | 15 +- lua/plugins.lua | 444 ++++++++++++++++++++++----------------------- lua/statusline.lua | 7 +- 3 files changed, 235 insertions(+), 231 deletions(-) diff --git a/init.lua b/init.lua index ac5b612..e07a995 100644 --- a/init.lua +++ b/init.lua @@ -126,12 +126,21 @@ KEYBINDS:set_navigation_keys({}) --|| PLUGINS -local install_path = VIMDIR..'/pack/packer/start/packer.nvim' -if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - local packer_bootstrap = vim.fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) end +vim.opt.rtp:prepend(lazypath) PLUGINS = require('plugins') +require('lazy').setup(PLUGINS) --|| THEME diff --git a/lua/plugins.lua b/lua/plugins.lua index bc48da4..288c1c4 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -8,47 +8,189 @@ GG &GGGGGGGGGGGGGB#& ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ #P# &&#BGGGGGGGGGGG# nvim plugins BP& &GGGGGGGGGB# - &#BGPP& &#BGGGGGGGB# * tldr: managed with packer.nvim + &#BGPP& &#BGGGGGGGB# * tldr: managed with lazy.nvim &#BGGGGGPP& &&#BGGGGGGB##& - lsp: integrated + nvim-lspconfig &#GPPPGGGGGBPB &&##BGGGGGBB#&& - completion: nvim-cmp + LuaSnip #PPPPPPPGGPG BP& &&##BBGGGGGGBB#&& - syntax: nvim-treesitter PPPPPPPPPPPPGBPG&&& &&&&&&###BBBGGGGGGGBB##&& - pickers: telescope.nvim - &BGPPPPPPPPPPPPPPGGGGGGGGGGGGGGGGGGGBBB##&&& - files: nvim-tree.lua + &BGPPPPPPPPPPPPPPGGGGGGGGGGGGGGGGGGGBBB##&&& - files: neo-tree.nvim &&##BBBBGGGGGGGPGBBBBBB####&&&& - git: vim-fugitive + gitsigns.nvim &#B#& - extra: hexmode, vim-combo, - && ###& rust-tools, nvim-colorizer - &G# &&#&&& - &&& + && ###& rust-tools, nvim-colorizer, + &G# &&#&&& nvim-jdtls, vim-surround, + &&& undotree, ]]-- -local init_fn = function(use) - use 'wbthomason/packer.nvim' -- packer can manage itself +local function set_lsp_binds(_, bufnr) + require('keybinds'):set_lsp_keys({buffer=bufnr}) +end - use 'alemidev/peak.nvim' -- color scheme +return { + 'alemidev/peak.nvim', -- color scheme - -- trying this thing out - use 'lervag/wiki.vim' -- utilities for managing my wiki - use 'lervag/wiki-ft.vim' -- wiki format syntax - -- really idk about it, need to use it for a while + 'rickhowe/diffchar.vim', -- word-level diffs + 'fidian/hexmode', -- convert buffers into hex view with xxd + 'alemidev/vim-combo', -- track code combos - use 'fidian/hexmode' -- convert buffers into hex view with xxd - use 'alemidev/vim-combo' -- track code combos - use 'editorconfig/editorconfig-vim' -- respect editorconfig + 'tpope/vim-fugitive', -- better git commands + 'tpope/vim-surround', -- text object motions for surrounding - use "ellisonleao/glow.nvim" -- markdown previewer with glow + 'mbbill/undotree', -- tree undo history visualizer - use 'tpope/vim-fugitive' -- better git commands - use 'tpope/vim-surround' -- text object motions for surrounding + "stevearc/dressing.nvim", -- better vim.fn.input() and vim.fn.select() - use 'neovim/nvim-lspconfig' -- import LSP configurations - use 'simrat39/rust-tools.nvim' -- extra LSP defaults for rust - use 'mfussenegger/nvim-jdtls' -- extra LSP stuff for java + { + 'norcalli/nvim-colorizer.lua', -- show hex color codes + config = function () require('colorizer').setup() end + }, - use 'L3MON4D3/LuaSnip' -- snippet engine + { + "ellisonleao/glow.nvim", -- markdown previewer with glow + config = function() require("glow").setup() end + }, - use { + { + 'lewis6991/gitsigns.nvim', -- show diff signs in gutter + config = function() + require('gitsigns').setup { -- configure symbols and colors + signs = { + add = {hl = 'GitSignsChange', text = '╎'}, + change = {hl = 'GitSignsChange', text = '│'}, + delete = {hl = 'GitSignsDelete', text = '_'}, + topdelete = {hl = 'GitSignsDelete', text = '‾'}, + changedelete = {hl = 'GitSignsDelete', text = '~'}, + untracked = {hl = 'GitSignsUntracked', text = '╎'}, + }, + } + end + }, + + { + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', -- if parsers break upon install, check under scoop/apps/neovim/{version}/lib/nvim/parser + config = function() + require('nvim-treesitter.configs').setup({ + highlight = { enable = true }, + incremental_selection = { enable = true }, + textobjects = { enable = true } + }) + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + end + }, + + { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + "alemidev/neo-tree-symbolmap.git", + "mrbjarksen/neo-tree-diagnostics.nvim", + }, + config = function () + vim.g.neo_tree_remove_legacy_commands = 1 + require('neo-tree').setup({ + sources = { + "filesystem", + "buffers", + "git_status", + "symbolmap", + "diagnostics", + }, + }) + end + }, + + { + 'nvim-telescope/telescope.nvim', -- fuzzy finder, GUI component + dependencies = { + {'nvim-lua/plenary.nvim'}, -- some utilities made for telescope + {'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, -- fzf algorithm implemented in C for faster searches + }, + config = function() + local telescope = require('telescope') + telescope.load_extension('fzf') + telescope.setup({ + defaults = { + path_display = { "truncate" }, + layout_config = { + horizontal = { + preview_width = 0.65, + results_width = 0.35, + }, + vertical = { + mirror = false, + }, + cursor = { + preview_width = 0.6, + results_width = 0.4, + } + }, + } + }) + require('keybinds'):set_telescope_keys({}) + -- for some reason, telescope breaks folds! + -- this should fix (took it off an issue on github) + vim.api.nvim_create_autocmd('BufRead', { + callback = function() + vim.api.nvim_create_autocmd('BufWinEnter', { + once = true, + command = 'normal! zx' + }) + end + }) + end + }, + + 'mfussenegger/nvim-jdtls', -- extra LSP stuff for java + + { + 'simrat39/rust-tools.nvim', -- extra LSP defaults for rust + dependencies = { + 'hrsh7th/nvim-cmp', -- referenced here to guarantee load order + }, + config = function () + local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) + local rust_tools = require("rust-tools") + rust_tools.setup({ + tools = { + inlay_hints = { auto = true, highlight = "InlayHint" }, + hover_actions = { border = "none" }, + }, + server = { + capabilities = capabilities, + on_attach = set_lsp_binds, + }, + dap = { adapter = require('dap').adapters.lldb }, + }) + rust_tools.inlay_hints.enable() + + end + }, + + { + 'neovim/nvim-lspconfig', -- import LSP configurations + dependencies = { + 'hrsh7th/nvim-cmp', -- referenced here to guarantee load order + 'folke/neodev.nvim', -- configure lua lsp with neovim runtime + }, + config = function () + local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) + local lspconfig = require("lspconfig") + lspconfig.bashls.setup({capabilities=capabilities, on_attach=set_lsp_binds}) + lspconfig.pylsp.setup({capabilites = capabilities, on_attach = set_lsp_binds, settings = { pylsp = { plugins = { pycodestyle = { enabled = false } } } } }) + lspconfig.clangd.setup({capabilities=capabilities, on_attach=set_lsp_binds}) + lspconfig.ltex.setup({capabilities=capabilities, on_attach=set_lsp_binds}) + -- lspconfig.kotlin_language_server.setup({capabilities=capabilities, on_attach=set_lsp_binds}) + lspconfig.lua_ls.setup({capabilites=capabilities, on_attach=set_lsp_binds, settings = { Lua = { telemetry = { enable = false }}}}) -- default-on telemetry is never ok ... + end + }, + + { 'mfussenegger/nvim-dap', -- debugger adapter protocol - requires = { + dependencies = { 'rcarriga/nvim-dap-ui', --batteries-included debugger ui }, config = function() @@ -109,11 +251,11 @@ local init_fn = function(use) require('keybinds'):set_dap_keys({}) require('dapui').setup() end, - } + }, - use { + { 'hrsh7th/nvim-cmp', -- completion engine core - requires = { + dependencies = { 'hrsh7th/cmp-nvim-lsp', -- complete with LSP 'hrsh7th/cmp-nvim-lsp-signature-help', -- complete function signatures 'hrsh7th/cmp-nvim-lsp-document-symbol', -- complete document symbols @@ -122,204 +264,60 @@ local init_fn = function(use) 'rcarriga/cmp-dap', -- complete in debugger 'saadparwaiz1/cmp_luasnip', -- complete with snippets 'onsails/lspkind.nvim', -- fancy icons and formatting + 'L3MON4D3/LuaSnip', -- snippet engine }, - } - - use { - 'norcalli/nvim-colorizer.lua', - config = function () require('colorizer').setup() end - } - - use "stevearc/dressing.nvim" -- better vim.fn.input() and vim.fn.select() - - use { - 'nvim-telescope/telescope.nvim', -- fuzzy finder, GUI component - requires = { - {'nvim-lua/plenary.nvim'}, -- some utilities made for telescope - {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }, -- fzf algorithm implemented in C for faster searches - }, - config = function() - local telescope = require('telescope') - telescope.load_extension('fzf') - telescope.setup({ - defaults = { - path_display = { "truncate" }, - layout_config = { - horizontal = { - preview_width = 0.65, - results_width = 0.35, - }, - vertical = { - mirror = false, - }, - cursor = { - preview_width = 0.6, - results_width = 0.4, - } - }, - } - }) - require('keybinds'):set_telescope_keys({}) - -- for some reason, telescope breaks folds! - -- this should fix (took it off an issue on github) - vim.api.nvim_create_autocmd('BufRead', { - callback = function() - vim.api.nvim_create_autocmd('BufWinEnter', { - once = true, - command = 'normal! zx' - }) - end - }) - end - } - - use { - 'lewis6991/gitsigns.nvim', -- show diff signs in gutter - config = function() - require('gitsigns').setup { -- configure symbols and colors - signs = { - add = {hl = 'GitSignsChange', text = '╎'}, - change = {hl = 'GitSignsChange', text = '│'}, - delete = {hl = 'GitSignsDelete', text = '_'}, - topdelete = {hl = 'GitSignsDelete', text = '‾'}, - changedelete = {hl = 'GitSignsDelete', text = '~'}, - untracked = {hl = 'GitSignsUntracked', text = '╎'}, + config = function () + local cmp = require('cmp') + cmp.setup({ + formatting = { + format = function(entry, vim_item) + local kind = require("lspkind").cmp_format({ mode = "symbol" })(entry, vim_item) + kind.kind = " " .. kind.kind .. " " + return kind + end, }, - } - end - } - - use { - 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate', -- if parsers break upon install, check under scoop/apps/neovim/{version}/lib/nvim/parser - config = function() - require('nvim-treesitter.configs').setup({ - highlight = { enable = true }, - incremental_selection = { enable = true }, - textobjects = { enable = true } + snippet = { + expand = function(args) require('luasnip').lsp_expand(args.body) end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.complete(), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp_signature_help', max_item_count = 1 }, + { name = 'nvim_lsp' }, + { name = 'path', max_item_count = 3 }, + { name = 'luasnip' }, + { name = 'buffer', keyword_length = 3, max_item_count = 3 }, + }), }) - vim.opt.foldmethod = "expr" - vim.opt.foldexpr = "nvim_treesitter#foldexpr()" - end - } - - use 'nvim-treesitter/playground' - - use { - 'kyazdani42/nvim-tree.lua', -- tree file explorer, alternative to nerdtree in lua - requires = { 'kyazdani42/nvim-web-devicons' }, -- optional, for file icons - config = function() - require('nvim-tree').setup({ - view={ - adaptive_size = false, - mappings={ - list={ - { key = "", action = "close" }, - { key = "t", action = "tabnew" }, - { key = "s", action = "split" }, - { key = "", action = "vsplit" }, - } - } - } + cmp.setup.filetype({ "dap-repl", "dapui_watches" }, { + formatting = { + format = function(entry, vim_item) + local kind = require("lspkind").cmp_format({ mode = "symbol" })(entry, vim_item) + kind.kind = " " .. kind.kind .. " " + return kind + end, + }, + mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.confirm({ select = true }) }), + sources = { + { name = 'dap' }, + }, }) + -- cmp.setup.cmdline('/', { + -- formatting = { + -- format = function(entry, vim_item) + -- local kind = require("lspkind").cmp_format({ mode = "symbol" })(entry, vim_item) + -- kind.kind = " " .. kind.kind .. " " + -- return kind + -- end, + -- }, + -- mapping = cmp.mapping.preset.cmdline(), + -- sources = cmp.config.sources({ + -- { name = 'nvim_lsp_document_symbol' }, + -- { name = 'buffer', keyword_length = 3 }, + -- }) + -- }) end - } - - -- TODO this part is messy, can I make it cleaner? - -- TODO can I put these setup steps inside their respective config callback? - -- TODO can I make them also load their highlight groups? - -- TODO can I make nvim-cmp configuration smaller? - - local cmp = require('cmp') - cmp.setup({ - formatting = { - format = function(entry, vim_item) - local kind = require("lspkind").cmp_format({ mode = "symbol" })(entry, vim_item) - kind.kind = " " .. kind.kind .. " " - return kind - end, - }, - snippet = { - expand = function(args) require('luasnip').lsp_expand(args.body) end, - }, - mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.confirm({ select = true }) }), - sources = cmp.config.sources({ - { name = 'nvim_lsp_signature_help', max_item_count = 1 }, - { name = 'luasnip' }, - { name = 'nvim_lsp' }, - { name = 'path', max_item_count = 3 }, - { name = 'buffer', keyword_length = 3, max_item_count = 3 }, - }), - }) - cmp.setup.filetype({ "dap-repl", "dapui_watches" }, { - formatting = { - format = function(entry, vim_item) - local kind = require("lspkind").cmp_format({ mode = "symbol" })(entry, vim_item) - kind.kind = " " .. kind.kind .. " " - return kind - end, - }, - mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.confirm({ select = true }) }), - sources = { - { name = 'dap' }, - }, - }) - -- cmp.setup.cmdline('/', { - -- formatting = { - -- format = function(entry, vim_item) - -- local kind = require("lspkind").cmp_format({ mode = "symbol" })(entry, vim_item) - -- kind.kind = " " .. kind.kind .. " " - -- return kind - -- end, - -- }, - -- mapping = cmp.mapping.preset.cmdline(), - -- sources = cmp.config.sources({ - -- { name = 'nvim_lsp_document_symbol' }, - -- { name = 'buffer', keyword_length = 3 }, - -- }) - -- }) - - -- Setup lspconfig. - capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) - -- Replace with each lsp server you've enabled. - local lspconfig = require("lspconfig") - - local function set_lsp_binds(_, bufnr) - require('keybinds'):set_lsp_keys({buffer=bufnr}) - end - - local rust_tools = require("rust-tools") - rust_tools.setup({ - tools = { - inlay_hints = { auto = true, highlight = "InlayHint" }, - hover_actions = { border = "none" }, - }, - server = { - capabilities = capabilities, - on_attach = set_lsp_binds, - }, - dap = { adapter = require('dap').adapters.lldb }, - }) - rust_tools.inlay_hints.enable() - - lspconfig.bashls.setup({capabilities=capabilities, on_attach=set_lsp_binds}) - lspconfig.pylsp.setup({capabilites = capabilities, on_attach = set_lsp_binds, settings = { pylsp = { plugins = { pycodestyle = { enabled = false } } } } }) - lspconfig.clangd.setup({capabilities=capabilities, on_attach=set_lsp_binds}) - lspconfig.ltex.setup({capabilities=capabilities, on_attach=set_lsp_binds}) - lspconfig.kotlin_language_server.setup({capabilities=capabilities, on_attach=set_lsp_binds}) - lspconfig.lua_ls.setup({ - capabilites=capabilities, - on_attach=set_lsp_binds, - settings = { - Lua = { - runtime = { version = 'LuaJIT' }, - diagnostics = { globals = {'vim'} }, - workspace = { library = vim.api.nvim_get_runtime_file("", true) }, - telemetry = { enable = false }, - } - } - }) -end - -return require('packer').startup(init_fn) - + }, +} diff --git a/lua/statusline.lua b/lua/statusline.lua index 0b5d811..a8e626f 100644 --- a/lua/statusline.lua +++ b/lua/statusline.lua @@ -88,11 +88,8 @@ function BARCYCLE:combo() end function BARCYCLE:git() - if vim.fn['fugitive#Head']() ~= nil then - return vim.fn['fugitive#Head']() - else - return "" - end + local success, head = pcall(vim.fn['fugitive#Head']) + if success then return head else return '' end end function BARCYCLE:lsp()