From 511efe89ed084bc922ae142d32e08427859198f4 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 10 Jun 2024 23:07:28 +0200 Subject: nvim: Completely rewrite my configuration --- .config/nvim/after/plugin/colors.lua | 14 -- .config/nvim/after/plugin/comment.lua | 1 - .config/nvim/after/plugin/emmet.lua | 1 - .config/nvim/after/plugin/fugitive.lua | 1 - .config/nvim/after/plugin/lsp.lua | 49 ------ .config/nvim/after/plugin/luasnip.lua | 202 ----------------------- .config/nvim/after/plugin/nvim-cmp.lua | 32 ---- .config/nvim/after/plugin/sort-motion.lua | 1 - .config/nvim/after/plugin/surround.lua | 27 --- .config/nvim/after/plugin/treesitter-context.lua | 8 - .config/nvim/after/plugin/treesitter.lua | 89 ---------- .config/nvim/after/plugin/undotree.lua | 1 - 12 files changed, 426 deletions(-) delete mode 100644 .config/nvim/after/plugin/colors.lua delete mode 100644 .config/nvim/after/plugin/comment.lua delete mode 100644 .config/nvim/after/plugin/emmet.lua delete mode 100644 .config/nvim/after/plugin/fugitive.lua delete mode 100644 .config/nvim/after/plugin/lsp.lua delete mode 100644 .config/nvim/after/plugin/luasnip.lua delete mode 100644 .config/nvim/after/plugin/nvim-cmp.lua delete mode 100644 .config/nvim/after/plugin/sort-motion.lua delete mode 100644 .config/nvim/after/plugin/surround.lua delete mode 100644 .config/nvim/after/plugin/treesitter-context.lua delete mode 100644 .config/nvim/after/plugin/treesitter.lua delete mode 100644 .config/nvim/after/plugin/undotree.lua (limited to '.config/nvim/after/plugin') diff --git a/.config/nvim/after/plugin/colors.lua b/.config/nvim/after/plugin/colors.lua deleted file mode 100644 index 779c60d..0000000 --- a/.config/nvim/after/plugin/colors.lua +++ /dev/null @@ -1,14 +0,0 @@ -local nohl = { bg = "surface" } - -require('rose-pine').setup { - styles = { - transparency = true, - }, - highlight_groups = { - Pmenu = nohl, - StatusLine = nohl, - StatusLineNC = nohl, - }, -} - -vim.cmd.colorscheme('rose-pine') diff --git a/.config/nvim/after/plugin/comment.lua b/.config/nvim/after/plugin/comment.lua deleted file mode 100644 index 933d7b7..0000000 --- a/.config/nvim/after/plugin/comment.lua +++ /dev/null @@ -1 +0,0 @@ -require('Comment').setup {} diff --git a/.config/nvim/after/plugin/emmet.lua b/.config/nvim/after/plugin/emmet.lua deleted file mode 100644 index 56e67db..0000000 --- a/.config/nvim/after/plugin/emmet.lua +++ /dev/null @@ -1 +0,0 @@ -vim.g.user_emmet_install = false diff --git a/.config/nvim/after/plugin/fugitive.lua b/.config/nvim/after/plugin/fugitive.lua deleted file mode 100644 index 6e1b92d..0000000 --- a/.config/nvim/after/plugin/fugitive.lua +++ /dev/null @@ -1 +0,0 @@ -vim.keymap.set('n', 'gs', vim.cmd.Git) diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua deleted file mode 100644 index e0684e2..0000000 --- a/.config/nvim/after/plugin/lsp.lua +++ /dev/null @@ -1,49 +0,0 @@ -local conf = require('lspconfig') - -conf.clangd.setup { - cmd = {'clangd', '-header-insertion=never'} -} -conf.gopls.setup {} -conf.rust_analyzer.setup {} -conf.lua_ls.setup { - settings = { - Lua = { - runtime = { - version = 'LuaJIT', - }, - diagnostics = { - globals = { - 'vim', - 'require', - }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file('', true), - }, - telemetry = { - enable = false, - }, - }, - }, -} - -vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('MangoLspConfig', {}), - callback = function(ev) - local function remap(mode, map, fn) - vim.keymap.set(mode, map, fn, { buffer = ev.buf }) - end - - vim.diagnostic.disable() - vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' - remap('n', 'K', vim.lsp.buf.hover) - remap('n', 'gd', vim.lsp.buf.definition) - remap('n', 'gi', vim.lsp.buf.implementation) - remap('n', 'gr', vim.lsp.buf.rename) - remap('n', 'gt', vim.lsp.buf.type_definition) - remap('n', 'g=', function() vim.lsp.buf.format { async = true } end) - remap('n', ']d', vim.diagnostic.goto_prev) - remap('n', '[d', vim.diagnostic.goto_next) - remap('n', 'la', vim.lsp.buf.code_action) - end, -}) diff --git a/.config/nvim/after/plugin/luasnip.lua b/.config/nvim/after/plugin/luasnip.lua deleted file mode 100644 index 5486aab..0000000 --- a/.config/nvim/after/plugin/luasnip.lua +++ /dev/null @@ -1,202 +0,0 @@ -local ls = require('luasnip') -local ts_utils = require('nvim-treesitter.ts_utils') -local ts_locals = require('nvim-treesitter.locals') - -local c = ls.choice_node -local d = ls.dynamic_node -local f = ls.function_node -local i = ls.insert_node -local s = ls.s -local sn = ls.snippet_node -local t = ls.text_node -local fmt = require('luasnip.extras.fmt').fmt - -local function same(index) - return f(function(args) - return args[1] - end, { index }) -end - -ls.config.set_config { - history = true, - updateevents = 'TextChanged,TextChangedI', -} - -ls.add_snippets('lua', { - s('req', fmt([[local {} = require('{}')]], { - f(function(name) - local xs = vim.split(name[1][1], '.', { plain = true }) - return xs[#xs] or '' - end, { 1 }), - i(1), - })), -}) - -local function is_ptr(str) - return string.find(str, '*', 1, true) ~= nil -end - -local function is_num(str) - return vim.regex( - '\\v^(' - .. 'u?int(8|16|32|64)?' - .. '|byte' - .. '|complex(64|128)' - .. '|float(32|64)' - .. '|rune' - .. '|uintptr' - .. ')$' - ):match_str(str) ~= nil -end - -local transforms = { - bool = 'false', - string = '""', - error = 'err', - [is_num] = '0', - [is_ptr] = 'nil', -} - -local transform = function(text) - local condition_matches = function(condition, ...) - if type(condition) == 'string' then - return condition == text - else - return condition(...) - end - end - - for condition, result in pairs(transforms) do - if condition_matches(condition, text) then - return t(result) - end - end - - return t(text .. '{}') -end - -local handlers = { - parameter_list = function(node) - local result = {} - - local count = node:named_child_count() - for idx = 0, count - 1 do - local matching_node = node:named_child(idx) - local type_node = matching_node:field('type')[1] - table.insert(result, transform( - vim.treesitter.get_node_text(type_node, 0) - )) - if idx ~= count - 1 then - table.insert(result, t({ ', ' })) - end - end - - return result - end, - - type_identifier = function(node) - local text = vim.treesitter.get_node_text(node, 0) - return { transform(text) } - end, -} - -local function_node_types = { - function_declaration = true, - method_declaration = true, - func_literal = true, -} - -local function go_result_type() - local cursor_node = ts_utils.get_node_at_cursor() - if cursor_node == nil then - print('Unable to find position') - return t('') - end - local scope = ts_locals.get_scope_tree(cursor_node, 0) - - local function_node - for _, v in ipairs(scope) do - if function_node_types[v:type()] then - function_node = v - break - end - end - - if not function_node then - print('Not inside of a function') - return t('') - end - - local query = vim.treesitter.query.parse('go', [[ - [ - (method_declaration result: (_) @id) - (function_declaration result: (_) @id) - (func_literal result: (_) @id) - ] - ]]) - for _, node in query:iter_captures(function_node, 0) do - if handlers[node:type()] then - return handlers[node:type()](node) - end - end -end - -ls.add_snippets('go', { - s( - 'ife', - fmt( - [[ - if err != nil { - return <> - } - ]], - { - d(1, function() - return sn(nil, go_result_type()) - end), - }, - { - delimiters = '<>', - } - ) - ), -}) - - -ls.add_snippets('c', { - s( - 'gu', - fmt( - [[ - #ifndef {}_H - #define {}_H - - {} - - #endif /* !{}_H */ - ]], - { i(1), same(1), i(0), same(1), } - ) - ), -}) - -vim.keymap.set({ 'i', 's' }, '', function() - if ls.expand_or_jumpable() then - ls.expand_or_jump() - end -end) -vim.keymap.set('i', '', function() - if ls.jumpable(-1) then - ls.jump(-1) - end -end) -vim.keymap.set('i', '', function() - if ls.choice_active() then - ls.change_choice(-1) - end -end) -vim.keymap.set('i', '', function() - if ls.choice_active() then - ls.change_choice(1) - end -end) diff --git a/.config/nvim/after/plugin/nvim-cmp.lua b/.config/nvim/after/plugin/nvim-cmp.lua deleted file mode 100644 index 399d5a3..0000000 --- a/.config/nvim/after/plugin/nvim-cmp.lua +++ /dev/null @@ -1,32 +0,0 @@ -local capabilities = require('cmp_nvim_lsp').default_capabilities() -local cmp = require('cmp') -local conf = require('lspconfig') -local snip = require('luasnip') - -conf['clangd'].setup { capabilities = capabilities } -conf['gopls'].setup { capabilities = capabilities } -conf['lua_ls'].setup { capabilities = capabilities } -conf['rust_analyzer'].setup { capabilities = capabilities } -cmp.setup { - snippet = { - expand = function(args) - snip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'path' }, - { name = 'luasnip' }, - }, { - { name = 'buffer', length = 5 }, - }), - experimental = { - ghost_text = true, - } -} diff --git a/.config/nvim/after/plugin/sort-motion.lua b/.config/nvim/after/plugin/sort-motion.lua deleted file mode 100644 index d408de8..0000000 --- a/.config/nvim/after/plugin/sort-motion.lua +++ /dev/null @@ -1 +0,0 @@ -vim.g.sort_motion_flags = 'l' diff --git a/.config/nvim/after/plugin/surround.lua b/.config/nvim/after/plugin/surround.lua deleted file mode 100644 index 605b1eb..0000000 --- a/.config/nvim/after/plugin/surround.lua +++ /dev/null @@ -1,27 +0,0 @@ -require('nvim-surround').setup { - surrounds = { - ['’'] = { - add = { '‘', '’' }, - find = '‘[^‘’]*’', - delete = '^(‘)().-(’)()$' - }, - - ['‘'] = { - add = { '‘ ', ' ’' }, - find = '‘[^‘’]*’', - delete = '^(‘ *)().-( *’)()$' - }, - - ['”'] = { - add = { '“', '”' }, - find = '“[^“”]*”', - delete = '^(“)().-(”)()$' - }, - - ['“'] = { - add = { '“ ', ' ”' }, - find = '“[^“”]*”', - delete = '^(“ *)().-( *”)()$' - }, - } -} diff --git a/.config/nvim/after/plugin/treesitter-context.lua b/.config/nvim/after/plugin/treesitter-context.lua deleted file mode 100644 index 27af4e8..0000000 --- a/.config/nvim/after/plugin/treesitter-context.lua +++ /dev/null @@ -1,8 +0,0 @@ -require('treesitter-context').setup { - enable = true, - max_lines = 2, - multiline_threshold = 2, - line_numbers = true, - trim_scope = 'inner', - mode = 'cursor', -} diff --git a/.config/nvim/after/plugin/treesitter.lua b/.config/nvim/after/plugin/treesitter.lua deleted file mode 100644 index e441371..0000000 --- a/.config/nvim/after/plugin/treesitter.lua +++ /dev/null @@ -1,89 +0,0 @@ -local config = require('nvim-treesitter.parsers').get_parser_configs() -config.gsp = { - install_info = { - url = 'https://git.sr.ht/~mango/tree-sitter-gsp', - files = {'src/parser.c'}, - }, - filetype = 'gsp', -} - -require('nvim-treesitter.configs').setup { - ensure_installed = { - 'c', - 'gsp', - 'vim', - 'vimdoc', - }, - - sync_install = false, - auto_install = true, - - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, - - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - node_decremental = '', - } - }, - - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ['ab'] = '@block.outer', - ['ib'] = '@block.inner', - ['ac'] = '@comment.outer', - ['ic'] = '@comment.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['an'] = '@node.outer', - ['in'] = '@node.inner', - ['at'] = '@text.outer', - ['it'] = '@text.outer', - }, - }, - move = { - enable = true, - set_jumps = true, - goto_next_start = { - [']c'] = '@comment.outer', - [']f'] = '@function.outer', - [']b'] = '@block.outer', - [']n'] = '@node.outer', - [']t'] = '@text.outer', - }, - goto_next_end = { - [']C'] = '@comment.outer', - [']F'] = '@function.outer', - [']B'] = '@block.outer', - [']N'] = '@node.outer', - [']T'] = '@text.outer', - }, - goto_previous_start = { - ['[c'] = '@comment.outer', - ['[f'] = '@function.outer', - ['[b'] = '@block.outer', - ['[n'] = '@node.outer', - ['[t'] = '@text.outer', - }, - goto_previous_end = { - ['[C'] = '@comment.outer', - ['[F'] = '@function.outer', - ['[B'] = '@block.outer', - ['[N'] = '@node.outer', - ['[T'] = '@text.outer', - }, - }, - }, - - indent = { - enable = true, - }, -} diff --git a/.config/nvim/after/plugin/undotree.lua b/.config/nvim/after/plugin/undotree.lua deleted file mode 100644 index a346462..0000000 --- a/.config/nvim/after/plugin/undotree.lua +++ /dev/null @@ -1 +0,0 @@ -vim.keymap.set('n', 'u', vim.cmd.UndotreeToggle) -- cgit v1.2.3