mirror of
https://github.com/amix/vimrc
synced 2025-02-28 14:12:51 +08:00
Added feature to execute code directly from vim
included support for: C, C++, Java, Python, Bash, Go and HTML
This commit is contained in:
parent
92dab794c6
commit
66a6ff5c98
@ -343,6 +343,15 @@ Shortcuts using `<leader>` instead of special characters:
|
||||
map <leader>sa zg
|
||||
map <leader>s? z=
|
||||
|
||||
### Running Code
|
||||
To run code directly from vim, press `F5`. The currently open code will execute without you having to type anything.
|
||||
|
||||
Can be used to execute code written in C, C++, Java, Python, Go, Octave, Bash scripts and HTML. To edit how you want your code to be executed, make changes in the file
|
||||
```
|
||||
|
||||
~/vim_runtime/vimrcs/run_code.vim
|
||||
|
||||
```
|
||||
|
||||
### Cope
|
||||
Query `:help cope` if you are unsure what cope is. It's super useful!
|
||||
|
@ -10,7 +10,7 @@ source $1/vimrcs/basic.vim
|
||||
source $1/vimrcs/filetypes.vim
|
||||
source $1/vimrcs/plugins_config.vim
|
||||
source $1/vimrcs/extended.vim
|
||||
|
||||
source $1/vimrcs/run_code.vim
|
||||
try
|
||||
source $1/my_configs.vim
|
||||
catch
|
||||
|
@ -9,7 +9,7 @@ source ~/.vim_runtime/vimrcs/basic.vim
|
||||
source ~/.vim_runtime/vimrcs/filetypes.vim
|
||||
source ~/.vim_runtime/vimrcs/plugins_config.vim
|
||||
source ~/.vim_runtime/vimrcs/extended.vim
|
||||
|
||||
source ~/.vim_runtime/vimrcs/run_code.vim
|
||||
try
|
||||
source ~/.vim_runtime/my_configs.vim
|
||||
catch
|
||||
|
27
vimrcs/run_code.vim
Normal file
27
vimrcs/run_code.vim
Normal file
@ -0,0 +1,27 @@
|
||||
map <F5> :call CompileRun()<CR>
|
||||
imap <F5> <Esc>:call CompileRun()<CR>
|
||||
|
||||
func! CompileRun()
|
||||
exec "w"
|
||||
if &filetype == 'c'
|
||||
exec "!gcc % -o %<"
|
||||
exec "!time ./%<"
|
||||
elseif &filetype == 'cpp'
|
||||
exec "!g++ % -o %<"
|
||||
exec "!time ./%<"
|
||||
elseif &filetype == 'java'
|
||||
exec "!javac %"
|
||||
exec "!time java -cp %:p:h %t:r"
|
||||
elseif &filetype == 'sh'
|
||||
exec "!time bash %"
|
||||
elseif &filetype == 'python'
|
||||
exec "!time python %"
|
||||
elseif &filetype == 'html'
|
||||
exec "!google-chrome % &"
|
||||
elseif &filetype == 'go'
|
||||
exec "!go build %<"
|
||||
exec "!time go run %"
|
||||
elseif &filetype == 'matlab'
|
||||
exec "!time octave %"
|
||||
endif
|
||||
endfunc
|
Loading…
Reference in New Issue
Block a user