I've just started wrapping my head around vim+python scripts (having no experience with native vim scripts).
How can I open a n开发者_运维百科ew window to contain the stdout from a background process?
Currently, after reading some :help python, the only option I see is something like:
cmd = ":bel new"
vim.command(cmd)
Since vim.command
can execute most (if not all?) ex commands, you can simply call :new +read!ls
from within it.
:new
splits the current window and puts a new (empty, no name) buffer into the upper window. It takes an argument +[cmd]
which we use to execute read!cmd
which reads the stdout of cmd after the bang into the buffer. Be aware that you need to escape spaces in your command with \
All in all you get vim.command("new +read!cmd")
:python vim.command("new +read!ls")
to read in the contents of the current directory into a new buffer in a n cichew, horizontally split window.
If you want to handle escaping of special characters, consider using python's re.escape():
:py import re;vim.command("new +read!"+re.escape("ls Dire*"))
which should be sufficient for most cases. If in doubt, check its documentation and compare it to that of your shell.
精彩评论