Creating ctags extension for markdown
Asked Answered
S

1

5

I edit quite a few markdown files using Vim these days. One thing I'm missing is a map of the file like function list in C based on ctags. So I came up with the following .ctags file

--langdef=markdown
--langmap=markdown:.md
--regex-markdown=/^# ([a-zA-Z0-9]+)/\1/

It runs OK but generates no valid tags for my .md file. With verbose mode turned on I get the following:

Considering option file /home/wenliang/.ctags: reading...
 Option: --langdef=markdown
 Option: --langmap=markdown:.md
 Setting markdown language map: .md
Option: --regex-markdown=/^# ([a-zA-Z0-9]+)/\1/
Considering option file ./.ctags: not found

What's wrong with what I did?

Studbook answered 9/9, 2014 at 10:30 Comment(1)
Looks fine to me. What's your source Markdown document, and what gets created?Illegalize
S
8

Your definition looks OK.

What command did you use to generate your tags file? $ ctags . won't index anything but $ ctags -R . will.

FWIW, here is a slightly modified version of your definition that provides meaningful tag names and kind informations:

--langdef=markdown
--langmap=markdown:.md
--regex-markdown=/^#[ \t](.*$)/\1/h,heading,headings/

:tselect /<CR>


As an alternative, you might be interested in these cheaper, built-in, solutions…

  • using the define option and :dlist:

    :setlocal define=^#\\s*
    :dli /<CR>
    
  • using :ilist and no setup:

    :il /#<CR>
    

which both produce the same list, ready for you to type :126<CR>:

:il /#<CR>

See :help :ilist, :help :dlist, :help 'define'.

Sohn answered 9/9, 2014 at 10:54 Comment(2)
What colorscheme is that? I really like it.Cede
@ldigas, thanks, it's called Apprentice.Sohn

© 2022 - 2024 — McMap. All rights reserved.