Save and run at the same time in Vim

前端 未结 12 650
悲哀的现实
悲哀的现实 2021-01-30 03:13

I do a lot of Python quick simulation stuff and I\'m constantly saving (:w) and then running (:!!). Is there a way to combine these actions?

Maybe a "save and run&qu

12条回答
  •  我在风中等你
    2021-01-30 03:41

    I got the following from the Vim tips wiki:

    command! -complete=file -nargs=+ shell call s:runshellcommand()
    function! s:runshellcommand(cmdline)
      botright vnew
      setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
      call setline(1,a:cmdline)
      call setline(2,substitute(a:cmdline,'.','=','g'))
      execute 'silent $read !'.escape(a:cmdline,'%#')
      setlocal nomodifiable
      1
    endfunction
    

    But I changed new to vnew on the third line, and then for Python I have the following:

    map  :w:Shell python %
    

    Hitting F9 saves, runs, and dumps the output into a new vertically split scratch buffer, for easy yanking, saving, etc. It also hits c-w so I only have to press h/c to close it and move back to my code.

提交回复
热议问题