From 2a6ff7e85a6718d975eecc16a646f2119e2c10be Mon Sep 17 00:00:00 2001 From: iofq Date: Thu, 8 Aug 2024 01:19:53 -0500 Subject: [PATCH] icmp and snip rice --- config/init.lua | 92 +++++++++++++++++++++++++++++++++++++++- config/lua/mini-conf.lua | 27 ++++++------ config/lua/nvim-conf.lua | 21 ++++----- config/lua/snippets.lua | 3 ++ plugins.nix | 10 +++++ 5 files changed, 126 insertions(+), 27 deletions(-) create mode 100644 config/lua/snippets.lua diff --git a/config/init.lua b/config/init.lua index 2b22b6f..d7ab949 100644 --- a/config/init.lua +++ b/config/init.lua @@ -22,6 +22,9 @@ vim.keymap.set("n", "fg", telescope.git_files, {noremap = true, silent = vim.keymap.set("n", "fc", telescope.command_history, {noremap = true, silent = true}) vim.keymap.set("n", "fa", telescope.live_grep, {noremap = true, silent = true}) vim.keymap.set("n", "f8", telescope.grep_string, {noremap = true, silent = true}) +vim.keymap.set("n", "fs", telescope.treesitter, {noremap = true, silent = true}) +vim.keymap.set("n", "fq", telescope.quickfix, {noremap = true, silent = true}) +vim.keymap.set("n", "fq", telescope.quickfix, {noremap = true, silent = true}) vim.keymap.set("n", "f", telescope.resume, {noremap = true, silent = true}) local telescope = require("telescope") @@ -113,12 +116,14 @@ require("nvim-treesitter.configs").setup { -- Setup language servers. local lspconfig = require('lspconfig') +local capabilities = require('cmp_nvim_lsp').default_capabilities() lspconfig.gopls.setup { on_attach = function(_, bufnr) + capabilities = capabilities vim.api.nvim_command("au BufWritePre lua vim.lsp.buf.format { async = false }") end } -lspconfig.pyright.setup {} -lspconfig.nil_ls.setup {} +lspconfig.pyright.setup { capabilities = capabilities } +lspconfig.nil_ls.setup { capabilities = capabilities } -- Global mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions @@ -149,6 +154,8 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set("n", "dr", "Telescope lsp_references", { buffer = bufnr }) vim.keymap.set("n", "dt", "Telescope lsp_type_definitions", { buffer = bufnr }) vim.keymap.set("n", "ds", "Telescope lsp_document_symbols", { buffer = bufnr }) + vim.keymap.set('n', 'dl', vim.lsp.codelens.run) + vim.keymap.set('n', 'dg', vim.diagnostic.setqflist) vim.keymap.set('n', 'df', function() vim.lsp.buf.format { async = true } end, opts) @@ -239,6 +246,87 @@ require("rose-pine").setup({ }) vim.cmd.colorscheme "rose-pine-main" +-------------------- +-- Neogen +-------------------- +require("neogen").setup{} +vim.keymap.set("n","nd", "Neogen", {noremap = true, silent = true}) + +-------------------- +---Completion +-------------------- +local cmp = require'cmp' + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + ['q'] = 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 = 'luasnip' }, + }, { + { name = 'buffer' }, + }) +}) + +cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } +}) + +cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }), + matching = { disallow_symbol_nonprefix_matching = false } +}) + +-------------------- +-- Luasnip +-------------------- +local ls = require("luasnip") +ls.config.set_config { + history = true, + updateevents = "TextChanged, TextChangedI", +} +require("luasnip.loaders.from_vscode").lazy_load() + +vim.keymap.set({"i", "s"}, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end +end, {silent = true}) + +vim.keymap.set({"i", "s"}, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end +end, {silent = true}) + +vim.keymap.set({"i", "s"}, "", function() + if ls.choice_active() then + ls.change_choice(1) + end +end, {silent = true}) + +-------------------- +-- Snippets +-------------------- +require("snippets") -------------------- -- include our config last to override -------------------- diff --git a/config/lua/mini-conf.lua b/config/lua/mini-conf.lua index fb06196..184101f 100644 --- a/config/lua/mini-conf.lua +++ b/config/lua/mini-conf.lua @@ -53,9 +53,10 @@ require('mini.pairs').setup( mappings = { ['['] = { action = 'open', pair = '[]', neigh_pattern = '[^\\].' }, ['{'] = { action = 'open', pair = '{}', neigh_pattern = '[^\\].' }, - [']'] = { action = 'close', pair = '[]', neigh_pattern = '[^\\].' }, ['}'] = { action = 'close', pair = '{}', neigh_pattern = '[^\\].' }, + ['"'] = { }, + ['\''] = { }, }, } ) @@ -75,15 +76,15 @@ indent.setup({ indent.gen_animation.none() -- -require('mini.completion').setup({ - delay = {completion = 10^7}, - window = { - info = { height = 25, width = 80, border = 'single' }, - signature = { height = 25, width = 80, border = 'single' }, - }, - lsp_completion = { - source_func = 'completefunc', - auto_setup = true, - }, - fallback_action = "" -}) +-- require('mini.completion').setup({ +-- delay = {completion = 10^7}, +-- window = { +-- info = { height = 25, width = 80, border = 'single' }, +-- signature = { height = 25, width = 80, border = 'single' }, +-- }, +-- lsp_completion = { +-- source_func = 'completefunc', +-- auto_setup = true, +-- }, +-- fallback_action = "" +-- }) diff --git a/config/lua/nvim-conf.lua b/config/lua/nvim-conf.lua index b2afb85..c7f7014 100644 --- a/config/lua/nvim-conf.lua +++ b/config/lua/nvim-conf.lua @@ -1,7 +1,6 @@ -- vim settings ++ mini.nvim.basics ---------------------------------------- vim.opt.backspace = "indent,eol,start" -vim.opt.clipboard = "unnamedplus" -- use system clipboard vim.opt.completeopt = "menuone" vim.opt.expandtab = true -- insert tabs as spaces vim.opt.inccommand = "split" -- incremental live completion @@ -27,20 +26,18 @@ vim.g.indent_blankline_use_treesitter = true -- no highlight floats vim.cmd([[ hi NormalFloat ctermbg=none ]]) - -- mappings ---------------------------------------- -local remap = function(type, key, value) - vim.api.nvim_set_keymap(type,key,value,{noremap = true, silent = true}); -end - -remap("i", "wq", "l") -remap("v", "wq", "l") -remap("n","gr", "gT") -remap("n","n", "nzz") -remap("n", "N", "Nzz") -remap("n","", "m0i`0") +vim.keymap.set("n","gr", "gT", {noremap = true, silent = true}) +vim.keymap.set("n","n", "nzz", {noremap = true, silent = true}) +vim.keymap.set("n", "N", "Nzz", {noremap = true, silent = true}) +vim.keymap.set("n","", "m0i`0", {noremap = true, silent = true}) +vim.keymap.set({'v', 'i'}, 'wq', 'l', {noremap = true, silent = true}) +vim.keymap.set({'n', 'v', 'i'}, 'qwq', 'lwqa', {noremap = true, silent = true}) +vim.keymap.set({'n', 'v'}, 'yy', '"+y', {noremap = true, silent = true}) +vim.keymap.set({'n', 'v'}, 'yp', '"+p', {noremap = true, silent = true}) +vim.keymap.set({'n', 'v'}, 'yd', '"+d', {noremap = true, silent = true}) -- Switch tab length on the fly vim.keymap.set("n", "\\t", function() diff --git a/config/lua/snippets.lua b/config/lua/snippets.lua new file mode 100644 index 0000000..732c9f3 --- /dev/null +++ b/config/lua/snippets.lua @@ -0,0 +1,3 @@ +ls.add_snippets("go", { + s("ie", fmta("if err != nil {\n\treturn \n}", { err = i(1, "err") })), +}) diff --git a/plugins.nix b/plugins.nix index aa4bf1c..5c0f151 100644 --- a/plugins.nix +++ b/plugins.nix @@ -1,10 +1,20 @@ {pkgs, ...}: { base = with pkgs.vimPlugins; [ + cmp-buffer + cmp-cmdline + cmp-nvim-lsp + cmp-path + cmp-treesitter + cmp_luasnip diffview-nvim + friendly-snippets gitsigns-nvim + luasnip mini-nvim + neogen neogit + nvim-cmp nvim-lspconfig nvim-treesitter-textobjects (nvim-treesitter.withPlugins(p: with p; [