How to configure a "unified" shortcut key for running "Python, Ruby and other mainstream shell languages" in Vim?
淡淡烟草味
淡淡烟草味 2017-05-16 16:37:32
0
4
704

[Description]
There is often this demand: In the Linux command line, I hope to run the currently edited script file under the test without leaving Vim (such as sometimes printing something)

I know a single language such as Python,<leader>r :!python %<cr>

I know that the shell can be called in Vim, but how to map multiple languages ​​to one shortcut key (preliminarily planned to be <Leader>r)?

淡淡烟草味
淡淡烟草味

reply all(4)
洪涛

The basic idea is to use the autocmd根据当前缓冲的文件的类型或者语法的类型添加不同的map command.

For example, if you only need to compile/execute the current file, you can add the following in your vimrcfile for each different file type:

autocmd FileType sometype nnoremap <buffer> <F5> :w<CR>:!somecompiler % <CR>

For python, that’s

autocmd FileType python nnoremap <buffer> <F5> :w<CR>:!python % <CR>

Among them<F5>可以改成其他你想映射的键位,如<leader>r.


If you need cross-platform, you can refer to here.

If you need more advanced functions, such as multi-file compilation, running part of the code in the file, etc., you need to write your own VIM script. For python, please refer to here.

PHPzhong

Create a file in vim's fplugin directory [语言名].vim
Then write the corresponding language configuration into this file, vim will automatically load these configurations based on the file suffix

迷茫

Add execution permissions to the file and add
#!/bin/bash #!/usr/bin/python #!/usr/bin/ruby to the file header.
Every time you want to run:./ this file will be fine.

淡淡烟草味

Recommend you to use
vim-quickrun

map <leader>r :QuickRun<CR>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template