178

Sometimes I try a customization/command in my vimrc. Everything seens to be correct, but it just doesn't work.

It's difficult to know what's happening when vim starts, and know which command failed or not, so it's really difficult to debug what can be causing a problem in my vimrc. It's a trial-error approach, which is time consuming and really a PITA. For example, I'm having problems with snipmate plugin in some files and just don't have a clue on how to discover the problem.

Is there a "runtime log" when vim starts, telling which commands it executed, which ones failed and such? This would help me a lot.

Community
  • 1
  • 1

6 Answers6

207

running vim with the -V[N] option will do a pretty hefty runtime log, here N is the debug level.

vim -V9myVim.log

would create a log of debug level 9 in the current directory with the filename myVim.log

ideasman42
  • 42,413
  • 44
  • 197
  • 320
sleepynate
  • 7,926
  • 3
  • 27
  • 38
  • I liked both approachs from Zyx and you, but your approach is better in my opinion because it's simpler, only in the cmd, and I can set a path to the log each time I run it, and I don't need to "inflate" my vimrc. And welcome to SO! – Somebody still uses you MS-DOS Jun 11 '10 at 21:47
  • 2
    See also [`:h 'verbose'`](http://vimdoc.sourceforge.net/htmldoc/options.html#%27verbose%27) and [`:h :verbose`](http://vimdoc.sourceforge.net/htmldoc/various.html#:verbose). – Palec Oct 27 '15 at 14:32
  • [MacVim](https://macvim-dev.github.io/macvim/) doesn't seem to support `-V` option or any command-line option. – emallove Feb 27 '19 at 23:07
  • this opens a empty vim buffer without a filename. What next? – Geoff Langenderfer Mar 20 '20 at 21:44
  • 1
    Unfortunately (according to `:h 'verbosefile'`): *"Writes are buffered, thus may not show up for some time."* – user202729 Oct 08 '21 at 09:55
  • @emallove With the help of [this post](https://stackoverflow.com/questions/2056137/how-to-run-mvim-macvim-from-terminal), I was able to get this running with MacVim by running `/Applications/MacVim.app/Contents/MacOS/Vim -g -V9myVim.log`. The MacVim command indeed doesn't take options, but I think this is equivalent (it still shows up as MacVim in the title bar) – cincodenada Feb 16 '22 at 20:58
135

:messages shows all warnings, errors, and informational messages that appeared (possibly briefly) in the vim statusline.

:echo errmsg prints the most recent error message.

g< is another feature few people know about. From :help g<:

The g< command can be used to see the last page of previous command output. This is especially useful if you accidentally typed <Space> at the hit-enter prompt.

For example try :!ls then cancel the prompt, then hit g<.

Justin M. Keyes
  • 6,679
  • 3
  • 33
  • 60
18

Put this function into .vimrc:

function! ToggleVerbose()
    if !&verbose
        set verbosefile=~/.log/vim/verbose.log
        set verbose=15
    else
        set verbose=0
        set verbosefile=
    endif
endfunction

Then create directory ~/.log/vim and call ToggleVerbose() to get your log in ~/.log/vim/verbose.log. Note that you may catch «variable nested too deep for displaying» error which will not normally appear just because you have raised your verbose level.

ZyX
  • 52,536
  • 7
  • 114
  • 135
1

I don't think there is a runtime log, per se, but you can run it in debug mode.
http://web.archive.org/web/20090323034339/http://www.troubleshootingwiki.org/Debugging_Vim_Scripts

Jay
  • 56,361
  • 10
  • 99
  • 123
  • 2
    This site seems to have been hacked or something. Until it's fixed, see the cached version at http://web.archive.org/web/20090323034339/http://www.troubleshootingwiki.org/Debugging_Vim_Scripts. – Mu Mind Dec 14 '12 at 19:43
  • I got 403 forbidden – Frank Fang Aug 18 '17 at 05:44
  • @FrankFang http://web.archive.org/web/20090323034339/http://www.troubleshootingwiki.org/Debugging_Vim_Scripts – Jay Aug 20 '17 at 18:54
1

This probably goes against everything SO stands for, but here's what I do: I just hit print screen soon as the warning comes up and look at the picture.

puk
  • 16,318
  • 29
  • 119
  • 199
-2

I had to add "set nocp" to use "ToggleVerbose()" function when run in root because of &verbose

masuch
  • 345
  • 1
  • 2
  • 8
  • 1
    This has nothing to do with the question, it is a basic part of vim scripting. Consider adding it as a comment to ZyX's answer. – Justin M. Keyes Aug 08 '21 at 15:19