echoing from inside autocommands seems erratic. Consider:
command! Echo1 redraw | echomsg 'First line' | echomsg 'Second line'
command! Echo2 call echo#Echo()
" In file ~/.vim/autoload/echo.vim:
function! echo#Echo()
redraw | echomsg 'First line' | echomsg 'Second line'
endfunction
:Echo1 and :Echo2 do exactly the same thing and they do it right: Output
two lines of text in the messages area. From inside autocommands it's
another story: Sometimes they work, sometimes the output is incomplete.
:Echo1 :Echo2 (autoload)
(from cmd-line) OK OK
ColorScheme OK OK
WinEnter OK* OK*
VimEnter incomplete incomplete**
CursorHold, InsertLeave incomplete incomplete
* OK with :sp and :vsp, but not CTRL-W w
** OK on my Mac (MacVim 7.3 and terminal Vim 7.2)
What is going on here? I'm on Vim 7.3.429 on Ubuntu 12.04.
Thanks, glts
asking for confirmation of flaky :echo behaviour in autocommands.
In a nutshell: Echoing more than one line from within an autocommand is
unreliable. The message may be shown in its entirety or partly,
depending on what type of event it is attached to.
I tried the following command with a number of autocommand events:
command! Echo redraw | echomsg 'First line' | echomsg 'Second line'
ColorScheme OK
FileType OK
WinEnter (:sp, :vsp) OK
WinEnter (CTRL-W ...) truncated
CursorHold truncated
InsertLeave truncated
FocusGained truncated
QuickFixCmdPost truncated
I would be glad if somebody could confirm what I am seeing, so I can set
this aside as a Vim-problem and not a me-problem.
Thanks, glts
thank you for answering.
On Saturday, December 8, 2012 1:07:48 PM UTC+1, Christian Brabandt wrote:
> I have seen the issue, but haven't found the problem yet. Is there any
> reason, why you are not using :echo?
No reason. It doesn't matter, however, as the behaviour is the same
regardless of whether I use :echo or :echomsg. At least with :echomsg
I can see the output via :messages.
glts
On Sunday, December 9, 2012 3:06:20 PM UTC+1, Christian Brabandt wrote:
> Hm, strange, but if you define
> :command! Echo redraw | echo "First line \nSecond line"
> it does not get truncated. So this is at least a workaround.
A poor workaround, unfortunately. It works with :echo but not with
:echomsg, and it isn't possible to highlight the lines (or part of a
line) differently.
I would look into this myself, but honestly I don't know where to start
because messages and autocommands don't seem to have anything to do with
one another ...
glts