Vimscript中的bash换人 [英] bash substitutions in vimscript
问题描述
我如何使用映射的bash命令替换在的Vimscript
?
How can I use bash substitutions in mapped commands in vimscript
?
Vim却与&功放做工精良和反引号操作符。
Vim does work well with &&
operator but it does not like bash $(command)
operator and backticks operator.
在我的的.vimrc
我有这样一个简化的行:
In my .vimrc
I have such a simplified line:
nnoremap SOME_KEY :!java $(echo % | sed 's/\.java//') <CR>
我希望上运行pressing Java测试
命令 SOME_KEY
如果我当前文件是 Test.java
。
I would expect running java Test
command on pressing SOME_KEY
if my current file is Test.java
.
相反,它在下面的错误结果 E492:不是一个编辑命令:SEDS / \\ java中//')
Instead it results in the following error E492: Not an editor command: sed 's/\.java//')
什么是pssing在vim一个键$ P $执行的命令来使用bash换人的正确方法?有没有更好的方式做什么,我尽力去完成?
What is the correct way to use bash substitutions in commands executed on pressing a key in vim? Is there a better way to do what I try to accomplish?
推荐答案
您必须更换 |
与&LT;酒吧GT;
。
如果您插入 |
成映射VIM间$ P $点后人物|
作为新命令。
If you insert |
into a mapping vim interprets the characters after |
as a new command.
因此,在你的情况下,Vim正确地抱怨 SED的/ \\。java的//
是不是一个编辑命令。
Hence, in your case vim rightly complains about sed 's/\.java//'
isn't an editor command.
实现你的映射另一种方法是
Another way to implement your mapping would be
nnoremap SOME_KEY :call system("java $(echo ". expand('%') ." | sed 's/\.java//')")<CR>
这篇关于Vimscript中的bash换人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!