From 8cc68ac8a50756dfc21ce269a969bd7897e173fd Mon Sep 17 00:00:00 2001 From: adamstuck Date: Sat, 12 Mar 2022 17:38:32 +0100 Subject: nvim: config cleanup + speedup (lazy load) --- .config/nvim/lua/binds.lua | 50 ----------- .config/nvim/lua/mappings.lua | 47 +++++++++++ .config/nvim/lua/options.lua | 63 ++++++++++++++ .config/nvim/lua/opts.lua | 97 --------------------- .config/nvim/lua/plugins.lua | 117 +++++++++++++++++++++----- .config/nvim/lua/post.lua | 3 + .config/nvim/lua/pre.lua | 1 + .config/nvim/lua/setup.lua | 38 --------- .config/nvim/lua/setup/indent-blankline.lua | 6 ++ .config/nvim/lua/setup/kommentary.lua | 3 + .config/nvim/lua/setup/lsp_signature.lua | 3 + .config/nvim/lua/setup/lualine.lua | 27 ++++++ .config/nvim/lua/setup/nvim-cmp.lua | 51 +++++++++++ .config/nvim/lua/setup/nvim-lsp-installer.lua | 17 ++++ .config/nvim/lua/setup/nvim-treesitter.lua | 5 ++ .config/nvim/lua/stl.lua | 27 ------ 16 files changed, 322 insertions(+), 233 deletions(-) delete mode 100644 .config/nvim/lua/binds.lua create mode 100644 .config/nvim/lua/mappings.lua create mode 100644 .config/nvim/lua/options.lua delete mode 100644 .config/nvim/lua/opts.lua create mode 100644 .config/nvim/lua/post.lua create mode 100644 .config/nvim/lua/pre.lua delete mode 100644 .config/nvim/lua/setup.lua create mode 100644 .config/nvim/lua/setup/indent-blankline.lua create mode 100644 .config/nvim/lua/setup/kommentary.lua create mode 100644 .config/nvim/lua/setup/lsp_signature.lua create mode 100644 .config/nvim/lua/setup/lualine.lua create mode 100644 .config/nvim/lua/setup/nvim-cmp.lua create mode 100644 .config/nvim/lua/setup/nvim-lsp-installer.lua create mode 100644 .config/nvim/lua/setup/nvim-treesitter.lua delete mode 100644 .config/nvim/lua/stl.lua (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/binds.lua b/.config/nvim/lua/binds.lua deleted file mode 100644 index 7b5d3fe..0000000 --- a/.config/nvim/lua/binds.lua +++ /dev/null @@ -1,50 +0,0 @@ -vim.g.mapleader = ' ' -vim.b.mapleader = ' ' - -local map = vim.api.nvim_set_keymap -local opts = { noremap = true, silent = true } - -map('', 'Y', 'y$', opts) -map('n', '', ':nohl', opts) -map('n', 'n', 'nzzzv', opts) -map('n', 'N', 'Nzzzv', opts) --- map('i', 'kj', '', opts) -map('t', 'kj', '', { noremap = true }) - -map('i', ',', ',u', opts) -map('i', '.', '.u', opts) -map('i', '[', '[u', opts) -map('i', '!', '!u', opts) -map('i', '?', '?u', opts) - -map('v', 'J', ":m '>+1gv=gv", opts) -map('v', 'K', ":m '<-2gv=gv", opts) - -map('n', 'h', ':wincmd h', opts) -map('n', 'j', ':wincmd j', opts) -map('n', 'k', ':wincmd k', opts) -map('n', 'l', ':wincmd l', opts) -map('n', '', ':wincmd h', opts) -map('n', '', ':wincmd j', opts) -map('n', '', ':wincmd k', opts) -map('n', '', ':wincmd l', opts) - -map('n', 'p', 'Telescope find_files', opts) -map('n', 'P', 'Telescope file_browser hidden=true', opts) -map('n', 'fg', 'Telescope live_grep', opts) -map('n', 'fb', 'Telescope buffers', opts) -map('n', 'fh', 'Telescope help_tags', opts) - -map('n', 'gd', 'Telescope lsp_definitions', opts) -map('n', 'gD', 'Telescope lsp_declarations', opts) -map('n', 'gr', 'Telescope lsp_references', opts) -map('n', 'gi', 'Telescope lsp_implementations', opts) -map('n', 'K', 'lua vim.lsp.buf.hover()', opts) -map('n', '', 'lua vim.lsp.buf.signature_help()', opts) -map('n', 'rn', 'lua vim.lsp.buf.rename()', opts) -map('n', 'xd', 'Telescope lsp_document_diagnostics', opts) -map('n', 'xD', 'Telescope lsp_workspace_diagnostics', opts) -map('n', 'xn', 'lua vim.lsp.diagnostic.goto_next()', opts) -map('n', 'xN', 'lua vim.lsp.diagnostic.goto_prev()', opts) -map('n', 'xx', 'Telescope lsp_code_actions', opts) -map('n', 'xX', 'Telescope lsp_range_code_actions', opts) diff --git a/.config/nvim/lua/mappings.lua b/.config/nvim/lua/mappings.lua new file mode 100644 index 0000000..81f0614 --- /dev/null +++ b/.config/nvim/lua/mappings.lua @@ -0,0 +1,47 @@ +vim.g.mapleader = ' ' +vim.b.mapleader = ' ' + +local map = vim.api.nvim_set_keymap +local opts = { noremap = true, silent = true } + +map('', 'Y', 'y$', opts) +map('n', '', ':nohl', opts) +map('n', 'n', 'nzzzv', opts) +map('n', 'N', 'Nzzzv', opts) +-- map('i', 'kj', '', opts) +map('t', 'kj', '', { noremap = true }) + +map('i', ',', ',u', opts) +map('i', '.', '.u', opts) +map('i', '[', '[u', opts) +map('i', '!', '!u', opts) +map('i', '?', '?u', opts) + +map('v', 'J', ":m '>+1gv=gv", opts) +map('v', 'K', ":m '<-2gv=gv", opts) + +map('n', 'h', ':wincmd h', opts) +map('n', 'j', ':wincmd j', opts) +map('n', 'k', ':wincmd k', opts) +map('n', 'l', ':wincmd l', opts) +map('n', '', ':wincmd h', opts) +map('n', '', ':wincmd j', opts) +map('n', '', ':wincmd k', opts) +map('n', '', ':wincmd l', opts) + +map('n', 'p', 'Telescope find_files', opts) +map('n', 'fg', 'Telescope live_grep', opts) +map('n', 'fb', 'Telescope buffers', opts) +map('n', 'fh', 'Telescope help_tags', opts) + +map('n', 'gd', 'Telescope lsp_definitions', opts) +map('n', 'gD', 'Telescope lsp_declarations', opts) +map('n', 'gr', 'Telescope lsp_references', opts) +map('n', 'gi', 'Telescope lsp_implementations', opts) +map('n', 'K', 'lua vim.lsp.buf.hover()', opts) +map('n', '', 'lua vim.lsp.buf.signature_help()', opts) +map('n', 'rn', 'lua vim.lsp.buf.rename()', opts) +map('n', 'xn', 'lua vim.lsp.diagnostic.goto_next()', opts) +map('n', 'xN', 'lua vim.lsp.diagnostic.goto_prev()', opts) +map('n', 'xx', 'Telescope lsp_code_actions', opts) +map('n', 'xX', 'Telescope lsp_range_code_actions', opts) diff --git a/.config/nvim/lua/options.lua b/.config/nvim/lua/options.lua new file mode 100644 index 0000000..caeccc7 --- /dev/null +++ b/.config/nvim/lua/options.lua @@ -0,0 +1,63 @@ +vim.cmd('syntax enable') +vim.cmd('set undodir=$XDG_CACHE_HOME/nvim/undo') +vim.cmd('set undofile') +require('onedark').load() + +local set = vim.opt +set.mouse = "a" +set.termguicolors = true +set.hidden = true +set.wildmenu = true +set.wildignorecase = true +set.fileignorecase = true +set.showcmd = true +set.hlsearch = true +set.ignorecase = true +set.smartcase = true +set.incsearch = true +set.backspace= 'indent,eol,start' +set.pastetoggle = '' +set.confirm = true +set.number = true +set.relativenumber = true +set.shiftwidth = 4 +set.softtabstop = 4 +set.autoindent = true +set.expandtab = true +set.showmode = false +set.ruler = false +set.timeout = false +set.ttimeoutlen = 200 +set.wrap = false +set.fcs = 'eob: ' +set.swapfile = false +set.pumblend = 0 +set.splitright = true +set.splitbelow = true +set.cursorline = true + +-- Disable default vim plugins +local disabled_built_ins = { + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "gzip", + "zip", + "zipPlugin", + "tar", + "tarPlugin", + "getscript", + "getscriptPlugin", + "vimball", + "vimballPlugin", + "2html_plugin", + "logipat", + "rrhelper", + "spellfile_plugin", + "matchit" +} + +for _, plugin in pairs(disabled_built_ins) do + vim.g["loaded_" .. plugin] = 1 +end diff --git a/.config/nvim/lua/opts.lua b/.config/nvim/lua/opts.lua deleted file mode 100644 index 1e5bfda..0000000 --- a/.config/nvim/lua/opts.lua +++ /dev/null @@ -1,97 +0,0 @@ --- CMP -local has_words_before = function() - local line, col = 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 luasnip = require("luasnip") -local cmp = require("cmp") -require("luasnip/loaders/from_vscode").lazy_load() -vim.o.completeopt = 'menuone,noselect' - -cmp.setup { - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - mapping = { - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.close(), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} -vim.cmd('autocmd FileType markdown lua require("cmp").setup.buffer { enabled = false }') - --- LSPCONFIG - -local lsp_installer = require("nvim-lsp-installer") - --- Register a handler that will be called for each installed server when it's ready (i.e. when installation is finished --- or if the server is already installed). -lsp_installer.on_server_ready(function(server) - local opts = {} - - -- (optional) Customize the options passed to the server - -- if server.name == "tsserver" then - -- opts.root_dir = function() ... end - -- end - - -- This setup() function will take the provided server configuration and decorate it with the necessary properties - -- before passing it onwards to lspconfig. - -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md - server:setup(opts) -end) - --- Misc - -require('nvim-autopairs').setup{} - -require'lsp_signature'.setup { - floating_window = false -} - -require'nvim-treesitter.configs'.setup { - highlight = { - enable = true, - }, -} - -require('kommentary.config').configure_language("default", { - prefer_single_line_comments = true, -}) - -require("indent_blankline").setup { - char = "¦", - show_trailing_blankline_indent = false, - buftype_exclude = {"startify", "help", "terminal"}, - filetype_exclude = {"startify", "help", "terminal"}, -} diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index c2ceed8..3164516 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -1,21 +1,97 @@ local use = require('packer').use require('packer').startup(function() use 'wbthomason/packer.nvim' - use 'romgrk/doom-one.vim' - -- use 'tpope/vim-fugitive' + use 'adast9/onedark.nvim' + use 'nathom/filetype.nvim' + use { + 'lewis6991/impatient.nvim', + config = function() + require("impatient") + end + } + use 'tpope/vim-surround' - -- use 'tpope/vim-repeat' - use 'b3nj5m1n/kommentary' + use { + 'b3nj5m1n/kommentary', + keys = { + {"n", "gcc"}, + {"n", "gc"}, + {"v", "gc"}, + }, + config = function() + require "setup.kommentary" + end + } + + use { + 'williamboman/nvim-lsp-installer', + -- after = 'nvim-lspconfig', + config = function() + require "setup.nvim-lsp-installer" + end + } - use 'williamboman/nvim-lsp-installer' use 'neovim/nvim-lspconfig' - use 'hrsh7th/cmp-nvim-lsp' - use 'hrsh7th/nvim-cmp' + -- use { + -- 'neovim/nvim-lspconfig', + -- after = { 'nvim-cmp' }, + -- event = { 'BufRead', 'BufNewFile', 'InsertEnter' }, + -- } - use "ray-x/lsp_signature.nvim" - use "windwp/nvim-autopairs" - use "lukas-reineke/indent-blankline.nvim" - use 'kyazdani42/nvim-web-devicons' + use { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + config = function() + require "setup.nvim-cmp" + end, + wants = 'LuaSnip', + requires = { + { + 'hrsh7th/cmp-nvim-lsp' + }, + { + "L3MON4D3/LuaSnip", + wants = "friendly-snippets", + event = "InsertCharPre", + config = function() + require("luasnip/loaders/from_vscode").lazy_load() + end + }, + { + "rafamadriz/friendly-snippets", + event = "InsertCharPre" + }, + { + "saadparwaiz1/cmp_luasnip", + event = "InsertCharPre" + } + } + } + + use { + "ray-x/lsp_signature.nvim", + event = 'InsertEnter', + -- event = { 'BufRead' , 'BufNewFile' }, + config = function() + require "setup.lsp_signature" + end + } + + use { + "windwp/nvim-autopairs", + after = { 'nvim-cmp'}, + config = function() + require('nvim-autopairs').setup{} + end + } + + use { + "lukas-reineke/indent-blankline.nvim", + event = { 'BufRead' , 'BufNewFile' }, + config = function() + require "setup.indent-blankline" + end + } use { 'nvim-telescope/telescope.nvim', @@ -27,19 +103,12 @@ require('packer').startup(function() } } - use { - "L3MON4D3/LuaSnip", - requires = { - "rafamadriz/friendly-snippets", - "saadparwaiz1/cmp_luasnip" - } - } - use { 'lewis6991/gitsigns.nvim', requires = { 'nvim-lua/plenary.nvim' }, + event = { 'BufRead' , 'BufNewFile' }, config = function() require('gitsigns').setup() end @@ -47,11 +116,17 @@ require('packer').startup(function() use { 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate' + run = ':TSUpdate', + config = function() + require "setup.nvim-treesitter" + end } use { 'nvim-lualine/lualine.nvim', - requires = {'kyazdani42/nvim-web-devicons', opt = true} + requires = {'kyazdani42/nvim-web-devicons', opt = true}, + config = function() + require "setup.lualine" + end } end) diff --git a/.config/nvim/lua/post.lua b/.config/nvim/lua/post.lua new file mode 100644 index 0000000..b984880 --- /dev/null +++ b/.config/nvim/lua/post.lua @@ -0,0 +1,3 @@ +-- vim.diagnostic.config({virtual_text = false}) +vim.opt.shadafile = "" +vim.cmd('highlight IndentBlanklineChar guifg=#3b414c gui=nocombine') diff --git a/.config/nvim/lua/pre.lua b/.config/nvim/lua/pre.lua new file mode 100644 index 0000000..5e6a458 --- /dev/null +++ b/.config/nvim/lua/pre.lua @@ -0,0 +1 @@ +vim.opt.shadafile = "NONE" diff --git a/.config/nvim/lua/setup.lua b/.config/nvim/lua/setup.lua deleted file mode 100644 index 3243853..0000000 --- a/.config/nvim/lua/setup.lua +++ /dev/null @@ -1,38 +0,0 @@ -vim.cmd('syntax enable') -vim.cmd('set undodir=$XDG_CACHE_HOME/nvim/undo') -vim.cmd('set undofile') -vim.cmd('set shada') -vim.cmd('colorscheme doom-one') - -local set = vim.opt -set.mouse = "a" -set.termguicolors = true -set.hidden = true -set.wildmenu = true -set.wildignorecase = true -set.fileignorecase = true -set.showcmd = true -set.hlsearch = true -set.ignorecase = true -set.smartcase = true -set.incsearch = true -set.backspace= 'indent,eol,start' -set.pastetoggle = '' -set.confirm = true -set.number = true -set.relativenumber = true -set.shiftwidth = 4 -set.softtabstop = 4 -set.autoindent = true -set.expandtab = true -set.showmode = false -set.ruler = false -set.timeout = false -set.ttimeoutlen = 200 -set.wrap = false -set.fcs = 'eob: ' -set.swapfile = false -set.pumblend = 0 -set.splitright = true -set.splitbelow = true -set.cursorline = true diff --git a/.config/nvim/lua/setup/indent-blankline.lua b/.config/nvim/lua/setup/indent-blankline.lua new file mode 100644 index 0000000..ff81338 --- /dev/null +++ b/.config/nvim/lua/setup/indent-blankline.lua @@ -0,0 +1,6 @@ +require("indent_blankline").setup { + char = "▏", + show_trailing_blankline_indent = false, + buftype_exclude = {"startify", "help", "terminal"}, + filetype_exclude = {"startify", "help", "terminal"}, +} diff --git a/.config/nvim/lua/setup/kommentary.lua b/.config/nvim/lua/setup/kommentary.lua new file mode 100644 index 0000000..3ca608d --- /dev/null +++ b/.config/nvim/lua/setup/kommentary.lua @@ -0,0 +1,3 @@ +require('kommentary.config').configure_language("default", { + prefer_single_line_comments = true, +}) diff --git a/.config/nvim/lua/setup/lsp_signature.lua b/.config/nvim/lua/setup/lsp_signature.lua new file mode 100644 index 0000000..65f7070 --- /dev/null +++ b/.config/nvim/lua/setup/lsp_signature.lua @@ -0,0 +1,3 @@ +require'lsp_signature'.setup { + floating_window = false +} diff --git a/.config/nvim/lua/setup/lualine.lua b/.config/nvim/lua/setup/lualine.lua new file mode 100644 index 0000000..0c07a4a --- /dev/null +++ b/.config/nvim/lua/setup/lualine.lua @@ -0,0 +1,27 @@ +require'lualine'.setup { + options = { + icons_enabled = true, + theme = 'onedark', + component_separators = {left = '', right = ''}, + section_separators = {left = '', right = ''}, + disabled_filetypes = {'startify', 'terminal', 'netrw', 'NvimTree'} + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + extensions = {} +} diff --git a/.config/nvim/lua/setup/nvim-cmp.lua b/.config/nvim/lua/setup/nvim-cmp.lua new file mode 100644 index 0000000..42bf348 --- /dev/null +++ b/.config/nvim/lua/setup/nvim-cmp.lua @@ -0,0 +1,51 @@ +local has_words_before = function() + local line, col = 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 luasnip = require("luasnip") +local cmp = require("cmp") +require("luasnip/loaders/from_vscode").lazy_load() +vim.o.completeopt = 'menuone,noselect' + +cmp.setup { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = { + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.close(), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} +vim.cmd('autocmd FileType markdown lua require("cmp").setup.buffer { enabled = false }') diff --git a/.config/nvim/lua/setup/nvim-lsp-installer.lua b/.config/nvim/lua/setup/nvim-lsp-installer.lua new file mode 100644 index 0000000..bd3496e --- /dev/null +++ b/.config/nvim/lua/setup/nvim-lsp-installer.lua @@ -0,0 +1,17 @@ +local lsp_installer = require("nvim-lsp-installer") + +-- Register a handler that will be called for each installed server when it's ready (i.e. when installation is finished +-- or if the server is already installed). +lsp_installer.on_server_ready(function(server) + local opts = {} + + -- (optional) Customize the options passed to the server + -- if server.name == "tsserver" then + -- opts.root_dir = function() ... end + -- end + + -- This setup() function will take the provided server configuration and decorate it with the necessary properties + -- before passing it onwards to lspconfig. + -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + server:setup(opts) +end) diff --git a/.config/nvim/lua/setup/nvim-treesitter.lua b/.config/nvim/lua/setup/nvim-treesitter.lua new file mode 100644 index 0000000..42bfcbd --- /dev/null +++ b/.config/nvim/lua/setup/nvim-treesitter.lua @@ -0,0 +1,5 @@ +require'nvim-treesitter.configs'.setup { + highlight = { + enable = true, + }, +} diff --git a/.config/nvim/lua/stl.lua b/.config/nvim/lua/stl.lua deleted file mode 100644 index 241e0ff..0000000 --- a/.config/nvim/lua/stl.lua +++ /dev/null @@ -1,27 +0,0 @@ -require'lualine'.setup { - options = { - icons_enabled = true, - theme = 'onedark', - component_separators = {left = '', right = ''}, - section_separators = {left = '', right = ''}, - disabled_filetypes = {'startify', 'terminal', 'netrw'} - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch'}, - lualine_c = {'filename'}, - lualine_x = {'encoding', 'filetype'}, - lualine_y = {'progress'}, - lualine_z = {'location'} - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {'filename'}, - lualine_x = {'location'}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - extensions = {} -} -- cgit v1.2.3-70-g09d2