How do I fix the delay in redirecting messages to a file in Vim?

I have this line in my vimrc:

redir! >/Users/seanmackesey/.vim/.vimmessages

      

But the messages do not appear in this file immediately after they are generated - when I run tail -f .vimmessages

in a shell, the messages appear slowly and somewhat erratic. Sometimes I get a big dump of messages when I run the command :messages

, but I can't figure out exactly what the template is. Is there a way to just add each message as it happens immediately to the end of the file?

+3


source to share


2 answers


The problem with the global :redir

is that it doesn't nest, so it throws errors with mappings and functions that also use :redir

. Rather use

:set verbosefile=/Users/seanmackesey/.vim/.vimmessages

      



to capture all messages. Since Vim's implementation uses buffered output, you will still experience a number of chunks.

You have not indicated where you intend to use this pin, so it is difficult to give a better recommendation. If you really want immediate output to an external file, you will need to use writefile()

or use the built-in scripting language to write and clear the file.

+3


source


Most likely, it was simple data buffering, and not any specific time delay.

I've grepped through Vim 7.3 source and it looks like this redir

is done with fopen, puts and putc and fclose (i.e. stdio). There were no calls to fflush, setbuf, setbuffer, setlinebuf, or setvbuf, so the redirection will always use the default buffering provided by your stdio systems (possibly "block buffering" of some convenient size).

You can periodically stop and restart the redirection to efficiently clean up the data:



redir END | redir! >>~/.vim/.vimmessages

      

In addition to this, there doesn't seem to be a good way to do what you want with a file redir

.

+1


source







All Articles