Got this function:

function! TaskAnnotateWithFile()
    let uuid = GetUUID()
    echo uuid . ' '
    annotate -- ~/

The idea here is a I want to prefill the command line with something like this:

:task 693614b6-0141-4e22-93cd-ebc37ef47d55 annotate -- ~/

I then want to be able to tab to the file I need with the prompt at the end of the command.

However, after the function runs, I get spilled back out into normal mode and I'm not in the command line. Is there a way to achieve what I want?

  • How do you call the function, from a mapping? If it's from a mapping, you might have some success using an <expr> mapping that will return the : Ex sequence not including a <CR> at the end that will allow for you to continue typing it... If it's not from a mapping, then maybe feedkeys() is what you need?
    – filbranden
    Dec 3, 2021 at 20:10
  • Yes, with a mapping. I'm not familiar with the <expr> mapping. I'll look it up. So that <expr> goes in the right hand side of the map?
    – StevieD
    Dec 3, 2021 at 20:20
  • 2
    @filbranden means something like nnoremap <expr> <leader>X printf(':!task %s annotate -- ~/', GetUUID()).
    – D. Ben Knoble
    Dec 3, 2021 at 21:01

2 Answers 2


If you want to trigger this with a mapping then there's really no need for the function. Everything can happen in the mapping without much trouble.

There are a couple ways to approach this.* I just happened to be using the c_CTRL-\_e command-line editing feature recently so let's use that. The key command looks like this:

CTRL-\ e {expr}

This populates the command line with whatever the expression in {expr} evaluates to. Our expression will be:

printf('task %s annotate -- ~/', GetUUID())

That returns a string with the UUID embedded between "task" and "annotate". In a Normal mode mapping that would be used like so:

:nnoremap <leader>X :<C-\>eprintf('task %s annotate -- ~/', GetUUID())<CR>

When executed you'll be on the command line with the cursor positioned after the ~/ so pressing tab will do file completion.

*Another way was suggested by @filbranden in the comments above (and filled out after this was posted). The method here is probably not as well known and perhaps a little more interesting as a result.

  • That works! Except I'm getting butt load of errors from the taskwiki plugin: pastebin.com/6AzKqTud Any ideas? It looks like an error from the GetUUID call but it pulls in the UUID just fine.
    – StevieD
    Dec 3, 2021 at 20:58
  • I'll take a look.
    – B Layer
    Dec 3, 2021 at 21:06
  • 1
    You can ignore the first 2 lines in that function. I still get the same error even with those lines commented out. It's just a dirty hack I'm using for updating the UUID.
    – StevieD
    Dec 3, 2021 at 21:09
  • 1
    So anyway, yeah, your solution worked. I need to find another dirty hack. :) Thanks!
    – StevieD
    Dec 3, 2021 at 21:11
  • 1
    Okay, cool. Good luck. :)
    – B Layer
    Dec 3, 2021 at 21:16

Filbranden and D. Ben Knoble came up with something like

nnoremap <expr> <leader>X printf(':!task %s annotate -- ~/', GetUUID())

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.