How to execute file I'm editing in Vi(m)

后端 未结 13 1850
悲哀的现实
悲哀的现实 2020-12-04 05:45

How to execute file that I\'m editing in Vi(m) and get output in split window (like in SciTE)?

Of course I could execute it like that:

:!scriptname
<         


        
13条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 06:13

    Based on @SethKriticos and @Cyril answers I now use the following:

    function! Setup_ExecNDisplay()
      execute "w"
      execute "silent !chmod +x %:p"
      let n=expand('%:t')
      execute "silent !%:p 2>&1 | tee ~/.vim/output_".n
      " I prefer vsplit
      "execute "split ~/.vim/output_".n
      execute "vsplit ~/.vim/output_".n
      execute "redraw!"
      set autoread
    endfunction
    
    function! ExecNDisplay()
      execute "w"
      let n=expand('%:t')
      execute "silent !%:p 2>&1 | tee ~/.vim/output_".n
      " I use set autoread
      "execute "1 . 'wincmd e'"
    endfunction
    
    :nmap  :call Setup_ExecNDisplay()
    :nmap  :call ExecNDisplay()
    

    Use F9 to setup the new window and F2 to execute your script and tee to your output file.

    I also added the script name to the output file name, so that you can use this for multiple scripts at the same time.

提交回复
热议问题