更新时间:2023-01-31 12:44:54
这样的事情会工作。只要创建的文件类型自动命令的地图< F4>
或任何你想保存并编译和运行程序。它使用exec来构建该字符串,并使用shellescape逃脱的文件名。
Something like this would work. Just create filetype autocmd that map <F4>
or whatever you want to save and compile and run the program. It uses exec to build the string and uses shellescape to escape the file name.
autocmd filetype python nnoremap <F4> :w <bar> exec '!python '.shellescape('%')<CR>
autocmd filetype c nnoremap <F4> :w <bar> exec '!gcc '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>
autocmd filetype cpp nnoremap <F4> :w <bar> exec '!g++ '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>
%
是当前缓冲区的文件名。 %,R
是缓冲文件名不带扩展
%
is the current buffer filename. %:r
is the buffer filename without extension