Skip to content

User function w/o argument in templates #181

@Ginner

Description

@Ginner

Description

I have a template with the following line:

Day:  {{GetDay}}

In my init.vim I have:

function! GetDay() abort
    let l:day_name = strftime("%A")
    return day_name
endfunction

This, however, just result in {{GetDay}} in the new file when using the template.

Workaround

A solution I've found, is to have GetDay take an argument and just give a 'dummy' argument in the template. Like this:
Template file:

Day:    {{GetDay dummyarg}}

init.vim function:

function! GetDay(...) abort
    let l:day_name = strftime("%A")
    return day_name
endfunction

This makes the template behave as intended.

Proposed solution

Am I going about it wrong? Otherwise, I'd suggest one of the following:

  1. Accept function substitutions without arguments.
  2. Allow for adding entries to the context-dictionary (is this already possible?). This could then be used for these small functions without arguments. This might be a good idea regardless.
  3. Describe that an argument is required in the documentation.

My vimscript capabilities are, unfortunately, non-existing. But I'll be happy to take care of option 3 if that's the chosen route.

And again, Karl, I cannot thank you enough for your vim plugins and your continual, non-stop work on them!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions