gpt4 book ai didi

java - Vim key mapping compile and run for Java and C code

转载 作者:行者123 更新时间:2023-11-30 08:23:55 24 4
gpt4 key购买 nike

这是我的 .vimrc 中的行:

autocmd FileType python nnoremap <buffer> <F9> :exec '!python' shellescape(%)<cr>
autocmd FileType java nnoremap <buffer> <F9> :exec '!javac' shellescape(%) && '!java' shellescape(%:r)<cr>
autocmd FileType c,cpp nnoremap <buffer> <F9> :exec '!gcc' shellescape(%) && './a.out'<cr>

Python map 执行良好。Java 映射可以正常编译,但无法运行。我不完全确定我的语法是否正确。我不知道 map 的 C 版本发生了什么......它一直显示消息:

"error: Class names, 'test.C,test', are only accepted if annotation processing is explicitly requested"

有人知道这是怎么回事吗?

最佳答案

你是对的,语法有点错误(对所有人来说!)。如果你打算发出两个 :!调用,这些必须用 | 分隔(在映射中转义了 <Bar>),而不是 && :

autocmd FileType java nnoremap <buffer> <F9> :exec '!javac' shellescape(%) <Bar> exec '!java' shellescape(%:r)<cr>

但最好只调用一次: &&然后必须引用,以便由 :! 启动的 shell 对其进行评估, 不是 Vim:

autocmd FileType java nnoremap <buffer> <F9> :exec '!javac' shellescape(%) '&& java' shellescape(%:r)<cr>

此外,特别%关键字只能在命令行中直接识别,而不是在 :execute 中使用它时表达。你需要用 expand() 包装它.哦,还有shellescape()应该为适当的 :! 接收一个附加标志逃跑。

autocmd FileType java nnoremap <buffer> <F9> :exec '!javac' shellescape(expand('%'), 1) '&& java' shellescape(expand('%:r'), 1)<cr>

关于java - Vim key mapping compile and run for Java and C code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23292917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com