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>
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()
.
+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?