简体   繁体   English

如何将stdout输出重定向到新的Vim选项卡?

[英]How to redirect stdout output to a new Vim tab?

I'm editing an XML file in Vim, and then I want to transform it a plain-text file with xsltproc, which by default outputs to a stdout (something like : !xsltproc TXTRULE.XSL %). 我正在Vim中编辑XML文件,然后我想用xsltproc将它转换为纯文本文件,默认输出为stdout(类似于:!xsltproc TXTRULE.XSL%)。 Is it possible to redirect that xsltproc output to a new tab in Vim without creating any intermediate files? 是否可以将该xsltproc输出重定向到Vim中的新选项卡而无需创建任何中间文件?

(I've tried to read :help redir and some wiki notes , but still can't get it. would be greateful for some kind of simple example.) (我试过阅读:帮助redir和一些wiki笔记 ,但仍然无法得到它。对于某种简单的例子会很有用。)

You can use read like in the following: 您可以使用如下所示的读取

:read !ls

Obviously you should change ls with your command. 显然你应该用你的命令改变ls If you want to open a new tab prepend tabnew with a bar to the command like: 如果要打开一个新选项卡,请在tabnew前面添加一个条形栏,如:

:tabnew|read !ls

To expand on lucapette's answer , you could create a map like this: 要扩展lucapette的答案 ,你可以创建一个这样的地图:

:map ,x :tabnew<Bar>read !xsltproc TXTRULE.XSL #

# expands to the previously opened buffer, which is the file you were editing, while % would expand to the new buffer opened by :tabnew . #展开到先前打开的缓冲区,即您正在编辑的文件,而%将扩展到由:tabnew打开的新缓冲区。

<Bar> has to be used instead of | 必须使用<Bar>代替| , because otherwise, the :map command would end at the | ,因为否则, :map命令将以|结束 .

I am using the following to view my program outputs (very useful for a makefile with a make run rule) 我使用以下内容来查看我的程序输出(对于带有make run规则的makefile非常有用)

It opens a new tab next to current one only if one was not already opened before for that purpose: 只有当之前尚未打开一个新选项卡时,它才会打开一个新选项卡:

fu! RedirStdoutNewTabSingle(cmd)
  let a:newt= expand('%:p') . ".out.tmp"
  tabnext
  if expand('%:p') != a:newt
    tabprevious
    exec "tabnew" . a:newt
  else
    exec "%d"
  endif
  exec 'silent r !' . a:cmd
  set nomodified
endfunc

au FileType xml noremap <buffer> <F6> :call RedirStdoutNewTabSingle("xsltproc")<CR>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM