简体   繁体   中英

How to create a command in vim that accesses the current filename?

I would like to create an individual vim command that does the following:

  1. save the current file
  2. run the current file with python

Currently I have to do it like this:

:w

:! python3 {filename}

Instead, I would like to do this:

:pyRun

or something similar

You can chain commands with |. So

:w | ! python3 %

will save the buffer and run it with python3.

See :help :bar and :help c_% for more information.

You can create a command for this like:

:command PyRun execute 'w <bar> ! python3 %'

Note that custom commands in vim have to start with an uppercase letter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM