From 31ac30fc374d860632c7c5b183a2a80796e66aaa Mon Sep 17 00:00:00 2001 From: shiradofu <43514606+shiradofu@users.noreply.github.com> Date: Thu, 4 Aug 2022 23:53:55 +0900 Subject: [PATCH] Move global mapping definitons make global mappings defined only once --- .../integrations/vim_commentary.lua | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lua/ts_context_commentstring/integrations/vim_commentary.lua b/lua/ts_context_commentstring/integrations/vim_commentary.lua index c2d8dbd..c3d3f3f 100644 --- a/lua/ts_context_commentstring/integrations/vim_commentary.lua +++ b/lua/ts_context_commentstring/integrations/vim_commentary.lua @@ -1,32 +1,32 @@ local gmap = vim.api.nvim_set_keymap local bmap = vim.api.nvim_buf_set_keymap +for _, mode in ipairs { 'n', 'x', 'o' } do + gmap( + mode, + 'ContextCommentary', + [[v:lua.context_commentstring.update_commentstring_and_run('Commentary')]], + { expr = true } + ) +end +gmap( + 'n', + 'ContextCommentaryLine', + [[v:lua.context_commentstring.update_commentstring_and_run('CommentaryLine')]], + { expr = true } +) +gmap( + 'n', + 'ContextChangeCommentary', + [[v:lua.context_commentstring.update_commentstring_and_run('ChangeCommentary')]], + { expr = true } +) + local M = {} ---Set up vim-commentary mappings to first update the commentstring, and then ---run vim-commentary function M.set_up_maps(maps) - for _, mode in ipairs { 'n', 'x', 'o' } do - gmap( - mode, - 'ContextCommentary', - [[v:lua.context_commentstring.update_commentstring_and_run('Commentary')]], - { expr = true } - ) - end - gmap( - 'n', - 'ContextCommentaryLine', - [[v:lua.context_commentstring.update_commentstring_and_run('CommentaryLine')]], - { expr = true } - ) - gmap( - 'n', - 'ContextChangeCommentary', - [[v:lua.context_commentstring.update_commentstring_and_run('ChangeCommentary')]], - { expr = true } - ) - maps = (maps and type(maps) == 'table') and maps or {} maps = vim.tbl_extend('force', { Commentary = 'gc',