1

Currently, I am using nnoremap <leader>d :vnew +pu=execute('')<left><left> to dump output in both vim and neovim. I tried it with verbose imap <tab> but it didn't work

nnoremap <leader>d :vnew +pu=execute('verbose imap <tab>')<left><left>

1
  • I think the problem is that a command passed with +cmd to e.g. :vnew needs to have no spaces... Using :vnew +pu=execute('verbose\ imap\ <tab>') seems to work for me. Can you check that's the case for you too?
    – filbranden
    Dec 21 '21 at 2:41
2

This is failing because when you use the +cmd argument to :vnew, you need to escape spaces with backslashes. As :help +cmd points out:

To include a white space in the {pat} or {command}, precede it with a backslash.

So, in your case, using the following would work:

:vnew +pu=execute('verbose\ imap\ <tab>')

Perhaps a better approach is to define a new user-command that would encapsulate the implementation. In that case, you can also modify the opened buffer to become a scratch-buffer, since you probably don't want to save its contents when quitting.

For example:

function! Dump(cmd)
  vnew
  setlocal buftype=nowrite bufhidden=delete noswapfile
  let result = trim(execute(a:cmd))
  put! =result
  1
endfunction
command! -nargs=* -complete=command Dump call Dump(<q-args>)

Which you can then use with:

:Dump verbose imap <tab>

Defining a user-command is also useful in that you can set up tab completion. In this case, to complete Vim commands, which is what you want to pass execute().

1
  • 1
    Thank you very much. It is exactly what I need.
    – Pham Hung
    Dec 21 '21 at 7:09

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.