diff options
Diffstat (limited to '.config/nvim/lua')
-rw-r--r-- | .config/nvim/lua/mango/init.lua | 3 | ||||
-rw-r--r-- | .config/nvim/lua/mango/lib.lua | 36 | ||||
-rw-r--r-- | .config/nvim/lua/mango/packer.lua | 59 | ||||
-rw-r--r-- | .config/nvim/lua/mango/remap.lua | 54 | ||||
-rw-r--r-- | .config/nvim/lua/mango/set.lua | 72 | ||||
-rw-r--r-- | .config/nvim/lua/pipe.lua | 42 | ||||
-rw-r--r-- | .config/nvim/lua/snippets.lua | 176 |
7 files changed, 218 insertions, 224 deletions
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', '<C-h>', '<C-w>h') -remap('n', '<C-j>', '<C-w>j') -remap('n', '<C-k>', '<C-w>k') -remap('n', '<C-l>', '<C-w>l') - --- I prefer visual-line mode on ‘V’ -remap('n', 'V', '<C-v>') -remap('n', '<C-v>', 'V') - --- Move selections up and down -remap('v', '<C-k>', ":m '<-2<CR>gv=gv") -remap('v', '<C-j>', ":m '>+1<CR>gv=gv") - --- Don’t move cursor with various commands -remap('n', 'J', 'mzJ`z') -remap('n', '<C-d>', '<C-d>zz') -remap('n', '<C-u>', '<C-u>zz') -remap('n', 'n', 'nzzzv') -remap('n', 'N', 'Nzzzv') - --- Compile code quickly -remap('n', 'M', ':make<CR>') - --- Transpose characters; for some reason it has a noticable delay if I just give --- a string instead of lambda functions -remap('n', '<leader>t', function() vim.cmd.normal('"zx"zp') end) -remap('n', '<leader>T', function() vim.cmd.normal('"zX"zp') end) - --- Open netrw quickly -remap('n', '-', ':Ex<CR>') - --- 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<CR>') -remap('n', 'g–', ':split | Ex<CR>') - -remap('n', '<leader>s', function() - vim.cmd('vsplit') - lib.scratch_buffer() -end) -remap('n', '<leader>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', '<Plug>PipeNormal', ':set opfunc=v:lua.pipe_normal<CR>g@', + { silent = true }) +vim.keymap.set('x', '<Plug>PipeVisual', ':<C-u>lua pipe_visual()<CR>', + { silent = true }) + +vim.keymap.set('n', '|', '<Plug>PipeNormal') +vim.keymap.set('x', '|', '<Plug>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), } + ) + ), +}) |