[Description]
There is often a requirement that in the Linux command line, one hopes not to deviate from the script file currently edited under Vim run tests (such as sometimes printing a thing)
For a single language like Python, I know,<leader>r :! python %<cr>
I know that shell can be called in Vim, but how do multiple languages map to a shortcut key (initially drafted as < Leader>r)?
The basic idea is to use
autocmd
According to the type of the currently buffered file or the type of syntaxmap
Orders.For example, if you only need to compile/execute the current file, you can do so in your
vimrc
Add the following to the file for each different file type:autocmd FileType sometype nnoremap <buffer> <F5> :w<CR>:! somecompiler % <CR>
For python, it is
autocmd FileType python nnoremap <buffer> <F5> :w<CR>:! python % <CR>
among them
<F5>
Can be changed to other keys you want to map, such as<leader>r
.
If you need to cross-platform, please refer toHere.
If you need more advanced functions, such as multi-file compilation, running part of the code in the file, you need to write your own VIM script. Python can be referred toHere.