In vim, you can combine the ": w" and the current script current together?

Every time I edit my python script, I have to type :wand then :!./myscript.py(run the current script).

Is it possible to combine these two teams?

+4
source share
3 answers

Write this in your .vimrc:

function! SaveAndRun()
    w
    !%:p
endfunction

nmap <F2> :call SaveAndRun()<cr>

and it will execute the current file when you press f2 in normal mode.

+6
source

Define a function in .vimrc, and then define a command to call it.

function DoMyStuff()
    :w
    :!./myscript.py
endfunction

command W exec DoMyStuff()

Then you can call it with :W.

, , !! . .

:w | !!
+5

Yes, you can use the pipe symbol between the commands:

: w |! ./ myscript.py

+4
source

Source: https://habr.com/ru/post/1541205/


All Articles