為什麼 Vim 中的 edit inside " 和 ( 之間有區別?

為什麼 Vim 中的 edit inside " 和 ( 之間有區別?

執行命令時,ci"Vim 將編輯該行下一個帶有引號的字串內的文本,即使遊標位於引號之外。但是,ci(只有當遊標位於括號內時,此操作才有效。

為什麼?可以ci(讓跳到第一次出現的地方(ci"

範例文字(使用 Erlang 語法)我正在玩的地方:

    ?assertEqual({200, "OK"}, status(FirstResponse)),
%   ^
%   Here I'm expecting  ci(  to jump in to the parenthesis ( ci"  works)

答案1

快速瀏覽一下文件 ( help v_aquote, help v_iquote) 後,我傾向於說這是 中的錯誤ci",而不是 中的缺陷ci(。觀察到的行為與和ci(一致。ci{ci[

ci(也就是說,您可以透過此映射獲得所需的行為:

nnoremap ci( f(ci(

- - 編輯 - -

---(這個問題已遷移到超級用戶,我不是其中的成員)

根據是否(檢測到前面的函數/映射,以下函數/映射具有不同的行為。它解決了(a) (b)我原來的映射的問題(如評論中指出的)。但它可能仍然不完美......

function New_cib()
    if search("(","bn") == line(".")
        sil exe "normal! f)ci("
        sil exe "normal! l"
        startinsert
    else
        sil exe "normal! f(ci("
        sil exe "normal! l"
        startinsert
    endif
endfunction

nnoremap ci( :call New_cib()<CR>
nnoremap cib :call New_cib()<CR>

答案2

原因是:中括號、尖括號和大括號是成對出現的。因此,它們可以築巢。

單引號和雙引號一般不能嵌套(除了在帶有"$("something")"語法的 bash 腳本中,因此即使遊標不在文本對象內部也允許查找文本對象,因為不能有任何外部對象。

答案3

我認為"這是唯一以這種方式工作的文字對象,即選擇行上的下一個匹配模式。

幫助可能會解釋原因:

a"                          *v_aquote* *aquote*
a'                          *v_a'* *a'*
a`                          *v_a`* *a`*
        "a quoted string".  Selects the text from the previous
        quote until the next quote.  The 'quoteescape' option
        is used to skip escaped quotes.
        Only works within one line.
        When the cursor starts on a quote, Vim will figure out
        which quote pairs form a string by searching from the
        start of the line.
        Any trailing white space is included, unless there is
        none, then leading white space is included.
        When used in Visual mode it is made characterwise.
        Repeating this object in Visual mode another string is
        included.  A count is currently not used.

顯然 Vim 試圖找出引用的文本從行首開始搜尋。所以無論你在哪裡上網都沒關係。 (但是,當遊標位於引用文字之後時,它似乎不起作用)

相關內容