You can use the :redir command to redirect the output of an ex command to a register and then paste the contents of the register into a Vim buffer. For example: :redir @a :set all :redir END Now, register 'a' will have the output of the "set all" ex command. You can paste this into a Vim buffer, using "ap. Example usage: :TabMessage highlight Note that :redir can use a variable instead of a register, as shown above.
Attributes | Values |
---|
rdfs:label
| - Capture ex command output
|
rdfs:comment
| - You can use the :redir command to redirect the output of an ex command to a register and then paste the contents of the register into a Vim buffer. For example: :redir @a :set all :redir END Now, register 'a' will have the output of the "set all" ex command. You can paste this into a Vim buffer, using "ap. Example usage: :TabMessage highlight Note that :redir can use a variable instead of a register, as shown above.
|
Version
| |
dbkwik:vim/property/wikiPageUsesTemplate
| |
Previous
| |
Category
| |
Text
| |
Complexity
| |
Created
| |
ID
| - 95(xsd:integer)
- 120(xsd:integer)
|
NEXT
| |
Rating
| |
abstract
| - You can use the :redir command to redirect the output of an ex command to a register and then paste the contents of the register into a Vim buffer. For example: :redir @a :set all :redir END Now, register 'a' will have the output of the "set all" ex command. You can paste this into a Vim buffer, using "ap. You can also write a Vim function to do the above. Since you probably don't want your command output to mess up your carefully constructed window layout, this function will pipe the output of a command into a new tab, allowing you to simply close the tab when done. If you don't like using tab pages, or you don't have tab support because you didn't compile with it or your Vim version is less than 7.0, you could modify this function to use a new split window instead: function! TabMessage(cmd) redir => message silent execute a:cmd redir END if empty(message) echoerr "no output" else " use "new" instead of "tabnew" below if you prefer split windows instead of tabs tabnew setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified silent put=message endif endfunction command! -nargs=+ -complete=command TabMessage call TabMessage() Example usage: :TabMessage highlight Note that :redir can use a variable instead of a register, as shown above. Note also that :redir will capture silenced messages as well. While this won't be problematic with most builtin commands that echo stuff that we are interested in, this is quite problematic when we execute a sequence of several commands. Since version 7.4-2008, Vim provides an execute() function that'll simplify things and avoid side-effects.
|