I'm attempting to add some debugging functionality to a small vim plugin that I am working on. I'd like to wrap echo / echom in a way that allows me to turn off output if I want.

I've attempted to do this:

function! s:log(...)
  if (get(g:, 'my_plugin_debug_setting', 0))
    echom a:000

:call s:log('Debugging information')

but that just logs the list ['Debugging information'] (which makes sense, since i've just done the equivalent of echo ['foo']).

I've also attempted to use call: :call call('echo', a:000) but this doesn't work because echo is not a function.

Is there a way to do what I want?


In my lh-vim-lib library plugin I provide a framework for logging (among many other things) .

Unlike other frameworks (like maktaba) I don't try support several modes (error, warning, info, debug). Instead, I can choose to enable logs independently on each autoload plugin. Then, I can chose where the logs go (:messages, quickfix/loclist window, file, nowhere).

Otherwise, you could have used :echom string(a:000), or even join(a:000, ', ') as long as the list only contains strings -- I had to do some recursive voodoo magic to obtain a nice result on any type of variables in my library.

  • Very interesting! It's unfortunate there isn't an easy way, but that's what I've come to expect from VimL :\ Jun 17 '17 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.