From e115f6e8d6b23484df3303953ca7d21eca3da4af Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 24 Feb 2023 07:31:04 +0100 Subject: [PATCH] Update neovim config. Remote lsp-zero --- dot_config/nvim/after/plugin/cmp.lua | 85 +++++++++++ dot_config/nvim/after/plugin/hop.lua | 14 ++ dot_config/nvim/after/plugin/lsp.lua | 160 +++++++++----------- dot_config/nvim/after/plugin/telescope.lua | 1 + dot_config/nvim/after/plugin/treesitter.lua | 35 +++-- dot_config/nvim/init.lua | 95 +++++++----- dot_zshrc.tmpl | 3 +- 7 files changed, 253 insertions(+), 140 deletions(-) create mode 100644 dot_config/nvim/after/plugin/cmp.lua create mode 100644 dot_config/nvim/after/plugin/hop.lua diff --git a/dot_config/nvim/after/plugin/cmp.lua b/dot_config/nvim/after/plugin/cmp.lua new file mode 100644 index 0000000..01f483e --- /dev/null +++ b/dot_config/nvim/after/plugin/cmp.lua @@ -0,0 +1,85 @@ +local ok, cmp = pcall(require, 'cmp') +if not ok then + return +end + +require('luasnip.loaders.from_vscode').lazy_load() + +local luasnip = require('luasnip') +local lspkind = require('lspkind') +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 1}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + }, + window = { + documentation = cmp.config.window.bordered() + }, + formatting = { + format = lspkind.cmp_format({ + mode = 'symbol_text', -- show only symbol annotations + maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) + }) + }, + mapping = { + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), + + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), + + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({select = true}), + [''] = cmp.mapping.confirm({select = false}), + + [''] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, {'i', 's'}), + + [''] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, {'i', 's'}), + + [''] = cmp.mapping(function(fallback) + local col = vim.fn.col('.') - 1 + + if cmp.visible() then + cmp.select_next_item(select_opts) + elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + fallback() + else + cmp.complete() + end + end, {'i', 's'}), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item(select_opts) + else + fallback() + end + end, {'i', 's'}), + }, +}) + + diff --git a/dot_config/nvim/after/plugin/hop.lua b/dot_config/nvim/after/plugin/hop.lua new file mode 100644 index 0000000..d79a57e --- /dev/null +++ b/dot_config/nvim/after/plugin/hop.lua @@ -0,0 +1,14 @@ +local ok, hop = pcall(require, 'hop') +if not ok then + return +end + +hop.setup { + quit_key = '', + uppercase_labels = true +} + +local map = vim.keymap.set +map('n', 'f', function() hop.hint_char1({current_line_only = true }) end, {remap=true}) +map('n', 's', function() hop.hint_char2() end, {remap=true}) + diff --git a/dot_config/nvim/after/plugin/lsp.lua b/dot_config/nvim/after/plugin/lsp.lua index b143692..093560f 100644 --- a/dot_config/nvim/after/plugin/lsp.lua +++ b/dot_config/nvim/after/plugin/lsp.lua @@ -1,95 +1,21 @@ -local ok, lsp = pcall(require, 'lsp-zero') +local ok, lsp = pcall(require, 'lspconfig') if not ok then return end -lsp.preset("recommended") - --- Fix Undefined global 'vim' -lsp.configure('sumneko_lua', { - settings = { - Lua = { - diagnostics = { - globals = { 'vim' } - } - } - } -}) - -local has_words_before = function() - unpack = unpack or table.unpack - 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') -local cmp_select = {behavior = cmp.SelectBehavior.Select} -local cmp_mappings = lsp.defaults.cmp_mappings({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.complete(), - [""] = 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" }), -}) - -local lspkind = require('lspkind') -local cmp_formatting = { - format = lspkind.cmp_format({ - mode = 'symbol_text', -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) +local sign = function(opts) + -- See :help sign_define() + vim.fn.sign_define(opts.name, { + texthl = opts.name, + text = opts.text, + numhl = '' }) -} - -lsp.setup_nvim_cmp({ - mapping = cmp_mappings, - formatting = cmp_formatting -}) - -lsp.on_attach(function(client, bufnr) - local bufmap = function(mode, lhs, rhs) - local opts = {buffer = true, remap = false} - vim.keymap.set(mode, lhs, rhs, opts) - end - - -- List diagnostics in Telescope - bufmap('n', 'gA', 'Telescope diagnostics') - - -- Lists all the references - bufmap('n', 'gr', 'Telescope lsp_references') -end) - - -local on_attach_format = function(client) - require("lsp-format").on_attach(client) end -lsp.configure('clangd', { - on_attach = on_attach_format -}) - -lsp.nvim_workspace() -lsp.setup() +sign({name = 'DiagnosticSignError', text = '✘'}) +sign({name = 'DiagnosticSignWarn', text = '▲'}) +sign({name = 'DiagnosticSignHint', text = '⚑'}) +sign({name = 'DiagnosticSignInfo', text = ''}) vim.diagnostic.config({ virtual_text = false, @@ -101,3 +27,67 @@ vim.diagnostic.config({ prefix = '', }, }) + +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( +vim.lsp.handlers.hover, +{border = 'rounded'} +) + +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( +vim.lsp.handlers.signature_help, +{border = 'rounded'} +) + +vim.lsp.handlers["workspace/diagnostic/refresh"] = function(_, _, ctx) + local ns = vim.lsp.diagnostic.get_namespace(ctx.client_id) + pcall(vim.diagnostic.reset, ns) + return true +end + +require("lsp-format").setup {} + +local on_attach = function(client) + local bufmap = function(mode, lhs, rhs) + local opts = {buffer = true} + vim.keymap.set(mode, lhs, rhs, opts) + end + require("lsp-format").on_attach(client) + + bufmap('n', 'K', 'lua vim.lsp.buf.hover()') + bufmap('n', 'gd', 'lua vim.lsp.buf.definition()') + bufmap('n', 'gD', 'lua vim.lsp.buf.declaration()') + bufmap('n', 'go', 'lua vim.lsp.buf.type_definition()') + bufmap('n', 'gs', 'lua vim.lsp.buf.signature_help()') + bufmap('n', 'gA', 'Telescope diagnostics') + bufmap('n', 'gr', 'Telescope lsp_references') + bufmap('n', 'gi', 'Telescope lsp_implementations') + bufmap('n', '', 'lua vim.lsp.buf.rename()') + bufmap('n', '', 'lua vim.lsp.buf.format({async = true})') + bufmap('n', '', 'lua vim.lsp.buf.code_action()') + bufmap('x', '', 'lua vim.lsp.buf.range_code_action()') + bufmap('n', 'gl', 'lua vim.diagnostic.open_float()') + bufmap('n', '[d', 'lua vim.diagnostic.goto_prev()') + bufmap('n', ']d', 'lua vim.diagnostic.goto_next()') +end + +lsp.gopls.setup { on_attach = on_attach } +lsp.clangd.setup { on_attach = on_attach } +lsp.ltex.setup { on_attach = on_attach } +lsp.svelte.setup { on_attach = on_attach } +lsp.tsserver.setup { on_attach = on_attach } +lsp.lua_ls.setup { + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + }, + -- workspace = { + -- library = vim.api.nvim_get_runtime_file("", true), + -- }, + -- telemetry = { + -- enable = false, + -- }, + } + }, + on_attach = on_attach +} diff --git a/dot_config/nvim/after/plugin/telescope.lua b/dot_config/nvim/after/plugin/telescope.lua index 348acbb..1a7e83b 100644 --- a/dot_config/nvim/after/plugin/telescope.lua +++ b/dot_config/nvim/after/plugin/telescope.lua @@ -32,3 +32,4 @@ map('n',"f", "Telescope live_grep") map('n',"g", "Telescope grep_string") map('n',"b", "Telescope buffers") map('n',"h", "Telescope help_tags") +map('n',"z=", "Telescope spell_suggest") diff --git a/dot_config/nvim/after/plugin/treesitter.lua b/dot_config/nvim/after/plugin/treesitter.lua index 5981801..ed81546 100644 --- a/dot_config/nvim/after/plugin/treesitter.lua +++ b/dot_config/nvim/after/plugin/treesitter.lua @@ -5,24 +5,31 @@ end treesitter.setup { - -- A list of parser names, or "all" - ensure_installed = "all", - - -- Install parsers synchronously (only applied to `ensure_installed`) + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + } + }, + }, + ensure_installed = { + 'javascript', + 'typescript', + 'css', + 'json', + 'c', + 'lua', + 'go' + }, sync_install = false, - - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally auto_install = true, - highlight = { - -- `false` will disable the whole extension enable = true, - - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages additional_vim_regex_highlighting = false, }, } diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index ed97d82..6b458af 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -1,26 +1,24 @@ HOME = os.getenv("HOME") vim.cmd([[colorscheme gruvbox]]) -vim.g.mapleader = " " +vim.g.mapleader = ' ' vim.g.maplocalleader = '\\' -- Plugins require "paq" { "savq/paq-nvim"; - {"nvim-treesitter/nvim-treesitter", run=function() vim.cmd "TSUpdate" end}; + "nvim-treesitter/nvim-treesitter"; "nvim-treesitter/nvim-treesitter-textobjects"; "nvim-tree/nvim-web-devicons"; - "onsails/lspkind.nvim"; - - "VonHeikemen/lsp-zero.nvim"; -- LSP support + "onsails/lspkind.nvim"; "lukas-reineke/lsp-format.nvim"; "neovim/nvim-lspconfig"; - "williamboman/mason.nvim"; - "williamboman/mason-lspconfig.nvim"; + -- "williamboman/mason.nvim"; + -- "williamboman/mason-lspconfig.nvim"; -- Autocomplete "hrsh7th/nvim-cmp"; @@ -34,38 +32,52 @@ require "paq" { "L3MON4D3/LuaSnip"; "rafamadriz/friendly-snippets"; + -- Programming support "kylechui/nvim-surround"; "windwp/nvim-autopairs"; "numToStr/Comment.nvim"; {"phaazon/hop.nvim", branch="v2"}; - "nvim-lua/plenary.nvim"; - -- Fuzzy search {"nvim-telescope/telescope-fzf-native.nvim", run="gmake"}; "nvim-telescope/telescope-file-browser.nvim"; "nvim-telescope/telescope.nvim"; + "folke/trouble.nvim"; "mfussenegger/nvim-dap"; + "theHamsta/nvim-dap-virtual-text"; "rcarriga/nvim-dap-ui"; + "NvChad/nvim-colorizer.lua"; "lewis6991/gitsigns.nvim"; - -- "ray-x/go.nvim"; + "tpope/vim-fugitive"; "renerocksai/telekasten.nvim"; "renerocksai/calendar-vim"; + "nvim-lua/plenary.nvim"; + "akinsho/toggleterm.nvim"; "nvim-lualine/lualine.nvim"; "ellisonleao/gruvbox.nvim"; } require('nvim-web-devicons').setup {} -require('lsp-format').setup {} -require('nvim-autopairs').setup() require('nvim-surround').setup() require('Comment').setup() -require('hop').setup() require('dapui').setup() require('gitsigns').setup() +require("trouble").setup() +require('nvim-autopairs').setup({ + fast_wrap = {}, +}) + +require 'colorizer'.setup { + filetypes = { + 'css', + 'javascript', + scss = { rgb_fn = true; }; + html = { mode = 'foreground'; } + }, +} require('lualine').setup { options = { @@ -76,29 +88,27 @@ require('lualine').setup { } } +require('toggleterm').setup({ + open_mapping = '', + direction = 'horizontal', + shade_terminals = true +}) + require("gruvbox").setup { italic = false, contrast = "hard" } -local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {}) -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = "*.go", - callback = function() - require('go.format').goimport() - end, - group = format_sync_grp, -}) - -- Options local o = vim.opt -- basic settings o.encoding = "utf-8" o.backspace = "indent,eol,start" -- backspace works on every char in insert mode -o.completeopt = 'menu,menuone,noselect' +o.completeopt = {'menu', 'menuone', 'noselect'} o.history = 1000 -o.dictionary = '/usr/share/dict/words' +-- o.dictionary = '/home/jan/.vim/dict/words' +-- o.dictionary = '/usr/share/dict/words' o.startofline = true o.title = true o.clipboard='unnamedplus' @@ -108,7 +118,8 @@ o.timeoutlen = 200 o.ttimeoutlen = 0 -- Spellchecker -o.spelllang="en_us" +o.spell = false +o.spelllang = { 'en_us' } o.spellfile= HOME .. '/.vim/spell/en.utf8.add' o.thesaurus= HOME .. '/.vim/thesaurus/english.txt' @@ -126,7 +137,6 @@ o.list = false -- do not display white characters o.termguicolors = true o.background = "dark" -- o.updatetime = 100 -vim.cmd([[highlight SpellBad cterm=undercurl ctermfg=Red]]) -- Folding o.foldenable = false @@ -140,7 +150,7 @@ o.showbreak= '↪' -- character to show when line is broken o.number = true -- line number on the left o.relativenumber = true o.numberwidth = 3 -- always reserve 3 spaces for line number -o.signcolumn = 'yes' -- keep 1 column for coc.vim check +o.signcolumn = 'yes' o.modelines = 0 -- Bottombar @@ -193,14 +203,29 @@ o.backup = true -- use backup files o.writebackup = false o.swapfile = false -- do not use swap file o.undofile = true -o.undodir = HOME .. '/.vim/dirs/undo//' -- undo files -o.backupdir = HOME .. '/.vim/dirs/backup//' -- backups +o.undodir = HOME .. '/.local/share/nvim/dirs/undo//' -- undo files +o.backupdir = HOME .. '/.local/share/nvim/dirs/backup//' -- backups -- Commands mode o.wildmenu = true -- on TAB, complete options for system command o.wildignore = 'deps,.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc' --- Mappings {{{ +vim.cmd([[ +au BufRead,BufNewFile *.md set ft=mkd tw=80 syntax=markdown +]]) + +vim.api.nvim_create_user_command('ReloadConfig', 'source $MYVIMRC', {}) + +local group = vim.api.nvim_create_augroup('user_cmds', {clear = true}) + +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight on yank', + group = group, + callback = function() + vim.highlight.on_yank({higroup = 'Visual', timeout = 200}) + end, +}) + local map = vim.keymap.set map({'n','v'}, '', "", { silent = true }) @@ -235,10 +260,6 @@ map('n','q', 'bdelete', { silent = true }) map('n','', '') map('n','', '') --- more natural movement with wrap on -map({'n','v'},'j', 'gj', { noremap = true, silent = true }) -map({'n','v'},'k', 'gk', { noremap = true, silent = true }) - -- Easy buffer navigation map('n','', 'h', { silent = true }) map('n','', 'j', { silent = true }) @@ -249,9 +270,3 @@ map('n','', 'resize -2', { silent = true }) map('n','', 'resize +2', { silent = true }) map('n','', 'vertical resize -2', { silent = true }) map('n','', 'vertical resize +2', { silent = true }) - -map({'n','i'},"s", "HopChar2", { silent = true }) -map('n',"w", "HopWord", { silent = true }) - -map('n',"", ":set invspell", { silent = true }) ---}}} diff --git a/dot_zshrc.tmpl b/dot_zshrc.tmpl index 3b24c4b..40ca3a7 100644 --- a/dot_zshrc.tmpl +++ b/dot_zshrc.tmpl @@ -38,11 +38,12 @@ export GPG_TTY=$TTY {{- if eq .chezmoi.os "openbsd" }} export PORTSDIR_PATH=/usr/ports/:/usr/ports/openbsd-wip -export PATH="$HOME/local/bin:$HOME/perl5/bin:$HOME/gems/bin:$HOME/.cargo/bin:$HOME/.yarn/bin:$PATH" +export PATH="$HOME/dev/src/ltex-ls-15.2.0/bin:$HOME/local/bin:$HOME/perl5/bin:$HOME/gems/bin:$HOME/.cargo/bin:$HOME/.yarn/bin:$PATH" export PERL5LIB=$HOME/perl5/lib/perl5 export PERL_LOCAL_LIB_ROOT=$HOME/perl5 export PERL_MB_OPT='--install_base "/home/jan/perl5"' export PERL_MM_OPT='INSTALL_BASE=/home/jan/perl5' +export JAVA_HOME=/usr/local/jdk-11/ export PMIX_MCA_gds='hash' alias top='htop'