markdowny.nvim
markdowny.nvim copied to clipboard
Overriding the default keymaps
Hi! thanks for making this plugin. I like it very much.
I'm trying to replace the default keymap for adding links with <C-l>
. However, I don't think setting a new custom keymap as directed in the readme overrides the default keymap.
If I am doing something wrong, please correct me but if not, I have two suggestions:
- Add an option value to remove the default keymaps
something like this:
-- markdowny.lua
function M.setup(opts)
opts = opts or {}
vim.api.nvim_create_autocmd('FileType', {
desc = 'markdowny.nvim keymaps',
pattern = opts.filetypes or 'markdown',
callback = function()
if opts.remove_keymaps then
return
end
vim.keymap.set('v', '<C-b>', ":lua require('markdowny').bold()<cr>", { buffer = 0 })
vim.keymap.set('v', '<C-i>', ":lua require('markdowny').italic()<cr>", { buffer = 0 })
vim.keymap.set('v', '<C-k>', ":lua require('markdowny').link()<cr>", { buffer = 0 })
end,
})
end
-- init.lua
require("markdowny").setup({ remove_keymaps = true })
- Create commands and let the user bind them to their own keymaps
This would need to use vim.api.nvim_create_user_command
to create a command for each method. The drawback of this is that there will be no default keymaps.
Again, I might be doing something very wrong so let me know if that's the case 😅
Hi and I am glad you enjoy the plugin.
Hello, you are correct. If you have provided remove_keymaps = true
the call for setup
function becomes redundant. This is why it is not reflected in the documentation. I meant to remove it before publishing the plugin. In your case you can create a single vim.api.nvim_create_autocmd
for your custom keymap and the default one. Essentially you can copy paste the snippet of code from your message and edit the keymaps as you wish. Does this work for you?
vim.api.nvim_create_autocmd('FileType', {
pattern = 'markdown',
callback = function()
vim.keymap.set('v', '<C-b>', ":lua require('markdowny').bold()<cr>", { buffer = 0 })
vim.keymap.set('v', '<C-i>', ":lua require('markdowny').italic()<cr>", { buffer = 0 })
vim.keymap.set('v', '<C-k>', ":lua require('markdowny').link()<cr>", { buffer = 0 })
end,
})