![](/img/trans.png)
[英]Replacing the equality operator (==) with the identity operator (===) in Vim
[英]Replacing a motion in operator mode
當它與操作員一起使用時,我試圖改變ge
運動的功能。 相反,它的目標詞的最后一個字符操作,我想它僅僅只工作,直到目標字的最后一個字符類似w
。
例子:
foo bar
^
當我在光標處使用dge
時,應該導致fooar
而不是foar
我對 Vimscript 一無所知,現在我非常依賴exe
。 我寫的這個快速嘗試似乎充滿了錯誤。 變量似乎根本無法正常工作。
我的主要想法是在操作員模式下鍵入 ge 時進行轉義,並希望使用正確的參數調用該函數。 然后在起始位置設置一個標記,向左移動一列(以確保它可以重復移動,即使這只是操作員模式),移動設置的ge
數量,然后向右移動一列(我的主要目標在這里)並刪除直到設置標記。
如果有人能指出我所犯的錯誤,將不勝感激!
function! FixGE(count, operator)
exe 'normal m['
exe 'normal h'
exe count.'normal ge'
exe 'normal l'
exe operator.'normal `['
endfunction
onoremap ge <esc>:call FixGE(v:prevcount, v:operator)<cr>
通過使用f
和t
運算符,可以在不更改ge
運動的情況下解決您的示例:
dTo
dF
(d + F + <空格> ) 如果您仍然覺得需要覆蓋ge
的默認行為,您應該檢查Ingo Karkat 的插件 CountJump:通過重復跳轉創建自定義動作和文本對象:
DESCRIPTION
Though it is not difficult to write a custom movement (basically a :map
that executes some kind of search or jump) and a custom text-object (an
:omap that selects a range of text), this is too complex for a novice user
and often repetitive.
這有點接近(未經測試):
function! FixGE(count, operator)
exe 'normal m['
exe 'normal h'
exe 'normal ' . a:count . 'ge'
exe 'normal l'
exe 'normal ' . a:operator . '`['
endfunction
onoremap ge <esc>:call FixGE(v:prevcount, v:operator)<cr>
函數參數必須使用:a
前綴(或符號,我認為)。 我知道count
是一個保留變量: :let count = 7
給出一個錯誤。 不過,我認為將其用作函數參數是可以的。
我還把:normal
放在兩行的開頭,而不是中間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.