From 3f7563540e835b39982e8316cb1d7cdbd443ad14 Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Fri, 17 Jan 2025 20:33:14 +0100 Subject: ftplugin/markdown: lots of changes - move from ftplugin to after/ftplugin - add keywordprg to lookup words in the dictionary --- after/ftplugin/markdown.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 after/ftplugin/markdown.lua (limited to 'after/ftplugin') diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua new file mode 100644 index 0000000..ac4a84e --- /dev/null +++ b/after/ftplugin/markdown.lua @@ -0,0 +1,32 @@ +local l = vim.opt_local + +l.keywordprg = ":MarkdownDictLookup" -- open dictionary for word under cursor + -- with K + +l.formatprg = "par -w 80" -- to format paragraphs with gq +l.textwidth = 80 -- wrap at 80 characters +l.wrap = true -- autowrap at 👆 +l.spell = true -- enable spell checking + +l.conceallevel = 2 -- conceal by default + +-- change conceallevel depending on the mode and never conceal in Insert mode +vim.api.nvim_create_autocmd({ "InsertEnter" }, { + pattern = { "*.{markdown,md}" }, + callback = function(_) l.conceallevel = 0 end, +}) + +vim.api.nvim_create_autocmd({ "InsertLeave" }, { + pattern = { "*.{markdown,md}" }, + callback = function(_) l.conceallevel = 2 end, +}) + +-- The custom user command used by keywordprg. I need this because vim insers a +-- space between keywordprg and the actual word. That is, to lookup 'foo', it +-- would run "open dict:// foo" which obviously won't work. There's no way to +-- make keywordprg take a lua fn, but it takes an Ex command like this just +-- fine. +-- Took the idea from https://vi.stackexchange.com/questions/36890/how-to-set-keywordprg-to-call-a-lua-function-in-neovim +vim.api.nvim_buf_create_user_command(0, "MarkdownDictLookup", function(opts) + vim.fn.system("open dict://" .. opts.args) +end, { nargs = 1 }) -- cgit v1.2.3