I would like to debug functions a bit more easily. Instead of running them and having to do:

:10 messages

To actually just have a vim.log file opened and tail -f'ed so I can see the output while it's running, without having to keep going into and out of messages and such.

Is there a way to do this? For example, in the following function:

func Toggle2 ()
    echom 'start toggle2...'
    echom 'end toggle2...'

I would essentially like to do:

  • Output goes to vim.log for this function
  • But I don't want all the other vim-related messages. Just this function.

How could this be done? I tried doing the following:

func Toggle2 ()
    call execute('redir > vim.log')
    echom 'start toggle2...'
    echom 'end toggle2...'
    call execute('redir END')

But received the following error:

E930: Cannot use :redir inside execute()

  • You don't need execute() to do :redir
    – Matt
    Commented Jun 13, 2020 at 7:09

2 Answers 2


As matt points our, just redir:

redir > file
redir END

The other possibility is to use a logging framework like mine.

When working on complex plugins for years it's really game changing. The main feature being:

  • having the logs sent to the quickfix window with the file+line where the log has been done
  • the possibility to choose which module is logging and which isn't (actually this is a consequence of how I use my logging framework) -- it works best, and very well, with autoload plugins that you haven't seen yet.

However, for your first plugins it may be a little overkill.

PS: I see :redir as the old solution which has few annoying drawbacks. I use it for portability issues when execute() isn't available. I even prefer call writefile('filename', execute('message')) -- I may have mixed-up the order of writefile() parameters.

PPS: I really feel like writing the same things over and over again. You really should avoid asking precisions on a topic in multiple questions

  • that's really cool (and incredible) that plugin. Inspired by that I tried writing a basic log function, which I've added a question about here: vi.stackexchange.com/questions/25936/…. How do you do introspection?
    – David542
    Commented Jun 13, 2020 at 22:21

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.