简体   繁体   中英

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 %). Is it possible to redirect that xsltproc output to a new tab in Vim without creating any intermediate files?

(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.)

You can use read like in the following:

:read !ls

Obviously you should change ls with your command. If you want to open a new tab prepend tabnew with a bar to the command like:

:tabnew|read !ls

To expand on lucapette's answer , you could create a map like this:

: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 .

<Bar> has to be used instead of | , because otherwise, the :map command would end at the | .

I am using the following to view my program outputs (very useful for a makefile with a make run rule)

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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