summaryrefslogtreecommitdiff
path: root/after/ftplugin/markdown.lua
blob: ac4a84ea13ebc80f76b156711e551c2fe012918c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 })