Instead of putting the command mapping in your .vimrc , put that mapping in your ~/.vim/ftplugin/python.vim (Windows $HOME\vimfiles\ftplugin\python.vim ). If you do not have this file or directories, just create them. Thus, the key is displayed only when opening the .py file or any file with filetype=python , since you will only run this command in Python scripts.
For real display, I like being able to edit in Vim while the script is running. Based on @cazyas answer, I have the ftplugin\python.vim in ftplugin\python.vim (Windows):
noremap <F5> <Esc>:w<CR>:!START /B python %<CR>
This will run the current Python script in the background. For Linux, just change this to this:
noremap <F5> <Esc>:w<CR>:!python % &<CR>
jpyams Jan 01 '18 at 17:51 2018-01-01 17:51
source share