Reputation: 455
I'm using universal tags. I have several markdown files that start with # Introduction # Getting started. To avoid
duplicate tags I started doing # Topic1 Introduction
and # Topic2 Introduction
. This
does not look good in documentation, is there a way that I can make unique tags based on file name
without changing the markdown?
What I want to do in vim is:
:tag topic1 introduction
But I want the markdown to look like this:
## Introduction
Something about topic1.
I don't want to create my own language file but if I have to I can do something like touch ~/.ctags.d/mymarkdown.ctags
? I'm not experienced in ctags, this was just something I was messing around with before the markdown default file was patched.
--_mtable-regex-MarkdownNew=main_sharp/^##[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/s/{_field=sectionMarker:##}{scope=push}{tenter=section,main}
Do something like this:
...*/printf "%s%s" \1 this.filename/s/{_file=...
I understand that this may be difficult because the tags need to get referenced some how.
So my next question to that would be, is there a way I can associate file1.md line 11 with 'topic1 introduction' tag in the .tags file? Then I would associate file2.md line 9 with 'topic2 introduction' in the .tags file. Then I could just reference :tag topic1 introduction
and :tag topic2 introduction
Upvotes: 1
Views: 233
Reputation: 196777
If "topic" == "file", then you can simply use :tjump Introduction
(I did :tj /intro
, here) and choose the tag you want:
The problem with this, however, is that it obviously doesn't scale beyond a few files/topics. But, if we are honest with ourselves, a system built on memorising topics/filenames like you are suggesting is probably even less scaleable.
If you really want that API:
:<command> <topic> <tag>
then the most interesting approach might be to create a custom command that behaves a bit like :help :cscope
, with "sub-command"-like completion:
:Foo <Tab>
(completes from available topics)
:Foo topic1 <Tab>
(completes from available tags for chosen topic)
:Foo topic1 Introduction<CR>
(opens the given tag)
Here are pointers that may prove useful if you want to go that route:
:help taglist()
:help filter()
:help :command-completion
:help :command-completion-customlist
Upvotes: 2