On 04/13/2011 08:52 AM, Jürgen Krämer wrote:
How can you insert the output of an Ex command into the
buffer at the place where the cursor is?

1) use :redir to a register and paste the register
contents:

Strange that there isn't a simpler method built-in.


I totally agree with you. Would be much more simpler if we could wrote
something like:

:<echo 25*47

And the output was directly put in the current buffer in the cursor position.
The sequence "redir 'something'", type a command and then 'redir END' is
really to much to do when we need to be fast. To get the result of the
calculation above is much more easy just "see" the value in the command window
and write it by your hand in the buffer.

This is a feature that a miss in Vim/GVim for quite sometime.

you can insert the output of every VimL expression with

   <C-R>=your-expression-goes-here<CR>

while you are in insert mode. Your example would then be typed as

   <C-R>=25*47<CR>

While this works for expressions (the followup question about "echo 25*47"), it doesn't satisfy the OP's request for arbitrary Ex commands. Assuming the commands to be executed don't include redirs and there's not a redir already in process (that you don't want to terminate), it could be wrapped in a function

 function! Capture(excmds)
   redir => s:results
   exec a:excmds
   redir END
   return s:results
 endfunction

You could then use the function in concert with the expression register:

  <c-r>=Capture('scriptnames')

(odd results if you don't have 'paste' set) in insert mode, or you can use

 "<c-r>=Capture('scriptnames')<cr>p

to paste it in normal mode. The command should also work with multiple pipe-separated commands:

  Capture('scriptnames|set')

Hope this helps,

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to