开发者

Open a new window in Vim-embedded python script

开发者 https://www.devze.com 2023-01-12 12:55 出处:网络
I\'ve just started wrapping my head around vim+python scripts (having no experience with native vim scripts).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消