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

后端 未结 13 1794
悲哀的现实
悲哀的现实 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 <F6> :w<CR>:silent !chmod 755 %<CR>:silent !./% > .tmp.xyz<CR>
         \ :tabnew<CR>:r .tmp.xyz<CR>:silent !rm .tmp.xyz<CR>:redraw!<CR>
    

    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<CR>                             write current buffer
    :silent !chmod 755 %<CR>           make file executable
    :silent !./% > .tmp.xyz<CR>        execute file, redirect output
    :tabnew<CR>                        new tab
    :r .tmp.xyz<CR>                    read file in new tab
    :silent !rm .tmp.xyz<CR>           remove file
    :redraw!<CR>                       in terminal mode, vim get scrambled
                                       this fixes it
    
    0 讨论(0)
提交回复
热议问题