b3nj5m1n/kommentary

Generalize to not rely on <Plug>

Closed this issue · 3 comments

Hi, great plugin! I'm using paq and I'm having a hard time remapping the keys. I'm not sure if that's because the implementation relies on <Plug> or if it's something else.

vim.g.kommentary_create_default_mappings = false
paq 'b3nj5m1n/kommentary'

map("n", "<leader>cc",  "<Plug>kommentary_line_default", {})
map("n", "<leader>c",   "<Plug>kommentary_motion_default", {})
map("v", "<leader>c",   "<Plug>kommentary_visual_default", {})

Really I'm looking for <leader>cc to comment and <leader>cu to uncomment (line and block)

Any help would be greatly appreciated!

What have you tried so far that hasn't worked? I'm pretty sure has nothing to do with your plugin manager.

False alarm...

local function map(mode, lhs, rhs, opts)
  local options = {noremap = true}
  if opts then options = vim.tbl_extend('force', options, opts) end
  vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end

-- doesn't work because the `map` function defaults to noremap = true
map("n", "<leader>cc", "<Plug>kommentary_line_default", {}) 

-- works!
map("n", "<leader>cc", "<Plug>kommentary_line_default", { noremap = false }) 

Why can't this plugin work with noremap instead of map?