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
autocmdAccording to the type of the currently buffered file or the type of syntax
For example, if you only need to compile/execute the current file, you can do so in your
vimrcAdd 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>
<F5>Can be changed to other keys you want to map, such as
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.