I'm using ctags to generate tag file so that I can jump to declaration or to definition while working with C/C++ project.

To make ctags work automatically while entering vim, I add such a line in my .vimrc:

autocmd VimEnter * silent! !eval 'ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -o newtags; mv newtags .tags;' &

As you see, this command won't block because of &.

Now, I want to make sure that a message will be printed at the bottom of the window of vim after this command is done. How could I do this?

1 Answer 1


Try it as a background job (:help job). Maybe like this:

function CtagsExit(cwd, job_id, exit_code)
    if a:exit_code == 0
        call rename(a:cwd . '/newtags', a:cwd . '/.tags')
        echo "Ctags finished with 0"
        echo "Ctags finished with " . a:exit_code . " (execute :messages to see output)"

function CtagsOutput(channel, data)
    echomsg a:data

function CtagsStartup()
    let cmdline='ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -o newtags'
    let options = {
                \   'in_io': "null",
                \   'out_cb': "CtagsOutput",
                \   'err_cb': "CtagsOutput",
                \   'exit_cb': function('CtagsExit', [ getcwd() ])
                \ }
    call job_start(cmdline, options)

autocmd VimEnter * call CtagsStartup()

Update: Handle changing directory while ctags is running. Update 2: Handle output.

  • I got an error: CtagsStartup: line 2: using Funcref as a String
    – Yves
    Jan 14, 2019 at 8:46
  • @Yves What Vim version do you use? Which OS?
    – Ralf
    Jan 14, 2019 at 8:48
  • Vim version: 7.4 OS:Ubuntu16.04.3
    – Yves
    Jan 14, 2019 at 8:49
  • Oops, now it works. I made a copy mistake.
    – Yves
    Jan 14, 2019 at 8:51
  • @Yves I realized, that the first version will fail, as soon as ctags produces any output. I updated the script.
    – Ralf
    Jan 14, 2019 at 10:06

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.