diff options
Diffstat (limited to 'after/ftplugin')
-rw-r--r-- | after/ftplugin/markdown.lua | 32 |
1 files changed, 32 insertions, 0 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 }) |