Created
June 14, 2020 07:34
-
-
Save huytd/668fc018b019fbc49fa1c09101363397 to your computer and use it in GitHub Desktop.
A Todo list syntax in Vim, with an actual checkbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim syntax file | |
" Language: Todo | |
" Maintainer: Huy Tran | |
" Latest Revision: 14 June 2020 | |
if exists("b:current_syntax") | |
finish | |
endif | |
" Custom conceal | |
syntax match todoCheckbox "\[\ \]" conceal cchar= | |
syntax match todoCheckbox "\[x\]" conceal cchar= | |
let b:current_syntax = "todo" | |
hi def link todoCheckbox Todo | |
hi Conceal guibg=NONE | |
setlocal cole=1 |
For users working in neovim, you can put this in your ftplugin/markdown.lua
.
function _G.pcall_markdown_sugar()
vim.cmd([[
augroup markdown
autocmd!
au BufEnter *.md :syn match todoCheckbox '\v(\s+)?(-|\*)\s\[\s\]'hs=e-4 conceal cchar=
au BufEnter *.md :syn match todoCheckbox '\v(\s+)?(-|\*)\s\[x\]'hs=e-4 conceal cchar=
au BufEnter *.md :syn match todoCheckbox '\v(\s+)?(-|\*)\s\[-\]'hs=e-4 conceal cchar=
au BufEnter *.md :syn match todoCheckbox '\v(\s+)?(-|\*)\s\[\.\]'hs=e-4 conceal cchar=⊡
au BufEnter *.md :syn match todoCheckbox '\v(\s+)?(-|\*)\s\[o\]'hs=e-4 conceal cchar=⬕
:hi def link todoCheckbox Todo
:highlight Conceal guibg=NONE guifg=#00cf37
:setlocal conceallevel=1
augroup END
]])
end
pcall_markdown_sugar()
@rohit-kumar-j I took the liberty of improving your code to use the available Neovim Lua APIs:
local function markdown_sugar()
local augroup = vim.api.nvim_create_augroup('markdown', {})
vim.api.nvim_create_autocmd('BufEnter', {
pattern = '*.md',
group = augroup,
callback = function()
vim.api.nvim_set_hl(0, 'Conceal', { bg = 'NONE', fg = '#00cf37' })
vim.api.nvim_set_hl(0, 'todoCheckbox', { link = 'Todo' })
vim.bo.conceallevel = 1
vim.cmd [[
syn match todoCheckbox '\v(\s+)?(-|\*)\s\[\s\]'hs=e-4 conceal cchar=
syn match todoCheckbox '\v(\s+)?(-|\*)\s\[x\]'hs=e-4 conceal cchar=
syn match todoCheckbox '\v(\s+)?(-|\*)\s\[-\]'hs=e-4 conceal cchar=
syn match todoCheckbox '\v(\s+)?(-|\*)\s\[\.\]'hs=e-4 conceal cchar=⊡
syn match todoCheckbox '\v(\s+)?(-|\*)\s\[o\]'hs=e-4 conceal cchar=⬕
]]
end
})
end
markdown_sugar()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Melkster nice you found the issue :)

Check I also added support for VimWiki ToDo's state using some symbols I found: