0

Question

How to use :VimwikiGenerateTagLink with a search pattern?

Explanation

  • The Vimwiki command :VimwikiGenerateTagLinks produces the list of tags and links of your wiki. Without arguments, it generates the full list of tags and the corresponding links. With arguments, it can report the links of every argument; every argument being a tag.
  • You can easily autocomplete tags in : command mode.
  • However, I don't find the way to pass the argument of a search pattern. For instance, :VimwikiGenerateTagLinks * produces a literal == * == header.

Use case

Suppose you have four tags::2024-01-01: :2024-01-02: :aaa: bbb and you want to report only the tags not containing dates, i.e. only :aaa: bbb. My ideal scenario would be something like

:VimwikiGenerateTagLinks [Not-beginning-with-number]+[any-character]

or

:VimwikiGenerateTagLinks [^0-9].*

(Forgive the bad regex use).

4
  • 1
    I had a look at the code and it seems not possible with the current implementation. I suppose you have to make a demand to the plugin manager or implement it your self :-). Commented Mar 20 at 13:52
  • Use the plugin's documentation/issue tracker.
    – romainl
    Commented Mar 20 at 13:52
  • Thanks @VivianDeSmedt. I don't know how to implement it, but I will ask the maintainers of the plugin about it.
    – Ludenticus
    Commented Mar 20 at 14:16
  • 1
    I have proposed an implementation that seems to work reasonably fine :-) Commented Mar 20 at 15:37

1 Answer 1

1

Looking at the VimWiki API you could do something like:

function! GenerateTagLinksRegex(regex)
  let tags = vimwiki#tags#get_tags()
  echom '^' .. a:regex .. '$'
  call filter(tags, {i, tag -> (match(tag, '^' .. a:regex .. '$') >= 0)})
  if len(tags) == 0
    return
  endif
  call call('vimwiki#tags#generate_tags', [1] + tags)
endfunction

command! -nargs=1 GenerateTagLinksRegex call GenerateTagLinksRegex(<f-args>)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.