![Vim の " と ( 内の編集に違いがあるのはなぜですか?](https://rvso.com/image/1288688/Vim%20%E3%81%AE%20%22%20%E3%81%A8%20(%20%E5%86%85%E3%81%AE%E7%B7%A8%E9%9B%86%E3%81%AB%E9%81%95%E3%81%84%E3%81%8C%E3%81%82%E3%82%8B%E3%81%AE%E3%81%AF%E3%81%AA%E3%81%9C%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
コマンドを実行すると、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は引用されたテキストを見つけようとするようだ行の先頭から検索する. そのため、行のどこにいても問題ありません。(ただし、カーソルが引用テキストの後ろにある場合は機能しないようです)