diff options
-rw-r--r-- | after/ftplugin/markdown.lua | 32 | ||||
-rw-r--r-- | ftplugin/markdown.lua | 6 |
2 files changed, 32 insertions, 6 deletions
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 }) diff --git a/ftplugin/markdown.lua b/ftplugin/markdown.lua deleted file mode 100644 index 162ff13..0000000 --- a/ftplugin/markdown.lua +++ /dev/null @@ -1,6 +0,0 @@ -local l = vim.opt_local - -l.formatprg = "par -w 80" -l.conceallevel = 0 -l.wrap = true -l.spell = true |