From c599929e4f196f22919b5b3352db8ba8af8c9fd7 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 3 Mar 2024 19:19:56 -0500 Subject: [PATCH] nvim: clean up lua init --- .gitmodules | 28 ++-- README.md | 17 ++- src/.config/nvim/lua/coding.lua | 140 ++++++++++++++++++ src/.config/nvim/lua/init.lua | 130 +++------------- .../nvim/site/pack/3pp/start/lsp-status.nvim | 1 - 5 files changed, 192 insertions(+), 124 deletions(-) create mode 100644 src/.config/nvim/lua/coding.lua delete mode 160000 src/.local/share/nvim/site/pack/3pp/start/lsp-status.nvim diff --git a/.gitmodules b/.gitmodules index a349633..d42ac94 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ +################ +# note-taking setup +################ [submodule "src/.local/bin/pyinstantref"] path = src/.local/bin/pyinstantref url = https://github.com/dogeystamp/pyinstantref @@ -5,6 +8,12 @@ path = src/.local/bin/inkscape-shortcut-manager url = https://github.com/dogeystamp/inkscape-shortcut-manager + + +################ +# neovim plugins +################ + # prompts # telescope.vim [submodule "src/.local/share/nvim/site/pack/3pp/start/telescope.nvim"] @@ -32,12 +41,6 @@ path = src/.local/share/nvim/site/pack/3pp/start/vim-gitgutter url = https://github.com/airblade/vim-gitgutter.git -# error/warning/info box -# coding.vim -[submodule "src/.local/share/nvim/site/pack/3pp/start/trouble.nvim"] - path = src/.local/share/nvim/site/pack/3pp/start/trouble.nvim - url = https://github.com/folke/trouble.nvim - # auto close brackets and quotes # coding.vim [submodule "src/.local/share/nvim/site/pack/3pp/start/auto-pairs"] @@ -51,13 +54,10 @@ url = https://github.com/puremourning/vimspector.git # language smarts -# coding.vim +# coding.lua [submodule "src/.local/share/nvim/site/pack/3pp/start/nvim-lspconfig"] path = src/.local/share/nvim/site/pack/3pp/start/nvim-lspconfig url = https://github.com/neovim/nvim-lspconfig.git -[submodule "src/.local/share/nvim/site/pack/3pp/start/lsp-status.nvim"] - path = src/.local/share/nvim/site/pack/3pp/start/lsp-status.nvim - url = https://github.com/nvim-lua/lsp-status.nvim.git [submodule "src/.local/share/nvim/site/pack/3pp/start/nvim-cmp"] path = src/.local/share/nvim/site/pack/3pp/start/nvim-cmp url = https://github.com/hrsh7th/nvim-cmp.git @@ -68,8 +68,14 @@ path = src/.local/share/nvim/site/pack/3pp/start/nvim-treesitter url = https://github.com/nvim-treesitter/nvim-treesitter.git +# error/warning/info box +# coding.lua +[submodule "src/.local/share/nvim/site/pack/3pp/start/trouble.nvim"] + path = src/.local/share/nvim/site/pack/3pp/start/trouble.nvim + url = https://github.com/folke/trouble.nvim + # aesthetic changes -# coding.vim +# init.lua [submodule "src/.local/share/nvim/site/pack/3pp/start/dressing.nvim"] path = src/.local/share/nvim/site/pack/3pp/start/dressing.nvim url = https://github.com/stevearc/dressing.nvim.git diff --git a/README.md b/README.md index 755dda9..2a9e348 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,15 @@ My dotfiles. ## Installation +Clone with submodules (this is necessary for Neovim plugins): + +```bash +git clone --recurse-submodules https://github.com/dogeystamp/dots.git +# alternatively, after cloning: +git submodule init +git submodule update +``` + Symlink all the files in src/ to your home directory using the provided dotinstall.sh script, or manually. Otherwise, copy them manually to your home directory. @@ -22,9 +31,13 @@ once the dotfiles are installed, see `~/.config/dot_profile.example` for more in ### Notes -`.local/bin/keyboard.sh` provides changes I like, such as swapping escape and caps lock, which you should remove if you don't need. +- `.local/bin/keyboard.sh` provides changes I like, such as swapping escape and caps lock, which you should remove if you don't need. -My qutebrowser configuration emphasizes privacy over usability, and you might need to edit it to suit your needs if you want to use it. +- My qutebrowser configuration emphasizes privacy over usability, and you might need to edit it to suit your needs if you want to use it. + +- Neovim plugins are installed [via git submodule](https://hiphish.github.io/blog/2021/12/05/managing-vim-plugins-without-plugin-manager/) + rather than through conventional means. This has less complexity than a plugin manager since I already manage all my dotfiles under Git. + Plugins are declared in `.gitmodules`. **Desktop Preview** diff --git a/src/.config/nvim/lua/coding.lua b/src/.config/nvim/lua/coding.lua new file mode 100644 index 0000000..dc55e45 --- /dev/null +++ b/src/.config/nvim/lua/coding.lua @@ -0,0 +1,140 @@ +-- stuff for coding + + + +------ +-- syntax highlighting +-- plug: nvim-treesitter +------ +require'nvim-treesitter.configs'.setup { + ensure_installed = { "c", "cpp", "javascript", "typescript", "python", "vim", "fish", "bash" }, + sync_install = false, + auto_install = false, + highlight = { + enable = true, + + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + }, +} + + +------ +-- diagnostics box +-- plug: trouble.nvim +------ +require('trouble').setup({ + icons = false, + fold_open = "v", -- icon used for open folds + fold_closed = ">", -- icon used for closed folds + indent_lines = false, -- add an indent guide below the fold icons + signs = { + -- icons / text used for a diagnostic + error = "error", + warning = "warn", + hint = "hint", + information = "info" + }, + use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client +}) + + + +-------------------------------- +-------------------------------- +-- language smarts (LSP and completion) +-------------------------------- +-------------------------------- + +------ +-- language server (LSP) +-- plug: nvim-lspconfig +------ +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + local opts = { noremap=true, silent=true } + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'gK', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'gt', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ss', 'lua vim.lsp.buf.workspace_symbol()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.format()', opts) +end + +-- table declares LSPs to be set up +-- as well as settings per server (overrides defaults) +local servers = { + --pyright = {}, + pylsp = { + settings = { + plugins = { + ['python-lsp-black'] = {}, + ['python-pyflakes'] = {}, + ['pylsp-mypy'] = {}, + }, + }, + }, + clangd = {}, + tsserver = {}, + bashls = {}, + cssls = {}, + rust_analyzer = { + settings = { + ['rust-analyzer'] = { + check = { + allTargets = false, + }, + }, + }, + }, +} +local nvim_lsp = require('lspconfig') +for lsp, sv_settings in pairs(servers) do + -- defaults + settings = { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + } + } + for k, v in pairs(servers[lsp]) do settings[k] = v end + nvim_lsp[lsp].setup(settings) +end + + +------ +-- completions +-- plug: nvim-cmp, cmp-nvim-lsp +------ +local cmp = require('cmp') +cmp.setup({ + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'buffer' }, + }) +}) diff --git a/src/.config/nvim/lua/init.lua b/src/.config/nvim/lua/init.lua index 30dceaa..a268d08 100644 --- a/src/.config/nvim/lua/init.lua +++ b/src/.config/nvim/lua/init.lua @@ -1,22 +1,13 @@ --- Syntax highlighting -require'nvim-treesitter.configs'.setup { - ensure_installed = { "c", "cpp", "javascript", "typescript", "python", "vim", "fish", "bash" }, - sync_install = false, - auto_install = false, - highlight = { - enable = true, +-------------------------------- +-------------------------------- +-- miscellaneous plugins +-------------------------------- +-------------------------------- - disable = function(lang, buf) - local max_filesize = 100 * 1024 -- 100 KB - local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) - if ok and stats and stats.size > max_filesize then - return true - end - end, - }, -} - --- motions to hop between URLs fast +------ +-- url motions +-- plug: urlview.nvim +------ require("urlview").setup({ jump = { prev = "uj", @@ -24,104 +15,23 @@ require("urlview").setup({ }, }) -local on_attach = function(client, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- Enable completion triggered by - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') - - local opts = { noremap=true, silent=true } - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'gK', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'gt', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'ss', 'lua vim.lsp.buf.workspace_symbol()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) - buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.format()', opts) -end - --- settings per server (overrides defaults) -local servers = { - --pyright = {}, - pylsp = { - settings = { - plugins = { - ['python-lsp-black'] = {}, - ['python-pyflakes'] = {}, - ['pylsp-mypy'] = {}, - }, - }, - }, - clangd = {}, - tsserver = {}, - bashls = {}, - cssls = {}, - rust_analyzer = { - settings = { - ['rust-analyzer'] = { - check = { - allTargets = false, - }, - }, - }, - }, -} - -local nvim_lsp = require('lspconfig') -for lsp, sv_settings in pairs(servers) do - -- defaults - settings = { - on_attach = on_attach, - flags = { - debounce_text_changes = 150, - } - } - for k, v in pairs(servers[lsp]) do settings[k] = v end - nvim_lsp[lsp].setup(settings) -end +------ -- fancy prompts +-- plug: dressing.nvim +------ require('dressing').setup({ input = { insert_only = false, } }) -local cmp = require'cmp' -cmp.setup({ - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'buffer' }, - }) -}) --- improved error list -require('trouble').setup({ - icons = false, - fold_open = "v", -- icon used for open folds - fold_closed = ">", -- icon used for closed folds - indent_lines = false, -- add an indent guide below the fold icons - signs = { - -- icons / text used for a diagnostic - error = "error", - warning = "warn", - hint = "hint", - information = "info" - }, - use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client -}) + +-------------------------------- +-------------------------------- +-- imports (see .config/nvim/lua/) +-------------------------------- +-------------------------------- + +require("coding") diff --git a/src/.local/share/nvim/site/pack/3pp/start/lsp-status.nvim b/src/.local/share/nvim/site/pack/3pp/start/lsp-status.nvim deleted file mode 160000 index 54f48eb..0000000 --- a/src/.local/share/nvim/site/pack/3pp/start/lsp-status.nvim +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 54f48eb5017632d81d0fd40112065f1d062d0629