-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from shiradofu/feat/add-config-for-commentary-…
…maps
- Loading branch information
Showing
3 changed files
with
54 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 46 additions & 7 deletions
53
lua/ts_context_commentstring/integrations/vim_commentary.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,54 @@ | ||
local map = vim.api.nvim_buf_set_keymap | ||
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() | ||
map(0, 'n', 'gc', [[v:lua.context_commentstring.update_commentstring_and_run('Commentary')]], { expr = true }) | ||
map(0, 'x', 'gc', [[v:lua.context_commentstring.update_commentstring_and_run('Commentary')]], { expr = true }) | ||
map(0, 'o', 'gc', [[v:lua.context_commentstring.update_commentstring_and_run('Commentary')]], { expr = true }) | ||
map(0, 'n', 'gcc', [[v:lua.context_commentstring.update_commentstring_and_run('CommentaryLine')]], { expr = true }) | ||
map(0, 'n', 'cgc', [[v:lua.context_commentstring.update_commentstring_and_run('ChangeCommentary')]], { expr = true }) | ||
function M.set_up_maps(maps) | ||
maps = (maps and type(maps) == 'table') and maps or {} | ||
maps = vim.tbl_extend('force', { | ||
Commentary = 'gc', | ||
CommentaryLine = 'gcc', | ||
ChangeCommentary = 'cgc', | ||
CommentaryUndo = 'gcu', | ||
}, maps) | ||
|
||
if maps.Commentary then | ||
for _, mode in ipairs { 'n', 'x', 'o' } do | ||
bmap(0, mode, maps.Commentary, '<Plug>ContextCommentary', {}) | ||
end | ||
end | ||
if maps.CommentaryLine then | ||
bmap(0, 'n', maps.CommentaryLine, '<Plug>ContextCommentaryLine', {}) | ||
end | ||
if maps.ChangeCommentary then | ||
bmap(0, 'n', maps.ChangeCommentary, '<Plug>ContextChangeCommentary', {}) | ||
end | ||
if maps.CommentaryUndo then | ||
bmap(0, 'n', maps.CommentaryUndo, '<Plug>ContextCommentary<Plug>Commentary', {}) | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters