10

vim で挿入モードの場合:

foo b[a]r

カーソル[]位置を示す

通常モードに戻ります。カーソルは 1 つ左の位置に移動します。

foo [b]ar

これの利点はありますか?

4

5 に答える 5

6

VIM FAQから:

10.2. In insert mode, when I press the <Esc> key to go to command mode, the
 cursor moves one character to the left (except when the cursor is on
 the first character of the line). Is it possible to change this
 behavior to keep the cursor at the same column?

No. It is not possible to change this behavior. The cursor is *always*
positioned on a valid character (unless you have virtual-edit mode
enabled). So, if you are appending text to the end of a line, when you
return to command mode the cursor *must* drop back onto the last character
you typed. For consistency sake, the cursor drops back everywhere, even if
you are in the middle of a line.

You can use the CTRL-O command in insert mode to execute a single ex
command and return back to insert mode without moving the cursor column.

.vimrc でこの動作を変更し、EOL でのみ左に配置したい場合は、このvim のヒントを参照してください。

于 2013-07-31T16:20:59.340 に答える
5

最初の「状態」が間違っています。これは挿入モードで得られるものです。

bar[]

挿入モードでは、通常モードではカーソルが文字のにありますが、カーソルは文字の間にあります。挿入モードを終了するとき、カーソル文字の上にある必要があります。それは何の文字でしょうか? 挿入モードカーソルの左側にあるものですか、それとも右側にあるものですか? Vim はどちらの側が良いかをどのように判断することになっていますか?

ヒントの 1 つは、挿入モードに入るコマンドです。挿入モードを終了すると、おそらくi左側にカーソルが残り、右側にカーソルが残る可能性がありますa。しかし、最後に入力した文字の右側にある文字にカーソルを合わせるとはどういう意味でしょうか?

とにかく、挿入モードはテキストを挿入するためだけのものです。i<Esc>またはa<Esc>意味がなく、実用的な目的を果たしません。一方で:

Lorem[] dolor sit amet.
Lorem ipsum[] dolor sit amet.
<Esc>
Lorem ipsu[m] dolor sit amet.

以下よりもはるかに理にかなっています。

Lorem[] dolor sit amet.
Lorem ipsum[] dolor sit amet.
<Esc>
Lorem ipsum[ ]dolor sit amet.

そうじゃない?

于 2013-07-31T16:23:55.560 に答える
3

入力するだけに勝る直接的な利点はありませんh

観測された左への移動は、VIM の規則の副産物です。挿入モードは常に「左」のままにしておきます。これは非常に便利だと思います。

挿入モードに入るには多くの方法があり、いくつかの挿入を行った後、どのように挿入モードに入ったかではなく、どのように終了するかを気にするので便利です。

この動作を変更する方法があります。これらの SE の投稿:

于 2013-07-31T15:26:18.187 に答える
2

たとえば、挿入モードでない場合は bar[] が ba[r] になる必要がありますが、常に発生する必要はありません。

于 2013-07-31T15:26:43.557 に答える