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/.gitignore | 8 - .config/nvim/after/ftdetect/c.lua | 6 + .config/nvim/after/ftdetect/c.vim | 1 - .config/nvim/after/ftdetect/nroff.lua | 6 + .config/nvim/after/ftdetect/nroff.vim | 1 - .config/nvim/after/ftplugin/c.lua | 15 +- .config/nvim/after/ftplugin/css.lua | 3 - .config/nvim/after/ftplugin/ebnf.lua | 3 +- .config/nvim/after/ftplugin/gitcommit.lua | 2 +- .config/nvim/after/ftplugin/gitrebase.lua | 6 +- .config/nvim/after/ftplugin/go.lua | 3 - .config/nvim/after/ftplugin/gsp.lua | 3 - .config/nvim/after/ftplugin/help.lua | 8 + .config/nvim/after/ftplugin/html.lua | 3 - .config/nvim/after/ftplugin/htmldjango.lua | 1 - .config/nvim/after/ftplugin/lex.lua | 3 - .config/nvim/after/ftplugin/lua.lua | 3 - .config/nvim/after/ftplugin/mail.lua | 7 +- .config/nvim/after/ftplugin/make.lua | 3 - .config/nvim/after/ftplugin/markdown.lua | 4 +- .config/nvim/after/ftplugin/nroff.lua | 2 +- .config/nvim/after/ftplugin/python.lua | 3 +- .config/nvim/after/ftplugin/query.lua | 2 +- .config/nvim/after/ftplugin/rust.lua | 2 - .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 - .config/nvim/after/syntax/c.vim | 1 - .config/nvim/after/syntax/diff.vim | 3 - .config/nvim/after/syntax/yacc.vim | 5 - .config/nvim/init.lua | 480 ++++++++++++++++++++++- .config/nvim/lua/mango/init.lua | 3 - .config/nvim/lua/mango/lib.lua | 36 -- .config/nvim/lua/mango/packer.lua | 59 --- .config/nvim/lua/mango/remap.lua | 54 --- .config/nvim/lua/mango/set.lua | 72 ---- .config/nvim/lua/pipe.lua | 42 ++ .config/nvim/lua/snippets.lua | 176 +++++++++ 47 files changed, 742 insertions(+), 713 deletions(-) delete mode 100644 .config/nvim/.gitignore create mode 100644 .config/nvim/after/ftdetect/c.lua delete mode 100644 .config/nvim/after/ftdetect/c.vim create mode 100644 .config/nvim/after/ftdetect/nroff.lua delete mode 100644 .config/nvim/after/ftdetect/nroff.vim delete mode 100644 .config/nvim/after/ftplugin/css.lua delete mode 100644 .config/nvim/after/ftplugin/go.lua delete mode 100644 .config/nvim/after/ftplugin/gsp.lua create mode 100644 .config/nvim/after/ftplugin/help.lua delete mode 100644 .config/nvim/after/ftplugin/html.lua delete mode 120000 .config/nvim/after/ftplugin/htmldjango.lua delete mode 100644 .config/nvim/after/ftplugin/lex.lua delete mode 100644 .config/nvim/after/ftplugin/lua.lua delete mode 100644 .config/nvim/after/ftplugin/make.lua delete mode 100644 .config/nvim/after/ftplugin/rust.lua 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 delete mode 100644 .config/nvim/after/syntax/c.vim delete mode 100644 .config/nvim/after/syntax/diff.vim delete mode 100644 .config/nvim/after/syntax/yacc.vim delete mode 100644 .config/nvim/lua/mango/init.lua delete mode 100644 .config/nvim/lua/mango/lib.lua delete mode 100644 .config/nvim/lua/mango/packer.lua delete mode 100644 .config/nvim/lua/mango/remap.lua delete mode 100644 .config/nvim/lua/mango/set.lua create mode 100644 .config/nvim/lua/pipe.lua create mode 100644 .config/nvim/lua/snippets.lua diff --git a/.config/nvim/.gitignore b/.config/nvim/.gitignore deleted file mode 100644 index 6412e7b..0000000 --- a/.config/nvim/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/ftdetect/* -!/ftdetect/gsp.vim -/ftplugin -/indent -/plugin -/syntax -/queries -.luarc.json diff --git a/.config/nvim/after/ftdetect/c.lua b/.config/nvim/after/ftdetect/c.lua new file mode 100644 index 0000000..a518a11 --- /dev/null +++ b/.config/nvim/after/ftdetect/c.lua @@ -0,0 +1,6 @@ +vim.api.nvim_create_autocmd({'BufRead', 'BufNewFile'}, { + pattern = '*.[ch]', + callback = function() + vim.bo.filetype = 'c' + end, +}) diff --git a/.config/nvim/after/ftdetect/c.vim b/.config/nvim/after/ftdetect/c.vim deleted file mode 100644 index 609b487..0000000 --- a/.config/nvim/after/ftdetect/c.vim +++ /dev/null @@ -1 +0,0 @@ -au BufRead,BufNewFile *.[ch] set ft=c diff --git a/.config/nvim/after/ftdetect/nroff.lua b/.config/nvim/after/ftdetect/nroff.lua new file mode 100644 index 0000000..592f620 --- /dev/null +++ b/.config/nvim/after/ftdetect/nroff.lua @@ -0,0 +1,6 @@ +vim.api.nvim_create_autocmd({'BufRead', 'BufNewFile'}, { + pattern = '*.[1-7]', + callback = function() + vim.bo.filetype = 'nroff' + end, +}) diff --git a/.config/nvim/after/ftdetect/nroff.vim b/.config/nvim/after/ftdetect/nroff.vim deleted file mode 100644 index f1c3d67..0000000 --- a/.config/nvim/after/ftdetect/nroff.vim +++ /dev/null @@ -1 +0,0 @@ -au BufRead,BufNewFile *.[1-7] setf nroff diff --git a/.config/nvim/after/ftplugin/c.lua b/.config/nvim/after/ftplugin/c.lua index 7f8d336..6058e31 100644 --- a/.config/nvim/after/ftplugin/c.lua +++ b/.config/nvim/after/ftplugin/c.lua @@ -1,3 +1,14 @@ -local lib = require('mango.lib') +vim.bo.commentstring = '/* %s */' -lib.set_tab_width(4, true) +vim.keymap.set('v', '=', ":'<'>!clang-format -style=file -", { + desc = 'Format the current selection with Clang Format', +}) + +vim.keymap.set('n', 'K', function() + vim.cmd [[ + execute "silent !man -Tpdf '" . expand('') . "' | zathura - &" + ]] +end, { + buffer = 0, + desc = 'View the manual page for the word under the cursor', +}) diff --git a/.config/nvim/after/ftplugin/css.lua b/.config/nvim/after/ftplugin/css.lua deleted file mode 100644 index 01efc8f..0000000 --- a/.config/nvim/after/ftplugin/css.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lib = require('mango.lib') - -lib.set_tab_width(8, true) diff --git a/.config/nvim/after/ftplugin/ebnf.lua b/.config/nvim/after/ftplugin/ebnf.lua index b1bb817..264b539 100644 --- a/.config/nvim/after/ftplugin/ebnf.lua +++ b/.config/nvim/after/ftplugin/ebnf.lua @@ -1,2 +1 @@ -require('Comment.ft').ebnf = { '(*%s*)', '(*%s*)' } -vim.bo.commentstring = '(*%s*)' +vim.bo.commentstring = '(* %s *)' diff --git a/.config/nvim/after/ftplugin/gitcommit.lua b/.config/nvim/after/ftplugin/gitcommit.lua index 9aa3038..21934e4 100644 --- a/.config/nvim/after/ftplugin/gitcommit.lua +++ b/.config/nvim/after/ftplugin/gitcommit.lua @@ -1 +1 @@ -vim.opt_local.expandtab = true +vim.bo.expandtab = true diff --git a/.config/nvim/after/ftplugin/gitrebase.lua b/.config/nvim/after/ftplugin/gitrebase.lua index 948ee30..00ee21a 100644 --- a/.config/nvim/after/ftplugin/gitrebase.lua +++ b/.config/nvim/after/ftplugin/gitrebase.lua @@ -1,6 +1,5 @@ -local ts_utils = require('nvim-treesitter.ts_utils') - local function map(lhs, rhs) + local ts_utils = require('nvim-treesitter.ts_utils') vim.keymap.set('n', lhs, function() local node = ts_utils.get_node_at_cursor() if node == nil then @@ -22,7 +21,8 @@ local function map(lhs, rhs) }) end +map('d', 'drop') +map('f', 'fixup') map('p', 'pick') map('r', 'reword') map('s', 'squash') -map('f', 'fixup') diff --git a/.config/nvim/after/ftplugin/go.lua b/.config/nvim/after/ftplugin/go.lua deleted file mode 100644 index 7f8d336..0000000 --- a/.config/nvim/after/ftplugin/go.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lib = require('mango.lib') - -lib.set_tab_width(4, true) diff --git a/.config/nvim/after/ftplugin/gsp.lua b/.config/nvim/after/ftplugin/gsp.lua deleted file mode 100644 index 50a85a4..0000000 --- a/.config/nvim/after/ftplugin/gsp.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lib = require('mango.lib') - -lib.set_tab_width(2, true) diff --git a/.config/nvim/after/ftplugin/help.lua b/.config/nvim/after/ftplugin/help.lua new file mode 100644 index 0000000..0b15270 --- /dev/null +++ b/.config/nvim/after/ftplugin/help.lua @@ -0,0 +1,8 @@ +vim.api.nvim_create_autocmd('BufWinEnter', { + desc = 'Open (neo)vim help pages in a vertical split', + group = vim.api.nvim_create_augroup('mango-vert-help', { clear = true }), + buffer = 0, + callback = function() + vim.cmd.wincmd 'L' + end, +}) diff --git a/.config/nvim/after/ftplugin/html.lua b/.config/nvim/after/ftplugin/html.lua deleted file mode 100644 index 50a85a4..0000000 --- a/.config/nvim/after/ftplugin/html.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lib = require('mango.lib') - -lib.set_tab_width(2, true) diff --git a/.config/nvim/after/ftplugin/htmldjango.lua b/.config/nvim/after/ftplugin/htmldjango.lua deleted file mode 120000 index d805bec..0000000 --- a/.config/nvim/after/ftplugin/htmldjango.lua +++ /dev/null @@ -1 +0,0 @@ -html.lua \ No newline at end of file diff --git a/.config/nvim/after/ftplugin/lex.lua b/.config/nvim/after/ftplugin/lex.lua deleted file mode 100644 index 7f8d336..0000000 --- a/.config/nvim/after/ftplugin/lex.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lib = require('mango.lib') - -lib.set_tab_width(4, true) diff --git a/.config/nvim/after/ftplugin/lua.lua b/.config/nvim/after/ftplugin/lua.lua deleted file mode 100644 index 7f8d336..0000000 --- a/.config/nvim/after/ftplugin/lua.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lib = require('mango.lib') - -lib.set_tab_width(4, true) diff --git a/.config/nvim/after/ftplugin/mail.lua b/.config/nvim/after/ftplugin/mail.lua index 599950a..72f99e9 100644 --- a/.config/nvim/after/ftplugin/mail.lua +++ b/.config/nvim/after/ftplugin/mail.lua @@ -1,5 +1,2 @@ -local lib = require('mango.lib') - -lib.set_tab_width(2, true) -vim.opt_local.expandtab = true -vim.opt_local.textwidth = 73 +vim.bo.expandtab = true +vim.bo.textwidth = 73 diff --git a/.config/nvim/after/ftplugin/make.lua b/.config/nvim/after/ftplugin/make.lua deleted file mode 100644 index 01efc8f..0000000 --- a/.config/nvim/after/ftplugin/make.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lib = require('mango.lib') - -lib.set_tab_width(8, true) diff --git a/.config/nvim/after/ftplugin/markdown.lua b/.config/nvim/after/ftplugin/markdown.lua index 1b0dfd2..3469231 100644 --- a/.config/nvim/after/ftplugin/markdown.lua +++ b/.config/nvim/after/ftplugin/markdown.lua @@ -1,2 +1,2 @@ -vim.opt_local.textwidth = 80 -vim.opt_local.expandtab = true +vim.bo.expandtab = true +vim.bo.textwidth = 80 diff --git a/.config/nvim/after/ftplugin/nroff.lua b/.config/nvim/after/ftplugin/nroff.lua index 484a35d..1532c29 100644 --- a/.config/nvim/after/ftplugin/nroff.lua +++ b/.config/nvim/after/ftplugin/nroff.lua @@ -1 +1 @@ -vim.opt_local.textwidth = 73 +vim.bo.textwidth = 73 diff --git a/.config/nvim/after/ftplugin/python.lua b/.config/nvim/after/ftplugin/python.lua index a97fe2e..c37615b 100644 --- a/.config/nvim/after/ftplugin/python.lua +++ b/.config/nvim/after/ftplugin/python.lua @@ -1,2 +1 @@ -vim.opt_local.textwidth = 100 -vim.opt_local.expandtab = false +vim.bo.expandtab = false diff --git a/.config/nvim/after/ftplugin/query.lua b/.config/nvim/after/ftplugin/query.lua index 9aa3038..21934e4 100644 --- a/.config/nvim/after/ftplugin/query.lua +++ b/.config/nvim/after/ftplugin/query.lua @@ -1 +1 @@ -vim.opt_local.expandtab = true +vim.bo.expandtab = true diff --git a/.config/nvim/after/ftplugin/rust.lua b/.config/nvim/after/ftplugin/rust.lua deleted file mode 100644 index a97fe2e..0000000 --- a/.config/nvim/after/ftplugin/rust.lua +++ /dev/null @@ -1,2 +0,0 @@ -vim.opt_local.textwidth = 100 -vim.opt_local.expandtab = false 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) diff --git a/.config/nvim/after/syntax/c.vim b/.config/nvim/after/syntax/c.vim deleted file mode 100644 index a2c7c43..0000000 --- a/.config/nvim/after/syntax/c.vim +++ /dev/null @@ -1 +0,0 @@ -hi link @lsp.type.macro Macro diff --git a/.config/nvim/after/syntax/diff.vim b/.config/nvim/after/syntax/diff.vim deleted file mode 100644 index e086592..0000000 --- a/.config/nvim/after/syntax/diff.vim +++ /dev/null @@ -1,3 +0,0 @@ -hi link @text.diff.add DiffAdd -hi link @text.diff.delete DiffDelete -hi link @attribute diffLine diff --git a/.config/nvim/after/syntax/yacc.vim b/.config/nvim/after/syntax/yacc.vim deleted file mode 100644 index fe6603e..0000000 --- a/.config/nvim/after/syntax/yacc.vim +++ /dev/null @@ -1,5 +0,0 @@ -syn match yaccDefines '^%\(debug\|header\|output\)\>' -syn match yaccKey '^\s*%\(nterm\|precedence\)\>' contained -syn match yaccType '<[a-zA-Z_][a-zA-Z0-9_]*\s*\*>' contains=yaccBrkt contained -syn match yaccString '"[^"]*"' contained -syn match yaccVar '@\(\$\|\d\+\)' containedin=cParen,cPreProc,cMulti contained diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index dfea4db..a11639f 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1 +1,479 @@ -require('mango') +vim.g.have_nerd_font = false +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' +vim.g.netrw_banner = 0 +vim.g.netrw_bufsettings = 'noma nomod nu nobl nowrap ro' +vim.g.netrw_list_hide = [[^\(\.\|\.\.\)/\?$,^__pycache__/\?,.*\.\(a\|o\|so\|pyc\)$]] + +-- NOTE: :help option-list +vim.opt.backup = false +vim.opt.breakindent = true +vim.opt.cursorline = true +vim.opt.expandtab = false +vim.opt.exrc = true +vim.opt.grepprg = 'rg --vimgrep -uu' +vim.opt.hlsearch = true +vim.opt.ignorecase = true +vim.opt.inccommand = 'split' +vim.opt.list = false +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +vim.opt.matchpairs:append('<:>') +vim.opt.matchpairs:append('‘:’') +vim.opt.matchpairs:append('“:”') +vim.opt.mouse = 'a' +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.scrolloff = 8 +vim.opt.secure = true +vim.opt.shiftwidth = 4 +vim.opt.showmode = false +vim.opt.signcolumn = 'no' +vim.opt.smartcase = true +vim.opt.smartindent = true +vim.opt.softtabstop = 4 +vim.opt.splitbelow = true +vim.opt.splitright = true +vim.opt.swapfile = false +vim.opt.tabstop = 4 +vim.opt.undodir = os.getenv('XDG_STATE_HOME') .. '/nvim/undo' +vim.opt.undofile = true + +function mk_scratch_buffer() + vim.cmd [[ + if bufexists('scratch') + buffer scratch + else + noswapfile hide enew + setlocal buftype=nofile bufhidden=hide + file scratch + endif + ]] +end + +vim.keymap.set('n', '', '', + { desc = 'Move focus to the left window' }) +vim.keymap.set('n', '', '', + { desc = 'Move focus to the lower window' }) +vim.keymap.set('n', '', '', + { desc = 'Move focus to the upper window' }) +vim.keymap.set('n', '', '', + { desc = 'Move focus to the right window' }) +vim.keymap.set('n', '', 'V', + { desc = 'Enter visual-line mode' }) +vim.keymap.set('n', 'h', function() vim.cmd 'split' end, + { desc = 'Open a [H]orizontal split' }) +vim.keymap.set('n', 'v', function() vim.cmd 'vsplit' end, + { desc = 'Open a [V]ertical split' }) +vim.keymap.set('n', 'M', ':make', + { desc = 'Run the configured compiler' }) +vim.keymap.set('n', 'V', '', + { desc = 'Enter visual-block mode' }) +vim.keymap.set('v', '', ":m '>+1gv=gv", + { desc = 'Move a selection down a line' }) +vim.keymap.set('v', '', ":m '<-2gv=gv", + { desc = 'Move a selection up a line' }) +vim.keymap.set({ 'n', 'o', 'x' }, '€', '$', + { desc = 'Go to end of the line' }) +vim.keymap.set('n', '', 'nohlsearch', + { desc = 'Disable highlighting of currently highlighted search matches' }) +vim.keymap.set('n', 't', function() vim.cmd.normal('"zx"zph') end, + { desc = '[T]ranspose the current and next characters' }) +vim.keymap.set('n', 'T', function() vim.cmd.normal('"zX"zp') end, + { desc = '[T]ranspose the current and previous characters' }) +vim.keymap.set('n', '-', ':Ex', + { desc = 'Open Netrw' }) + +vim.keymap.set('n', 'k', function() + vim.cmd 'vsplit' + mk_scratch_buffer() +end, { desc = 'Open the scratch buffer in a vertical split' }) +vim.keymap.set('n', 'K', function() + vim.cmd 'split' + mk_scratch_buffer() +end, { desc = 'Open the scratch buffer in a horizontal split' }) + +-- Don’t move the cursor with various commands +vim.keymap.set('n', 'J', 'mzJ`z') +vim.keymap.set('n', '', 'zz') +vim.keymap.set('n', '', 'zz') +vim.keymap.set('n', 'n', 'nzzzv') +vim.keymap.set('n', 'N', 'Nzzzv') + +vim.api.nvim_create_autocmd('BufEnter', { + desc = 'Disable auto-commenting', + group = vim.api.nvim_create_augroup('mango-no-autocomment', { clear = true }), + callback = function() + vim.opt.formatoptions:remove({ 'c', 'r', 'o' }) + end, +}) + +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Momentarily highlight yanked text', + group = vim.api.nvim_create_augroup('mango-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, +}) + +-- Weird way to make buffer auto-reverting work? +vim.cmd [[ + if !exists('g:CheckUpdateStarted') + let g:CheckUpdatedStarted = 1 + call timer_start(1000, 'CheckUpdate', {'repeat': -1}) + endif + + function! CheckUpdate(_) + silent! checktime + endfunction +]] + +-- Bootstrap Paq +local paqpath = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim' +if not vim.uv.fs_stat(paqpath) then + vim.fn.system({ + 'git', 'clone', '--depth=1', + 'https://github.com/savq/paq-nvim.git', + paqpath + }) +end + +require 'paq' { + 'christoomey/vim-sort-motion', + 'echasnovski/mini.nvim', + 'folke/todo-comments.nvim', + 'folke/tokyonight.nvim', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + 'hrsh7th/nvim-cmp', + 'https://git.sr.ht/~mango/tree-sitter-gsp', + 'kylechui/nvim-surround', + 'L3MON4D3/LuaSnip', + 'luckasRanarison/tree-sitter-hypr', + 'mattn/emmet-vim', + 'neovim/nvim-lspconfig', + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope.nvim', + 'nvim-telescope/telescope-ui-select.nvim', + { 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate' }, + 'nvim-treesitter/nvim-treesitter-textobjects', + 'saadparwaiz1/cmp_luasnip', + 'savq/paq-nvim', + 'wellle/targets.vim', +} + +-- emmet-vim +vim.g.user_emmet_install = false + +-- vim-sort-motion +vim.g.sort_motion_flags = 'l' + +-- tokyonight.nvim +vim.cmd.colorscheme 'tokyonight-night' + +-- telescope.nvim +local telescope = require 'telescope' +local tsactions = require 'telescope.actions' +local tsbuiltin = require 'telescope.builtin' +local tsthemes = require 'telescope.themes' + +telescope.setup { + defaults = { + scroll_strategy = 'limit', + path_display = { 'filename_first' }, + get_status_text = function(_) return '' end, + mappings = { + i = { + [''] = { + tsactions.close, + type = 'action', + opts = { nowait = true, silent = true }, + }, + [''] = { + tsactions.move_selection_next, + type = 'action', + opts = { nowait = true, silent = true }, + }, + [''] = { + tsactions.move_selection_previous, + type = 'action', + opts = { nowait = true, silent = true }, + }, + }, + }, + }, + extensions = { + ['ui-select'] = { tsthemes.get_dropdown() }, + } +} + +pcall(telescope.load_exetension, 'fzf') +pcall(telescope.load_exetension, 'ui-select') + +vim.keymap.set('n', 'ff', tsbuiltin.find_files, + { desc = '[F]ind [F]iles' }) +vim.keymap.set('n', 'fh', tsbuiltin.help_tags, + { desc = '[F]ind [H]elp' }) +vim.keymap.set('n', 'fg', tsbuiltin.live_grep, + { desc = '[F]ind [G]rep' }) +vim.keymap.set('n', '/', function() + tsbuiltin.current_buffer_fuzzy_find(tsthemes.get_dropdown { + winblend = 10, + previewer = false, + }) +end, { desc = 'Fuzzily search in current buffer' }) + +-- todo-comments.nvim +require('todo-comments').setup { + signs = false, + keywords = { + TODO = { color = 'info' }, + NOTE = { color = 'hint' }, + }, + highlight = { + before = '', + keyword = 'fg', + after = '', + }, +} + +-- mini.nvim +local statusline = require 'mini.statusline' +statusline.setup { use_icons = false } +statusline.section_location = function() return '%2l:%-2v' end + +-- nvim-treesitter +local treeconfs = require('nvim-treesitter.parsers').get_parser_configs() +treeconfs.gsp = { + install_info = { + url = 'https://git.sr.ht/~mango/tree-sitter-gsp', + files = { 'src/parser.c' }, + }, + filetype = 'gsp', +} + +require('nvim-treesitter.install').prefer_git = true +require('nvim-treesitter.configs').setup { + auto_install = true, + sync_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', + }, + }, + }, +} + +-- nvim-surround +require('nvim-surround').setup { + surrounds = { + ['’'] = { + add = { '‘', '’' }, + find = '‘[^‘’]*’', + delete = '^(‘)().-(’)()$', + }, + + ['‘'] = { + add = { '‘ ', ' ’' }, + find = '‘[^‘’]*’', + delete = '^(‘ *)().-( *’)()$', + }, + + ['”'] = { + add = { '“', '”' }, + find = '“[^“”]*”', + delete = '^(“)().-(”)()$', + }, + + ['“'] = { + add = { '“ ', ' ”' }, + find = '“[^“”]*”', + delete = '^(“ *)().-( *”)()$', + }, + } +} + +-- nvim-lspconfig +local lsp = require 'lspconfig' +local caps = require('cmp_nvim_lsp').default_capabilities() + +lsp.clangd.setup { + cmd = { 'clangd', '-header-insertion=never' }, + capabilities = caps, +} +lsp.gopls.setup { + capabilities = caps, +} +lsp.rust_analyzer.setup { + capabilities = caps, +} +lsp.lua_ls.setup { + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = { + 'vim', + 'require', + }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file('', true), + }, + telemetry = { + enable = false, + }, + }, + }, + capabilities = caps, +} + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('mango-lsp-config', { clear = true }), + 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' + vim.keymap.set('n', 'gK', vim.lsp.buf.hover, + { buffer = ev.buf, desc = 'View symbol hover information' }) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, + { buffer = ev.buf, desc = 'Goto [D]efinition' }) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, + { buffer = ev.buf, desc = 'Goto [I]mplementation' }) + vim.keymap.set('n', 'gr', vim.lsp.buf.rename, + { buffer = ev.buf, desc = '[R]ename symbol' }) + vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, + { buffer = ev.buf, desc = 'Goto [T]ype definition' }) + end, +}) + +-- nvim-cmp & luasnip +local cmp = require 'cmp' +local luasnip = require 'luasnip' + +luasnip.config.setup { + history = true, + updateevents = 'TextChanged,TextChangedI', +} +require 'snippets' + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { completeopt = 'menu,menuone,noinsert' }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.scroll_docs(-1), + [''] = cmp.mapping.scroll_docs(1), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.select_next_item({ + behaviour = cmp.SelectBehavior.Select, + }), + [''] = cmp.mapping.select_prev_item({ + behaviour = cmp.SelectBehavior.Select, + }), + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, {'i', 's'}), + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable(-1) then + luasnip.expand_or_jump(-1) + end + end, {'i', 's'}), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, + experimental = { + ghost_text = true, + }, +} +-- cmp.event:on('confirm_done', function(ev) +-- if ev.commit_character then +-- return +-- end +-- +-- local types = require 'cmp.types' +-- local kind = ev.entry:get_kind() +-- +-- if +-- kind == types.lsp.CompletionItemKind.Function or +-- kind == types.lsp.CompletionItemKind.Method +-- then +-- local keys = vim.api.nvim_replace_termcodes('()', true, false, true) +-- vim.api.nvim_feedkeys(keys, 'i', false) +-- end +-- end) + +require('pipe') diff --git a/.config/nvim/lua/mango/init.lua b/.config/nvim/lua/mango/init.lua deleted file mode 100644 index 9e7f273..0000000 --- a/.config/nvim/lua/mango/init.lua +++ /dev/null @@ -1,3 +0,0 @@ -require('mango.packer') -require('mango.remap') -require('mango.set') diff --git a/.config/nvim/lua/mango/lib.lua b/.config/nvim/lua/mango/lib.lua deleted file mode 100644 index e062352..0000000 --- a/.config/nvim/lua/mango/lib.lua +++ /dev/null @@ -1,36 +0,0 @@ -local M = {} - -function M.set_tab_width(tw, localp) - local opt = localp and vim.opt_local or vim.opt - - opt.tabstop = tw - opt.softtabstop = tw - opt.shiftwidth = tw -end - -function M.remap(modes, from, to, opts) - local ct = {} - - modes:gsub('.', function(c) - table.insert(ct, c) - end) - - vim.keymap.set(ct, from, to, opts or { - noremap = true, - silent = true, - }) -end - -function M.scratch_buffer() - vim.cmd [[ - if bufexists('scratch') - buffer scratch - else - noswapfile hide enew - setlocal buftype=nofile bufhidden=hide - file scratch - endif - ]] -end - -return M diff --git a/.config/nvim/lua/mango/packer.lua b/.config/nvim/lua/mango/packer.lua deleted file mode 100644 index 8b5c583..0000000 --- a/.config/nvim/lua/mango/packer.lua +++ /dev/null @@ -1,59 +0,0 @@ -vim.cmd.packadd('packer.nvim') - -return require('packer').startup(function(use) - -- Package manager - use 'wbthomason/packer.nvim' - - -- Colorscheme - use { - 'rose-pine/neovim', - as = 'rose-pine', - } - - -- More textobjects; more is more - use 'wellle/targets.vim' - use { - 'nvim-treesitter/nvim-treesitter-textobjects', - after = 'nvim-treesitter', - requires = 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate', - } - - -- Efficiency improvements - use 'kylechui/nvim-surround' - use 'mattn/emmet-vim' - use 'numToStr/Comment.nvim' - use 'christoomey/vim-sort-motion' - - -- Git integration - use 'tpope/vim-fugitive' - - -- Improvements to builtin functionality - use 'mbbill/undotree' - use 'tpope/vim-speeddating' - - -- Additional language support - use 'Glench/Vim-Jinja2-Syntax' - use 'https://git.sr.ht/~mango/tree-sitter-gsp' - use 'luckasRanarison/tree-sitter-hypr' - - -- LSP support and completions - use 'neovim/nvim-lspconfig' - use { - 'hrsh7th/nvim-cmp', - requires = { - -- Completion backends - { 'hrsh7th/cmp-buffer' }, - { 'hrsh7th/cmp-nvim-lua' }, - { 'hrsh7th/cmp-nvim-lsp' }, - { 'hrsh7th/cmp-path' }, - - -- Snippets - { 'L3MON4D3/LuaSnip' }, - { 'saadparwaiz1/cmp_luasnip' }, - }, - } - - -- Function context - use 'nvim-treesitter/nvim-treesitter-context' -end) diff --git a/.config/nvim/lua/mango/remap.lua b/.config/nvim/lua/mango/remap.lua deleted file mode 100644 index a22632e..0000000 --- a/.config/nvim/lua/mango/remap.lua +++ /dev/null @@ -1,54 +0,0 @@ -local lib = require('mango.lib') -local remap = lib.remap - -vim.g.mapleader = ' ' - --- Make adjustments for my custom keyboard layout -remap('nov', '€', '$') - --- Better frame navigation -remap('n', '', 'h') -remap('n', '', 'j') -remap('n', '', 'k') -remap('n', '', 'l') - --- I prefer visual-line mode on ‘V’ -remap('n', 'V', '') -remap('n', '', 'V') - --- Move selections up and down -remap('v', '', ":m '<-2gv=gv") -remap('v', '', ":m '>+1gv=gv") - --- Don’t move cursor with various commands -remap('n', 'J', 'mzJ`z') -remap('n', '', 'zz') -remap('n', '', 'zz') -remap('n', 'n', 'nzzzv') -remap('n', 'N', 'Nzzzv') - --- Compile code quickly -remap('n', 'M', ':make') - --- Transpose characters; for some reason it has a noticable delay if I just give --- a string instead of lambda functions -remap('n', 't', function() vim.cmd.normal('"zx"zp') end) -remap('n', 'T', function() vim.cmd.normal('"zX"zp') end) - --- Open netrw quickly -remap('n', '-', ':Ex') - --- Open netrw in a vertical- or horizontal split. The split is made manually --- instead of by using :Vexplore or :Sexplore so that it’s made on the right or --- bottom instead of the left or top -remap('n', '–', ':vsplit | Ex') -remap('n', 'g–', ':split | Ex') - -remap('n', 's', function() - vim.cmd('vsplit') - lib.scratch_buffer() -end) -remap('n', 'S', function() - vim.cmd('split') - lib.scratch_buffer() -end) diff --git a/.config/nvim/lua/mango/set.lua b/.config/nvim/lua/mango/set.lua deleted file mode 100644 index 6b92625..0000000 --- a/.config/nvim/lua/mango/set.lua +++ /dev/null @@ -1,72 +0,0 @@ -local lib = require('mango.lib') -local api = vim.api - -local o = vim.opt -local g = vim.g - -local augroup = api.nvim_create_augroup('Mango', { clear = true }) - -o.nu = true -o.relativenumber = true -o.signcolumn = 'no' -o.colorcolumn = '81' - -o.exrc = true -o.secure = true - -g.guifont = { 'Iosevka Smooth Term', ':h16' } - -lib.set_tab_width(4) -o.expandtab = false -o.smartindent = true - -o.wrap = false - -o.swapfile = false -o.backup = false -o.undodir = os.getenv('XDG_STATE_HOME') .. '/nvim/undo' -o.undofile = true - -o.hlsearch = true -o.incsearch = true - -o.termguicolors = true - -o.scrolloff = 8 - -o.isfname:append('@-@') - -o.splitright = true -o.splitbelow = true - --- Better settings for netrw -g.netrw_banner = 0 -g.netrw_bufsettings = 'noma nomod nu nobl nowrap ro' -- Enable line-numbers -g.netrw_list_hide = [[^\(\.\|\.\.\)/\?$,^__pycache__/\?,.*\.\(o\|pyc\)$]] - -vim.cmd [[ set grepprg=rg\ --vimgrep ]] - --- Disable auto commenting -api.nvim_create_autocmd('BufEnter', { - callback = function() - o.formatoptions:remove({ 'c', 'r', 'o' }) - end, - group = augroup, -}) - --- Make buffer auto-reverting work… somehow -vim.cmd([[ - if !exists('g:CheckUpdateStarted') - let g:CheckUpdateStarted = 1 - call timer_start(1000, 'CheckUpdate', {'repeat': -1}) - endif - - function! CheckUpdate(_) - silent! checktime - endfunction -]]) - --- Allow for jumping between these pairs with % -o.matchpairs:append('<:>') -o.matchpairs:append('‘:’') -o.matchpairs:append('“:”') diff --git a/.config/nvim/lua/pipe.lua b/.config/nvim/lua/pipe.lua new file mode 100644 index 0000000..f09a030 --- /dev/null +++ b/.config/nvim/lua/pipe.lua @@ -0,0 +1,42 @@ +function pipe_visual() + pipe_internal({'<', '>'}, vim.fn.visualmode() ~= 'v') +end + +function pipe_normal(arg) + pipe_internal({'[', ']'}, arg == 'line') +end + +function pipe_internal(marks, linesp) + local mode = vim.fn.visualmode() + + local sr, sc = unpack(vim.api.nvim_buf_get_mark(0, marks[1])) + local er, ec = unpack(vim.api.nvim_buf_get_mark(0, marks[2])) + + local lines = linesp + and vim.api.nvim_buf_get_lines(0, sr - 1, er, true) + or vim.api.nvim_buf_get_text(0, sr - 1, sc, er - 1, ec + 1, {}) + + local ok, cmd = pcall(vim.fn.input, { + prompt = '… | ', + cancelreturn = vim.NIL, + }) + + if not ok or cmd == vim.NIL then + return + end + + local out = vim.fn.systemlist(cmd, lines) + if linesp then + vim.api.nvim_buf_set_lines(0, sr - 1, er, true, out) + else + vim.api.nvim_buf_set_text(0, sr - 1, sc, er - 1, ec + 1, out) + end +end + +vim.keymap.set('n', 'PipeNormal', ':set opfunc=v:lua.pipe_normalg@', + { silent = true }) +vim.keymap.set('x', 'PipeVisual', ':lua pipe_visual()', + { silent = true }) + +vim.keymap.set('n', '|', 'PipeNormal') +vim.keymap.set('x', '|', 'PipeVisual') diff --git a/.config/nvim/lua/snippets.lua b/.config/nvim/lua/snippets.lua new file mode 100644 index 0000000..db46bf4 --- /dev/null +++ b/.config/nvim/lua/snippets.lua @@ -0,0 +1,176 @@ +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.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), } + ) + ), +}) -- cgit v1.2.3