8

I am working on a vim plugin and as part of that I am testing various things like "auto-groups" and events where I can hook bits and pieces in general. While things are running I am using functions that output various debug messages using the echom command. The problem is once I want to have a look at the output, I need to type :message and then keep hitting a key until the end of the messages appear, so I can see what was the last message.

Is there a workaround for this? Like, is there a plugin that would help me see the messages stream in realtime inside a separate buffer?

Thanks. (OSX, MacVim)

mbilyanov
  • 2,315
  • 4
  • 29
  • 49
  • 1
    Yeah, I spent some time trying to figure out what the "-1" means and when you get it :) – mbilyanov Dec 26 '13 at 00:55
  • You could try starting vim with option `-Vlogfile.txt`, and then either use a `tail -f logfile.txt` in separate terminal window or open `logfile.txt` in Vim with a `:setlocal autoread` (or any of the various tail plugins for vim). However, Vim doesn't seem to flush the logfile very frequently, so you will be a bit "behind" in the log... Also note that when you do `:messages` in Vim, you can go directly to the last message by hitting `G` and use other navigation keys (see `:help messages`). – Miichi Dec 26 '13 at 11:19

2 Answers2

3

Instead of using :echom directly, write a little s:Log(message) function. It should switch to your log buffer, then append a:message at the bottom (or the top, if you like). Switch back to the current buffer and :execute "echom" a:message.

If you also want to see regular messages in your log buffer, you could use :redir to capture the messages, then append them to your log buffer on a CursorHold event. This is more complicated, and it would tie up one of your named buffers.

:help :wincmd
:help :put
:help append()
:help :redir
:help CursorHold
benjifisher
  • 5,054
  • 16
  • 18
0

For me, :echomsg and :messages is fine most of the time. If you need something more elaborate, have a look at the Decho - Vim script internal debugger plugin. It can capture log messages in a separate window.

For hairy parts, no amount of log output will be enough; you can then launch the built-in interactive debugging; see :help debug-scripts.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324