This is a card in Dave's Virtual Box of Cards.

Vim "mini-plugin": Task file lists

Page created: 2023-06-16

Back to vim or vim-mini-plugins.

Custom syntax highlighting

This one is incredibly silly and incredibly helpful. At work, we have a lot of source files. When I start a new task, I make a VimWiki page for it using a script that pre-populates the page with a title and that sort of thing. It also creates a block with FILELIST …​ ENDFILELIST.

In that block, I put file paths related to the task along with comments about that file. It looks like this:

Notes, blah blah blah.

FILELIST

foo/bar.js <--- added new function
biz/baz.html
    todo: add section

biz/baz.js
    Note: Surprisingly not related to baz.html

ENDFILELIST

Jump to file

The coloring helps me see the file names easily, which is important because I also use them as a menu! I just put the cursor over the path and type g f which is the standard Vim command to "go to the file" under the cursor!

Another important shortcut not shown here because it is highly custom to my setup: I also defined g w to "go back to the wiki page" for the current task.

Source

function! FileListMiniPlug()
    syn region sweetFileList start=/FILELIST/ end=/ENDFILELIST/ keepend
    syn match sweetFile /^[^ ]\+/ containedin=sweetFileList contained
    syn match sweetNote / .\+/ containedin=sweetFileList contained
    syn match sweetSyntax /FILELIST\|ENDFILELIST/ containedin=sweetFileList contained
    hi link sweetFile Special
    hi link sweetNote Comment
    hi link sweetSyntax Keyword
endfunction

# apply the "mini-plugin" when we enter a vimwiki page:
augroup sweet
    autocmd!
    autocmd FileType vimwiki call FileListMiniPlug()
augroup END

I laughed out loud when I saw the "sweet" names in the above vimscript. I hadn’t seen this code for years. It’s just been quietly working in the background for all that time.