kommentary icon indicating copy to clipboard operation
kommentary copied to clipboard

Expose Lua API directly

Open mrjones2014 opened this issue 2 years ago • 1 comments

Now that we have vim.keymap.set API in Neovim nightly, it allows us to setup keymaps in really clean ways.

I'm using legendary.nvim to set all my keymaps, and I try to keep them all in the same place. I tend to have plugins not set their own keymaps through the plugin config, and instead set the keymaps in my single location where I set up all my keymaps.

You can also now set keymaps directly to Lua functions.

Can you expose the implementations of the <Plug> mappings as Lua functions I can map from my keymaps file?

mrjones2014 avatar Feb 18 '22 13:02 mrjones2014

I'm not sure if this is what you are wanting but I use the following function (found at the bottom of 'lua/kommentary/init.lua') for my custom keymaps:

require('kommentary').toggle_comment(arg1, arg2)

Arg1 is the first line you want commented and arg2 is the last. For example, to toggle comments on the current line I use:

require('kommentary').toggle_comment(vim.fn.line('.'), vim.fn.line('.'))

And to comment a visual selection would be:

require('kommentary').toggle_comment(vim.fn.line('v'), vim.fn.line('.'))

I hope this helped!

declancm avatar Mar 05 '22 08:03 declancm

Hi, thanks for your interest in kommentary, unfortunately I'll not be adding any new features, I'm sorry I never got to this issue.

b3nj5m1n avatar Nov 05 '22 05:11 b3nj5m1n