From 8e4e909be2220ffc557dbfdf7f00343981c5f1cf Mon Sep 17 00:00:00 2001 From: winston Date: Tue, 18 Oct 2022 10:02:19 +0200 Subject: [PATCH] feat(nvim): debloat setup, tweak lsp --- dot_config/nvim/init.lua | 8 +- dot_config/nvim/lua/config/bufferline.lua | 2 +- dot_config/nvim/lua/config/dashboard.lua | 33 +- dot_config/nvim/lua/config/presence.lua | 6 +- dot_config/nvim/lua/lsp.lua | 51 +- dot_config/nvim/lua/plugins.lua | 692 +++++++++++----------- 6 files changed, 407 insertions(+), 385 deletions(-) diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index 41bfb43..d3afeb3 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -1,13 +1,13 @@ -- vim:fdm=marker -pcall(require, "impatient") -pcall(require, "plugins") -pcall(require, "lsp") +require("impatient") +require("plugins") +require("lsp") -- true colors vim.o.termguicolors = true -- map leader to space vim.g.mapleader = " " -vim.o.cmdheight = 0 +vim.o.cmdheight = 1 -- line numbers vim.o.mouse = "" vim.o.number = true diff --git a/dot_config/nvim/lua/config/bufferline.lua b/dot_config/nvim/lua/config/bufferline.lua index c32e6df..f4e98cb 100644 --- a/dot_config/nvim/lua/config/bufferline.lua +++ b/dot_config/nvim/lua/config/bufferline.lua @@ -1,7 +1,7 @@ require("bufferline").setup({ options = { show_close_icon = false, - separator_style = "slant", + separator_style = "thin", show_buffer_close_icons = false, offsets = { { filetype = "NvimTree" } }, left_mouse_command = "buffer %d", diff --git a/dot_config/nvim/lua/config/dashboard.lua b/dot_config/nvim/lua/config/dashboard.lua index fd68fbf..8c3d0b7 100644 --- a/dot_config/nvim/lua/config/dashboard.lua +++ b/dot_config/nvim/lua/config/dashboard.lua @@ -1,11 +1,10 @@ -local home = os.getenv("HOME") local db = require("dashboard") db.custom_header = function() local cringe = { "Have fun coding!", - "Sisyphus wasn't forbidden to smile.", - "Pro tip: Run :q! to exit. Now!", + "neovim got rid of the :smile command.", + "Pro tip: You can use :q to exit. Do it. Now!", } local random_cringe = cringe[math.random(#cringe)] return { @@ -34,34 +33,48 @@ db.custom_header = function() } end +local padding = 25 +local function pad(string) + local str = string + for _ = 1, padding - #string do + str = str .. " " + end + return str +end + db.custom_center = { { icon = " ", - desc = "Open Projects ", + desc = pad("Open Projects"), action = "Telescope project", + shortcut = "SPC f p", }, { icon = " ", - desc = "Find File ", + desc = pad("Find File"), action = "Telescope find_files find_command=rg,--hidden,--files", + shortcut = "SPC f f", }, { icon = " ", - desc = "File Browser ", + desc = pad("File Browser"), action = "Telescope file_browser", + shortcut = "SPC f b", }, { icon = " ", - desc = "Find word ", + desc = pad("Find word"), action = "Telescope live_grep", + shortcut = "SPC f g", }, { icon = " ", - desc = "Open Settings ", + desc = pad("Open Settings"), action = function() - vim.cmd("cd " .. home .. "/.config/nvim/") - vim.cmd("edit init.lua") + local confpath = vim.fn.resolve(vim.fn.stdpath("config")) + require("telescope.builtin").find_files({ cwd = confpath }) end, + shortcut = "SPC f s", }, } diff --git a/dot_config/nvim/lua/config/presence.lua b/dot_config/nvim/lua/config/presence.lua index 7575617..a7017e7 100644 --- a/dot_config/nvim/lua/config/presence.lua +++ b/dot_config/nvim/lua/config/presence.lua @@ -3,10 +3,10 @@ function string.starts(self, str) end local conceal = function() - local home = os.getenv("HOME") + local home = vim.fn.expand("$HOME") .. "/Code/" local blacklist = { - [home .. "/git/work"] = "Using nvim at work.", - [home .. "/git/freelance"] = "Using nvim to freelance.", + [vim.fn.resolve(home .. "work")] = "Using nvim at work.", + [vim.fn.resolve(home .. "freelance")] = "Using nvim to freelance.", [vim.fn.resolve(vim.fn.stdpath("config"))] = "Stuck in the hell of nvim config.", } diff --git a/dot_config/nvim/lua/lsp.lua b/dot_config/nvim/lua/lsp.lua index a1c06f5..d284097 100644 --- a/dot_config/nvim/lua/lsp.lua +++ b/dot_config/nvim/lua/lsp.lua @@ -14,10 +14,27 @@ vim.opt.completeopt = "menu,menuone,noselect" local present, cmp = pcall(require, "cmp") if not present or not cmp then - vim.pretty_print("cmp not found") return end +local has_words_before = function() + local line, col = table.unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 + and vim.api + .nvim_buf_get_lines(0, line - 1, line, true)[1] + :sub(col, col) + :match("%s") + == nil +end + +local feedkey = function(key, mode) + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes(key, true, true, true), + mode, + true + ) +end + cmp.setup({ snippet = { expand = function(args) @@ -29,19 +46,30 @@ cmp.setup({ documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) - -- This little snippet will confirm with tab, and if no entry is selected, will confirm the first item if cmp.visible() then - local entry = cmp.get_selected_entry() - if not entry then - cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) - else - cmp.confirm() - end + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() else - fallback() + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. end - end, { "i", "s", "c" }), + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), }), sources = cmp.config.sources({ { name = "nvim_lsp" }, @@ -187,6 +215,3 @@ local toggle_formatters = function() end vim.api.nvim_create_user_command("ToggleFormatters", toggle_formatters, {}) - -local cmp_autopairs = require("nvim-autopairs.completion.cmp") -cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) diff --git a/dot_config/nvim/lua/plugins.lua b/dot_config/nvim/lua/plugins.lua index 93a9c91..8bd5a78 100644 --- a/dot_config/nvim/lua/plugins.lua +++ b/dot_config/nvim/lua/plugins.lua @@ -1,23 +1,4 @@ -local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath("data") - .. "/site/pack/packer/start/packer.nvim" - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({ - "git", - "clone", - "--depth", - "1", - "https://github.com/wbthomason/packer.nvim", - install_path, - }) - vim.cmd([[packadd packer.nvim]]) - return true - end - return false -end - -local packer_bootstrap = ensure_packer() +local packer = require("packer") -- auto-compile when lua files in `~/.config/nvim/*` change vim.api.nvim_create_autocmd("BufWritePost", { @@ -32,343 +13,346 @@ vim.api.nvim_create_autocmd("BufWritePost", { end, }) -return require("packer").startup(function(use) - -- Packer managing itself - use("wbthomason/packer.nvim") - -- startup time or some shit - use("lewis6991/impatient.nvim") +return packer.startup({ + function(use) + -- Packer managing itself + use("wbthomason/packer.nvim") + -- startup time or some shit + use("lewis6991/impatient.nvim") - -- colour scheme - use({ - "catppuccin/nvim", - as = "catppuccin", - run = ":CatppuccinCompile", - config = function() - require("config/catppuccin") - end, - }) - - -- git gutter - use({ - "lewis6991/gitsigns.nvim", - config = function() - require("config/gitsigns") - end, - }) - -- rainbow indents - use({ - "lukas-reineke/indent-blankline.nvim", - config = function() - require("indent_blankline").setup({ - space_char_blankline = " ", - show_current_conext = true, - char_highlight_list = { - "IndentBlanklineIndent1", - "IndentBlanklineIndent2", - "IndentBlanklineIndent3", - "IndentBlanklineIndent4", - "IndentBlanklineIndent5", - "IndentBlanklineIndent6", - }, - }) - vim.g.indent_blankline_filetype_exclude = { - "dashboard", - "help", - "neogitstatus", - "fugitive", - "packer", - "NvimTree", - "Trouble", - } - end, - }) - - -- top bar - use({ - "akinsho/bufferline.nvim", - config = function() - require("config/bufferline") - end, - }) - - -- bottom bar - use({ - "feline-nvim/feline.nvim", - requires = "kyazdani42/nvim-web-devicons", - after = { "catppuccin" }, - config = function() - require("config/feline") - end, - }) - - -- DJI Osmo - use({ - "luukvbaal/stabilize.nvim", - config = function() - require("stabilize").setup() - end, - }) - - -- syntax - use({ - "nvim-treesitter/nvim-treesitter", - run = function() - require("nvim-treesitter.install").update({ with_sync = true }) - end, - config = function() - require("config/treesitter") - end, - }) - use({ - "p00f/nvim-ts-rainbow", - requires = "nvim-treesitter/nvim-treesitter", - }) - - -- show possible key combos - use({ - "folke/which-key.nvim", - config = function() - require("which-key").setup({}) - end, - }) - - -- syntax - use("alker0/chezmoi.vim") - use("ron-rs/ron.vim") - use("elkowar/yuck.vim") - - -- tooling - use("gpanders/editorconfig.nvim") - -- read and write encrypted pgp files - use("jamessan/vim-gnupg") - - -- additional functionality - use({ - "numToStr/Comment.nvim", - config = function() - require("Comment").setup() - end, - }) - use({ - "kylechui/nvim-surround", - config = function() - require("nvim-surround").setup({}) - end, - }) - use("ggandor/lightspeed.nvim") - - use("windwp/nvim-autopairs") - use({ - "windwp/nvim-ts-autotag", - config = function() - require("nvim-ts-autotag").setup() - end, - }) - -- - -- git - use("tpope/vim-fugitive") - -- why not both? - use({ - "TimUntersberger/neogit", - requires = "nvim-lua/plenary.nvim", - config = function() - Map("n", "ng", "Neogit") - end, - }) - use("dhruvasagar/vim-table-mode") - use({ - "kyazdani42/nvim-tree.lua", - config = function() - require("nvim-tree").setup({ update_cwd = true }) - Map("n", "", ":NvimTreeToggle") - end, - }) - use({ - "nvchad/nvim-colorizer.lua", - config = function() - require("config/colorizer") - end, - }) - use({ - "simrat39/symbols-outline.nvim", - config = function() - require("symbols-outline").setup() - Map("n", "so", ":SymbolsOutline") - end, - }) - - -- databases - use("tpope/vim-dadbod") - use("kristijanhusak/vim-dadbod-completion") - use({ - "kristijanhusak/vim-dadbod-ui", - config = function() - Map("n", "db", ":DBUIToggle") - vim.g.db_ui_use_nerd_fonts = true - vim.g.db_ui_win_position = "right" - end, - }) - - -- telescope - use({ - "nvim-telescope/telescope.nvim", - requires = "nvim-lua/plenary.nvim", - config = function() - Map("n", "fr", "Telescope asynctasks all") - Map("n", "fb", "Telescope buffers") - Map("n", "ff", "Telescope find_files") - Map("n", "fg", "Telescope live_grep") - Map("n", "fh", "Telescope help_tags") - end, - }) - use({ - "nvim-telescope/telescope-fzf-native.nvim", - run = "make", - requires = "nvim-telescope/telescope.nvim", - config = function() - local telescope = require("telescope") - telescope.setup({ - extensions = { - fzf = { - fuzzy = true, - override_generic_sorter = true, - override_file_sorter = true, - case_mode = "smart_case", - }, - }, - }) - telescope.load_extension("fzf") - end, - }) - use({ - "nvim-telescope/telescope-file-browser.nvim", - config = function() - require("telescope").load_extension("file_browser") - end, - }) - use({ - "nvim-telescope/telescope-project.nvim", - config = function() - require("telescope").load_extension("project") - end, - }) - use({ - "nvim-telescope/telescope-packer.nvim", - config = function() - require("telescope").load_extension("packer") - end, - }) - - use({ - "andweeb/presence.nvim", - config = function() - require("config/presence") - end, - }) - use({ "iamcco/markdown-preview.nvim", run = "cd app && yarn install" }) - - -- external extensions - use("williamboman/mason.nvim") - -- LSP - use("williamboman/mason-lspconfig.nvim") - use("neovim/nvim-lspconfig") - -- completion - use("hrsh7th/nvim-cmp") - use("hrsh7th/cmp-buffer") - use("hrsh7th/cmp-cmdline") - use("hrsh7th/cmp-nvim-lsp") - use("hrsh7th/cmp-path") - use("hrsh7th/cmp-vsnip") - use("hrsh7th/vim-vsnip") - use("petertriho/cmp-git") - use("rafamadriz/friendly-snippets") - use("jose-elias-alvarez/null-ls.nvim") - use({ - "glepnir/lspsaga.nvim", - branch = "main", - config = function() - require("config/lspsaga") - end, - }) - - use("b0o/schemastore.nvim") - use({ - "github/copilot.vim", - config = function() - local opt = { noremap = true, silent = true, expr = true } - Map("i", "", "copilot#Accept()", opt) - vim.g.copilot_no_tab_map = true - end, - }) - - -- organization - use({ - "vimwiki/vimwiki", - branch = "dev", - config = function() - vim.g.vimwiki_global_ext = 0 - vim.g.vimwiki_list = { - { - auto_export = 1, - path = "~/.local/share/vimwiki/", - syntax = "markdown", - ext = ".md", - path_html = "~/vimwiki/", - template_path = "~/.config/vimwiki/templates/", - template_default = "default", - template_ext = ".tpl", - custom_wiki2html = "vimwiki_markdown", - html_filename_parameterization = 1, - }, - } - end, - }) - use("tools-life/taskwiki") - - use({ - "skywind3000/asyncrun.vim", - config = function() - vim.g.asyncrun_open = 6 - end, - }) - use({ "skywind3000/asynctasks.vim" }) - use({ - "GustavoKatel/telescope-asynctasks.nvim", - config = function() - require("telescope").load_extension("asynctasks") - end, - }) - - -- startup - use({ - "glepnir/dashboard-nvim", - config = function() - require("config/dashboard") - end, - }) - - -- automatic theme switching - if vim.fn.has("macunix") then + -- colour scheme use({ - "f-person/auto-dark-mode.nvim", + "catppuccin/nvim", + as = "catppuccin", + run = ":CatppuccinCompile", config = function() - local auto_dark_mode = require("auto-dark-mode") - auto_dark_mode.setup({ - ---@diagnostic disable-next-line: assign-type-mismatch - update_interval = 1000, - set_dark_mode = function() - vim.cmd("Catppuccin frappe") - end, - set_light_mode = function() - vim.cmd("Catppuccin latte") - end, - }) - auto_dark_mode.init() + require("config/catppuccin") end, }) - end - if packer_bootstrap then - require("packer").sync() - end -end) + -- git gutter + use({ + "lewis6991/gitsigns.nvim", + config = function() + require("config/gitsigns") + end, + }) + -- rainbow indents + use({ + "lukas-reineke/indent-blankline.nvim", + config = function() + require("indent_blankline").setup({ + space_char_blankline = " ", + show_current_conext = true, + char_highlight_list = { + "IndentBlanklineIndent1", + "IndentBlanklineIndent2", + "IndentBlanklineIndent3", + "IndentBlanklineIndent4", + "IndentBlanklineIndent5", + "IndentBlanklineIndent6", + }, + }) + vim.g.indent_blankline_filetype_exclude = { + "dashboard", + "help", + "neogitstatus", + "fugitive", + "packer", + "NvimTree", + "Trouble", + } + end, + }) + + -- top bar + use({ + "akinsho/bufferline.nvim", + config = function() + require("config/bufferline") + end, + }) + + use({ + "nvim-lualine/lualine.nvim", + requires = { "kyazdani42/nvim-web-devicons", opt = true }, + config = function() + require("lualine").setup({ + options = { + theme = "catppuccin", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + }, + sections = { + lualine_x = { + { + "diagnostics", + sources = { "nvim_lsp" }, + -- Displays diagnostics for the defined severity types + sections = { "error", "warn", "info", "hint" }, + diagnostics_color = { + -- Same values as the general color option can be used here. + error = "DiagnosticError", -- Changes diagnostics' error color. + warn = "DiagnosticWarn", -- Changes diagnostics' warn color. + info = "DiagnosticInfo", -- Changes diagnostics' info color. + hint = "DiagnosticHint", -- Changes diagnostics' hint color. + }, + symbols = { error = "E", warn = "W", info = "I", hint = "H" }, + colored = true, -- Displays diagnostics status in color if set to true. + update_in_insert = false, -- Update diagnostics in insert mode. + always_visible = false, -- Show diagnostics even if there are none. + }, + }, + }, + }) + end, + }) + + -- DJI Osmo + use({ + "luukvbaal/stabilize.nvim", + config = function() + require("stabilize").setup() + end, + }) + + -- syntax + use({ + "nvim-treesitter/nvim-treesitter", + run = function() + require("nvim-treesitter.install").update({ with_sync = true }) + end, + config = function() + require("config/treesitter") + end, + }) + use({ + "p00f/nvim-ts-rainbow", + requires = "nvim-treesitter/nvim-treesitter", + }) + + -- show possible key combos + use({ + "folke/which-key.nvim", + config = function() + require("which-key").setup({}) + end, + }) + + -- syntax + use("alker0/chezmoi.vim") + -- tooling + use("gpanders/editorconfig.nvim") + -- read and write encrypted pgp files + use("jamessan/vim-gnupg") + + -- additional functionality + use({ + "numToStr/Comment.nvim", + config = function() + require("Comment").setup() + end, + }) + use({ + "kylechui/nvim-surround", + config = function() + require("nvim-surround").setup({}) + end, + }) + use("ggandor/lightspeed.nvim") + + use({ + "windwp/nvim-autopairs", + config = function() + require("nvim-autopairs").setup({}) + local cmp_autopairs = require("nvim-autopairs.completion.cmp") + local cmp = require("cmp") + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }) + use({ + "windwp/nvim-ts-autotag", + config = function() + require("nvim-ts-autotag").setup() + end, + }) + + -- git + use("tpope/vim-fugitive") + -- why not both? + use({ + "TimUntersberger/neogit", + requires = "nvim-lua/plenary.nvim", + config = function() + Map("n", "ng", "Neogit") + end, + }) + use("dhruvasagar/vim-table-mode") + use({ + "nvchad/nvim-colorizer.lua", + config = function() + require("config/colorizer") + end, + }) + use({ + "simrat39/symbols-outline.nvim", + config = function() + require("symbols-outline").setup() + Map("n", "so", ":SymbolsOutline") + end, + }) + + -- databases + use("tpope/vim-dadbod") + use("kristijanhusak/vim-dadbod-completion") + use({ + "kristijanhusak/vim-dadbod-ui", + config = function() + Map("n", "db", ":DBUIToggle") + vim.g.db_ui_use_nerd_fonts = true + vim.g.db_ui_win_position = "right" + end, + }) + + -- telescope + use({ + "nvim-telescope/telescope.nvim", + requires = "nvim-lua/plenary.nvim", + config = function() + Map("n", "fr", "Telescope asynctasks all") + Map("n", "fb", "Telescope file_browser") + Map("n", "ff", "Telescope find_files") + Map("n", "fg", "Telescope live_grep") + Map("n", "fh", "Telescope help_tags") + Map("n", "fp", "Telescope project") + Map("n", "fs", function() + local confpath = vim.fn.resolve(vim.fn.stdpath("config")) + require("telescope.builtin").find_files({ cwd = confpath }) + end) + end, + }) + use({ + "nvim-telescope/telescope-fzf-native.nvim", + run = "make", + requires = "nvim-telescope/telescope.nvim", + config = function() + local telescope = require("telescope") + telescope.setup({ + extensions = { + fzf = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case", + }, + }, + }) + telescope.load_extension("fzf") + end, + }) + use({ + "nvim-telescope/telescope-file-browser.nvim", + config = function() + require("telescope").load_extension("file_browser") + end, + }) + use({ + "nvim-telescope/telescope-project.nvim", + config = function() + require("telescope").load_extension("project") + end, + }) + + use({ + "andweeb/presence.nvim", + config = function() + require("config/presence") + end, + }) + use({ "iamcco/markdown-preview.nvim", run = "cd app && yarn install" }) + + -- LSP + use("williamboman/mason.nvim") + use("williamboman/mason-lspconfig.nvim") + use("neovim/nvim-lspconfig") + -- completion + use("hrsh7th/nvim-cmp") + use("hrsh7th/cmp-buffer") + use("hrsh7th/cmp-cmdline") + use("hrsh7th/cmp-nvim-lsp") + use("hrsh7th/cmp-path") + use("hrsh7th/cmp-vsnip") + use("hrsh7th/vim-vsnip") + use("petertriho/cmp-git") + use("rafamadriz/friendly-snippets") + use("jose-elias-alvarez/null-ls.nvim") + use({ + "glepnir/lspsaga.nvim", + branch = "main", + config = function() + require("config/lspsaga") + end, + }) + + use("b0o/schemastore.nvim") + use({ + "github/copilot.vim", + config = function() + local opt = { noremap = true, silent = true, expr = true } + Map("i", "", "copilot#Accept()", opt) + vim.g.copilot_no_tab_map = true + end, + }) + + -- organization + use({ + "vimwiki/vimwiki", + branch = "dev", + config = function() + vim.g.vimwiki_global_ext = 0 + vim.g.vimwiki_list = { + { + auto_export = 1, + path = "~/.local/share/vimwiki/", + syntax = "markdown", + ext = ".md", + path_html = "~/vimwiki/", + template_path = "~/.config/vimwiki/templates/", + template_default = "default", + template_ext = ".tpl", + custom_wiki2html = "vimwiki_markdown", + html_filename_parameterization = 1, + }, + } + end, + }) + use("tools-life/taskwiki") + + use({ + "skywind3000/asyncrun.vim", + config = function() + vim.g.asyncrun_open = 6 + end, + }) + use({ "skywind3000/asynctasks.vim" }) + use({ + "GustavoKatel/telescope-asynctasks.nvim", + config = function() + require("telescope").load_extension("asynctasks") + end, + }) + + -- startup + use({ + "glepnir/dashboard-nvim", + config = function() + require("config/dashboard") + end, + }) + end, + config = { + display = { + open_fn = require("packer.util").float, + }, + }, +})