3

In order to keep my tags file up to date I wrote this function which runs ctags -R . whenever I save a file.

function! UpdateCtags()
    " assume if a tags file exists - then current dir is ok
    if filereadable("tags")
        echo "updating tags file"
        call system('ctags -R .')
    else
        echo "unable to update tags file - probably wrong current dir"
    endif
endfunction

au BufWritePost * silent! call UpdateCtags()

The function seems to work ok, but it triggers a prompts

"somefile" 508L, 16090C written  
updating tags file  
Press ENTER or type command to continue

Its not a major problem, but considering I save a file probably every 15 seconds, I want a message confirming the function ran to be printed, but I don't want to be interupted by a prompt.
.
Is it possible to make this prompt go away?

Ive tried adding silent! to the autocmd

au BufWritePost * silent! call UpdateCtags()

But it seems to have no effect

3

After reading this vim.wikia.com article, I learnt that the cause of the prompt is content in the command line exceeding the available commandline height

so I added set cmdheight=2 to the function to this and it now seems to work

if filereadable("tags")
    set cmdheight=2
    "^^^^^^^^^^^^^^^^
    echo "updating tags file"
    call system('ctags -R .')
    set cmdheight=1
    "^^^^^^^^^^^^^^^
else
  • 2
    You should probably store the old height and restore it, rather than hard offing the "old" value. – Fund Monica's Lawsuit Dec 28 '15 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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