Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Todo list syntax in Vim, with an actual checkbox
" 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
@huytd

This comment has been minimized.

Copy link
Owner Author

@huytd huytd commented Jun 14, 2020

It's required to use a nerdfont to have the icons displayed correctly.

image

@mrassili

This comment has been minimized.

Copy link

@mrassili mrassili commented Jun 14, 2020

@huytd what font is that exactly?

@hutchison

This comment has been minimized.

@mrassili

This comment has been minimized.

Copy link

@mrassili mrassili commented Jun 14, 2020

thanks!

@Melkster

This comment has been minimized.

Copy link

@Melkster Melkster commented Jun 14, 2020

This seems to only work if the file does not have a defined syntax.

How could I get this to work for Markdown files?

@20jam

This comment has been minimized.

Copy link

@20jam 20jam commented Jun 14, 2020

How could I get this to work for Markdown files? +1

@huytd

This comment has been minimized.

Copy link
Owner Author

@huytd huytd commented Jun 14, 2020

@20jam

This comment has been minimized.

Copy link

@20jam 20jam commented Jun 14, 2020

Thank you, I've tried everything but just won't work. I look forward, thanks

@huytd

This comment has been minimized.

Copy link
Owner Author

@huytd huytd commented Jun 14, 2020

@20jam

This comment has been minimized.

Copy link

@20jam 20jam commented Jun 14, 2020

Amazing thanks for the help

to make it work in lists

syntax match todoCheckbox "- \[\ \]" conceal cchar=
syntax match todoCheckbox "- \[x\]" conceal cchar=

@Melkster

This comment has been minimized.

Copy link

@Melkster Melkster commented Jun 24, 2020

This doesn't work for lists in lists, since only the outermost list gets concealed. For example:

- [ ] foo
  - [x] bar
  - [ ] baz
- [ ] foz

I tried to solve it with the following:

syntax match todoCheckbox /\v\s*- \[\ \]/ conceal cchar=
syntax match todoCheckbox /\v\s*- \[x\]/ conceal cchar=

But that removes the indentation when concealing. What pattern do I need in my syntax match to match but not conceal the indentation? I tried to use regex capture groups (which I think is how you should do it) but couldn't get it working correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.