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

后端 未结 13 1851
悲哀的现实
悲哀的现实 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:16

    I have a shortcut for that in my vimrc:

    nmap  :w:silent !chmod 755 %:silent !./% > .tmp.xyz
         \ :tabnew:r .tmp.xyz:silent !rm .tmp.xyz:redraw!
    

    This writes the current buffer, makes the current file executable (unix only), executes it (unix only) and redirects the output to .tmp.xyz, then creates a new tab, reads the file and then deletes it.

    Breaking it down:

    :w                             write current buffer
    :silent !chmod 755 %           make file executable
    :silent !./% > .tmp.xyz        execute file, redirect output
    :tabnew                        new tab
    :r .tmp.xyz                    read file in new tab
    :silent !rm .tmp.xyz           remove file
    :redraw!                       in terminal mode, vim get scrambled
                                       this fixes it
    

提交回复
热议问题