nvim-config

Log | Files | Refs | Submodules | README

commit a54acb3778f42dd72ab30d9fc351a2d5dbb556ed
parent 60acc2b95e2292c1de30d338dfdf0e55c454a72e
Author: Thomas Vigouroux <me@vigoux.eu>
Date:   Mon, 11 Mar 2024 16:53:39 +0100

refactor: better mappings namespacing

Diffstat:
Mafter/ftplugin/tex.lua | 3+--
Minit.lua | 2+-
Mlua/mappings.lua | 25++++++++++++++++---------
3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/after/ftplugin/tex.lua b/after/ftplugin/tex.lua @@ -16,8 +16,7 @@ end MiniPairs.map_buf(0, 'i', '$', { action = 'closeopen', pair = '$$', register = { cr = false } }) -- XXX: when calling map_buf, it resets the mapping for `<CR>` and `<BS>`, so we need to reset them -vim.api.nvim_buf_set_keymap(0, 'i', '<CR>', '', { callback = cr_confirm }) -vim.api.nvim_buf_set_keymap(0, 'i', '<BS>', '', { callback = backspace }) +require "mappings".set_mappings() local edit = require "architext.edit" local utls = require "mytsutils" diff --git a/init.lua b/init.lua @@ -107,7 +107,7 @@ vim.cmd [[language en_US.utf8]] vim.cmd [[language time POSIX]] -- Now load plugins and such -require "mappings" +require "mappings".set_mappings() require "neogit-config" -- Set up some useful diagnostics stuff diff --git a/lua/mappings.lua b/lua/mappings.lua @@ -1,7 +1,8 @@ -- Completion and so on +local M = {} require "completree-config" local complementree = require 'complementree' -local mpairs = require'mini.pairs' +local mpairs = require 'mini.pairs' -- local snippy = require 'snippy' -- local luasnip = require 'luasnip' local rt = function(codes) @@ -26,7 +27,7 @@ local function sjump() end) end -function tab_complete() +local function tab() if vim.fn.pumvisible() == 1 then return feed '<C-N>' elseif vim.api.nvim_get_current_line():sub(1, vim.fn.getcurpos()[3] - 1):match("^%s*$") then @@ -39,7 +40,7 @@ function tab_complete() end end -function cr_confirm() +local function cr() if vim.fn.pumvisible() == 1 then feed '<C-Y>' -- sjump() @@ -48,7 +49,7 @@ function cr_confirm() end end -function backspace() +local function bs() local pumvisible = vim.fn.pumvisible() -- feed(mpairs.bs()) vim.api.nvim_feedkeys(mpairs.bs(), 'n', true) @@ -59,11 +60,15 @@ function backspace() end) end -vim.keymap.set('i', '<CR>', cr_confirm, { noremap = true }) +function M.set_mappings() + vim.keymap.set('i', '<CR>', cr, { noremap = true }) -vim.keymap.set({'i', 's'}, '<Tab>', tab_complete) -vim.keymap.set({'i', 's'}, '<BS>', backspace) -vim.keymap.set({'i', 's'}, '<C-l>', function() vim.snippet.jump(1) end) + vim.keymap.set({ 'i', 's' }, '<Tab>', tab) + + vim.keymap.set({ 'i', 's' }, '<BS>', bs) + + vim.keymap.set({ 'i', 's' }, '<C-l>', function() vim.snippet.jump(1) end) +end --- Tiny mapping to select the node at cursor and input it do @@ -71,7 +76,7 @@ do local node = vim.treesitter.get_node() if not node then return end - local types = {} ---@type string[] + local types = {} ---@type string[] repeat types[#types + 1] = node:type() node = node:parent() @@ -79,3 +84,5 @@ do vim.api.nvim_input(types[1]) end) end + +return M