diff options
author | Christian Segundo | 2025-01-17 20:33:14 +0100 |
---|---|---|
committer | Christian Segundo | 2025-01-17 20:33:14 +0100 |
commit | 3f7563540e835b39982e8316cb1d7cdbd443ad14 (patch) | |
tree | 13f4d5a1ee6e3a090e3b0feff1477f3944164a9e /after | |
parent | 656397b42043b34732812d2b40eeb0216d729c8e (diff) | |
download | config-3f7563540e835b39982e8316cb1d7cdbd443ad14.tar.gz |
ftplugin/markdown: lots of changes
- move from ftplugin to after/ftplugin
- add keywordprg to lookup words in the dictionary
Diffstat (limited to 'after')
-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 }) |