[英]Vim Send a Word under Cursor to External command
我正在尝试将Word发送给外部命令。 我做了一些挖掘工作,但没有一个可行的解决方案。 我了解了使用<cword>
但似乎无法将当前单词传递给外部命令。
这是我的命令:
nmap <silent> <F8> :!start test.exe s/\(<c-r>=expand("<cword>")<cr>\)/
它所做的只是获取光标下的当前单词并将其传递给test.exe。 有人可以帮忙吗?
更新资料
这是我想要达到的目标。 我在代码中有函数名称。
a = 0
b = 1
c = add_function(a,b)
我想在光标下使用word将add_function
传递给我拥有的自定义可执行文件。 这样它将启动test.exe,并通过以下命令:
open, 'add_function'
我尝试了上面的vim命令,但是它确实起作用。
我不知道你映射的问题是什么正因为如此 ,如果删除<silent>
我得到了我的CMDLINE:
:!start test.exe s/\(WORD\)/
您可能想要哪个? 它不会发送,因为您没有在末尾添加<Cr>
(并且由于<silent>
而未在命令行中显示)...
nnoremap <silent> <F8> :!start test.exe s/\(<c-r>=expand("<cword>")<cr>\)/<CR>
如果这不是您想要的,并且不是故意添加s/\\(..\\)/
,那么让我们从尝试通过仅回显Vim中的当前单词来获得最简单的工作映射开始:
nnoremap <F8> :echo shellescape(expand('<cword>'))<Cr>
然后将其展开以运行外部echo
命令:
nnoremap <F8> :execute ':!echo ' . shellescape(expand('<cword>'))<Cr>
然后将其展开以运行您的start text.exe
:
nnoremap <F8> :execute ':!start test.exe' . shellescape(expand('<cword>'))<Cr>
最后添加<silent>
:
nnoremap <silent> <F8> :execute ':!start test.exe' . shellescape(expand('<cword>'))<Cr>
再添加一个“ cr”以运行外部程序
nmap <silent><F8> :!start test.exe s/\(<c-r>=expand("<cword>")<cr><cr>\)/
最终最好将其重写为
nnoremap <silent><F8> :!start test.exe %s/\(<c-r>=expand("<cword>")<cr><cr>\)/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.