Skip to content

Commit

Permalink
Move global mapping definitons
Browse files Browse the repository at this point in the history
make global mappings defined only once
  • Loading branch information
shiradofu committed Aug 4, 2022
1 parent 54b9a93 commit 31ac30f
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lua/ts_context_commentstring/integrations/vim_commentary.lua
Original file line number Diff line number Diff line change
@@ -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,
'<Plug>ContextCommentary',
[[v:lua.context_commentstring.update_commentstring_and_run('Commentary')]],
{ expr = true }
)
end
gmap(
'n',
'<Plug>ContextCommentaryLine',
[[v:lua.context_commentstring.update_commentstring_and_run('CommentaryLine')]],
{ expr = true }
)
gmap(
'n',
'<Plug>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,
'<Plug>ContextCommentary',
[[v:lua.context_commentstring.update_commentstring_and_run('Commentary')]],
{ expr = true }
)
end
gmap(
'n',
'<Plug>ContextCommentaryLine',
[[v:lua.context_commentstring.update_commentstring_and_run('CommentaryLine')]],
{ expr = true }
)
gmap(
'n',
'<Plug>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',
Expand Down

0 comments on commit 31ac30f

Please sign in to comment.