Linux下vim编写python脚本一键运行
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
在Linux下,常常使用vim来编写脚本,但是每次编写完成后要退出再运行:python xxx.py才可以测试脚本,可在vim的配置文件中添加一些配置,即可编写完脚本后不用退出即可验证脚本的正确性(一键执行)。
- vim编辑器的配置文件为:/etc/vimrc
通过:sudo vim /etc/vimrc
打开vim的配置文件
在结尾添加如下内容即可指定F5
为测试脚本的快捷键:
注:此方式便于对脚本进行单元测试。
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
exec "!time python2.7 %"
exec "!time python3.6 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'mkd'
exec "!~/.vim/markdown.pl % > %.html &"
exec "!firefox %.html &"
endif
endfunc
- 示例
vim编写的脚本内容
vim编写完成后不退出直接按F5后结果:




A beautiful web dashboard for Linux
最近提交(Master分支:5 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
所有评论(0)