为什么 Vim 中“和(”里面的编辑有区别?

为什么 Vim 中“和(”里面的编辑有区别?

执行此命令时,ci"Vim 将编辑行中下一个带引号的字符串内的文本,即使光标位于引号之外。但是,执行ci(此命令时,只有当光标位于括号内时才有效。

为什么?可以ci(跳转到第一次出现的(asci"吗?

示例文本(使用 Erlang 语法)我正在玩的地方:

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

答案1

快速浏览文档(help v_aquotehelp 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 尝试通过以下方式找出引用的文本:从行首开始搜索。因此,您在哪一行并不重要。(但是,当您的光标位于引用文本之后时,它似乎不起作用)

相关内容