Ubuntu – How to run a script from within the vim editor

command lineeditorscriptsvim

When within vim (the editor I use mostly because of the terminal integration), I want to run my script (e.g. Python or Javascript) from within vim.

I do not mind if it opens a new window, I would just like to know if there is an editor command for save/run. TNX1.0E6,

Best Answer

You can run commands inside of vim with !

:!echo "hello"

The symbol % is a shortcut for the name of the current open file, so you can execute your current file with

:!%

The console output will appear, and you press enter to return to editing your file

You can add a keybind to save and run in your ~/.vimrc

nnoremap <F5> <esc>:w<enter>:!%:p<enter>
inoremap <F5> <esc>:w<enter>:!%:p<enter>
Related Question