Is there a "vim runtime log"? - vim

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.

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

: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<.

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.

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

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.

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

Related

Vim: Sourcecode output at startup

Today I installed vim on my new computer and installed a couple of plugins.
When I start vim (with no arguments and with files to edit) I get a lot of verbose output in my console which I never encountered before.
This seems to be something from the vim sourcecode or from a plugin but I couldn't encounter where it comes from and especially why.
I'm interested in tracking down this issue. How can I do that?
I tried searching for some of these lines in my plugin folder but got no results and starting with the -D flag also gave me no hint. Google and SO search also yielded no results for me.
Additionally I tried to disable each plugin seperately but this also failed.
Thanks.
PS: I would like to provide a picture but since the output is more than 150 lines long this is not a good idea since it doesn't seem to be related with a plugin and I don't have enough reputation.
Maybe a very small part of it:
syntaxset FileType
*exe "set syntax=" . expand("<amatch>")
filetypedetect StdinReadPost
...
svn-commit*.tmp
setf svn
Xresources*
call s:StarSetf('xdefaults')
*/app-defaults/*
Remark: This is not representative since it is randomly chosen from the terminal output, I just wanted to give an impression what is going on.
EDIT: This is NOT an error, its just printing out some kind of source code. Everything is working fine otherwise.
SOLUTION: Removing the autocmd line without any further text did the job. Thanks to FDinoff. Debugging with finish is really pleasant.
Some Vim commands, when argument(s) are left off, print all existing such artifacts. This is useful during interactive use, but if you forget to specify the argument in your (plugin / ~/.vimrc) configuration, this has the effect of "printing cryptic code" (an error would be more useful here).
Your output is likely from an :autocmd without arguments. Check your ~/.vimrc and other files read during startup (see :scriptnames).

Ignore errors and warnings for a VIM plugin

Suppose I have a VIM plugin that is very useful, but it generates a lot of errors/warnings that I don't care for.
How can I ignore all errors from that plugin? I just want to be disturbed by these messages anymore.
Is there any setting/function call that turns off such things?
I know that the best thing would be to report this as issue, but how can I just make them not appear?
Example of errors:
Well, I would definitely look into the root cause of the errors, as it might affect the plugin's functionality. At least this should allow you to send a precise bug report to the plugin's author.
Errors and warnings can be suppressed via the :silent! (note the !) command. Basically, any Ex command can be prefixed with it. So, if you have a :TroublesomeCommand, you can silence the errors via
:silent! TroublesomeCommand
To silence the plugin (if you really must), you can might be able to redefine its mappings (to include :silent!) and commands, but the use of <SID> may force you to modify the plugin itself. In that case, you can also put the :silent! directly before the offending command (the error should include its location), but again, fixing the root cause would be preferable.

Can I have errors from "lein cljsbuild auto" appear in my Vim quickfix window?

I want to be able to have errors from cljsbuild appear in my Vim quickfix window. More detail below.
I'm enjoying ClojureScript while using Vim as my editor but I want to improve my work flow.
Currently I edit in Vim and have a watcher task in another terminal that will auto build whenever I change any source. My leinengein file is configured to spawn this with
lein cljsbuild autobuild
This is great as I don't have to spin up the JVM for every compile and it's pretty quick. So the work flow is:
Edit
Save
Auto compile
Switch to the browser
Refresh and run
Nice :) The only issue is when I get an error or warning. I have to keep an eye on the other terminal window to see if there's any error spew and then work out where the error line is by trawling through it. I'm a bit of a newb so I get a lot of errors :D
What I'd prefer is having any errors appear in Vim in my quickfix window so I can jump to them quickly while not giving up the benefits of having the cljsbuild run as a file watcher.
Is this possible? Any help gratefully received :)
gaz
As long as the errors are shown in stdout, Vim can show these errors and respective line numbers from the quickfix window.
Since I don't use clojurescript, you'll have to read Vim's documentation about makeprg and errorformat. This is rather straight forward.
I've used makeprg with autocmd before, but now I let Syntastic do the work for me. Unfortunately, it doesn't support clojurescript at the moment, you could do a pull request if you get it to work.
As long as you can capture the build output into a file (by appending > build.log or | tee build.log), you can then load this into Vim's quickfix list via:
:cfile build.log
Of course, you need to set an appropriate 'errorformat' first so that Vim is able to correctly parse it.

Warning keep popping when running conque in VIM

When running conque in VIM, the warning message prompts out every time:
Warning:
Global CursorHoldI and CursorMovedI autocommands may cause ConqueTerm to run slowly
I found a method to remove the warning is to comment out the warning-function in the conque_term.vim, but I don't think it's a decent and safe way to solve the problem.
I'm new with VIM, so I found no way to identify the source of problem by myself. Could anyone help? Thanks a lot!
One integration point into Vim is through events, which can trigger automatic commands; the Conque plugin itself uses these to implement its functionality. Events like CursorMovedI are fired whenever you type something or move the cursor in insert mode; this can have an impact on performance, and that's what the warning is about.
You can list all such automatic commands via:
:verbose autocmd CursorHoldI,CursorMovedI
As long as Conque works well for you, it's fine to ignore (and suppress) the warning. But if you indeed run into problems, you'd need to check the other autocmd sources and maybe disable one or the other plugin (at least for the Conque buffer). (See :help autocmd-remove for how to do this.)
Off topic, but using Ctrl+Z to drop back to shell and fg to return to vim seems to work way better than Conque. That is if you're using vim from the terminal, which you should.
Some inspiration: http://statico.github.com/vim.html

How do I setup REPL on vim?

I have installed vimclojure to make it easier to start learning clojure. But, I haven't been able to setup REPL inside vim. This is essentially because I was not able to write a maplocalleader in vim(?)
Based on the documentation in vimclojure/doc/clojure.txt I put the following in my .vimrc to start the REPL -
:map <LocalLeader>sr *sr* *StartRepl*
But typing "sr" doesn't start the REPL.
Thanks in advance.
Most likely there is an error occurring in the plugin before the VimClojure mappings are fully defined.
One likely scenario that I have run into several times occurs when the Clojure source file has syntax errors when it's loaded into the Vim buffer.
There's something going on in the plugin during the load of the source file (syntax highlighting or something) that errors out and prevents the mappings from getting defined.
This is probably just an unfortunate issue with VimClojure and should be reported, but I haven't had time to dig enough and log an intelligent bug report/patch.
To troubleshoot, with a Clojure source file open in current buffer, try doing this:
:call vimclojure#Repl.New()
This invokes the function inside the plugin that is mapped to \sr. It's not a recommended way of launching the Repl, but since we're just troubleshooting your configuration, hopefully it will reveal something meaningful to you.
Also, do this to see if there happen to be any helpful messages getting logged.
:messages
<LocalLeader> uses value from maplocalleader variable or it is backslash by default. If you do not set maplocalleader variable try \sr
I've found vim-fireplace plugin a much easier way to start learning Clojure in Vim. Good introduction can be found in "Unboxing vim-fireplace".
I don't have a mapping for sr in my .vimrc, but it works for me.
Have you checked that your Nailgun server is running, and that you have turned on Gorilla?
E.g.,
let clj_want_gorilla = 1
let vimclojure#NailgunClient = "/Users/foo/vimclojure-2.1.0/ng"
One can use Conque, a vim plugin that supports running a shell in a vim buffer. I have successfully used it to run a clojure REPL inside vim. It supports split screens, so one can send code from a clojure source code buffer to the clojure REPL.
I've found that if the NailgunClient cannot be found, VimClojure will fail silently and none of the <LocalLeader> commands will work. I'm basically just repeating Joe Holloway above, but try this to verify that the Nailgun client is actually found:
:call vimclojure#Repl.New()
In my case I forgot to build the client, so I just returned to the unzipped VimClojure folder and ran make. This creates ng, the nailgun client executable. Make sure this is in your PATH somewhere, or set
let vimclojure#NailgunClient = "/Users/foo/vimclojure-2.1.0/ng"
as mentioned above.
Don't you need to press ,sr? LocalLeader is a comma by default I think.
Have you tried mapping it to something else? It seems like you aren't sure what LocalLeader is mapped to, so I would recommend changing your mapping.
I solved the E10 problem with :set nocompatible. Then the \sr etc. commands worked OK.
Getting VimClojure setup with a Nailgun server is how I've done it. I use leiningen to help manage the classpath. It's a fairly complicated process, but nice once you've got it set up.
In addition to using the correct local leader key (ie. "\" -> \sr by default), note that in order for VimClojure to start a repl, a clojure file needs to be loaded in the buffer. If you just start vim and hit \sr nothing will happen because VimClojure is not active yet.
You can activate VimClojure by editing a file with the clj extension. From inside vim:
:e test.clj
Now when you hit \sr the repl should open. If not, see the other answer regarding checking hidden error messages.
This tutorial is up-to-date as of time of writing and helped me get VimClojure set up with Leiningen in OSX: https://github.com/daveray/vimclojure-easy
The more advanced setup linked to in the What's Next section was also helpful.

Resources