2016-03-21 107 views
1

我正在試圖發送一個字到一個外部命令。我做了一些挖掘,但不能有一個工作解決方案。我學會了使用<cword>,但似乎無法將當前單詞傳遞給外部命令。Vim在光標下發送一個字到外部命令

這裏是我的命令:

nmap <silent> <F8> :!start test.exe s/\(<c-r>=expand("<cword>")<cr>\)/ 

它所做的就是獲取當前光標下的單詞,並把它傳遞給TEST.EXE。有人可以幫忙嗎?

更新

這裏就是我想要的目的。我在代碼中有函數名。

a = 0 
b = 1 
c = add_function(a,b) 

我想用一句話下光標通過add_function到自定義可執行我。因此,將推出TEST.EXE,並通過以下事項:

open, 'add_function' 

enter image description here

我試過上面的Vim命令,但它確實工作。

回答

4

我不知道你的映射問題是這樣什麼,如果我刪除<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> 
0

再添加一個 「CR」 運行外部程序

nmap <silent><F8> :!start test.exe s/\(<c-r>=expand("<cword>")<cr><cr>\)/ 

End i t最好重寫成

nnoremap <silent><F8> :!start test.exe %s/\(<c-r>=expand("<cword>")<cr><cr>\)/ 
+0

雖然這段代碼可能會回答這個問題,但提供關於_why_的附加上下文更好地改善了它的長期價值。 –