Save and run at the same time in Vim

前端 未结 12 536
悲哀的现实
悲哀的现实 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:53

    Okay, the simplest form of what you're looking for is the pipe command. It allows you to run multiple cmdline commands on the same line. In your case, the two commands are write `w` and execute current file `! %:p`. If you have a specific command you run for you current file, the second command becomes, e.g. `!python %:p`. So, the simplest answer to you question becomes:

    :w | ! %:p
     ^ ^ ^
     | | |--Execute current file
     | |--Chain two commands
     |--Save current file
    

    One last thing to note is that not all commands can be chained. According to the Vim docs, certain commands accept a pipe as an argument, and thus break the chain...

提交回复
热议问题