1

Vim で時間を節約するために、あるアイデアを思いつきました。通常モードと挿入モードの両方で :w キーバインディングを Esc にマップします。ただし、挿入モードでのみ機能しますが、通常モードでは、新しいファイルを開くと面倒になります。これは私が.vimrcに追加したものです:

:inoremap <Esc> <Esc>:w<CR>
:nnoremap <Esc> :w<CR>

最初のコマンドだけで言ったように、うまくいきます。しかし、2番目のコマンドを追加すると、新しいファイルを開くと、特にキーがめちゃくちゃになります。たとえば、.vimrc に明示的に追加しましたが:

map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>

通常モードの 2 番目のコマンドを追加すると、上下左右のキーを押すと、挿入モードに入り、ABC D が追加されます。

私のアイデアを実現するのを手伝ってくれませんか?

4

2 に答える 2

3

Vim FAQ 10.9に関する情報が役立つ場合があります

10.9. When I use my arrow keys, Vim changes modes, inserts weird characters
     in my document but doesn't move the cursor properly. What's going on?

There are a couple of things that could be going on: either you are using
Vim over a slow connection or Vim doesn't understand the key sequence that
your keyboard is generating.

If you are working over a slow connection (such as a 2400 bps modem), you
can try to set the 'timeout' or 'ttimeout' option. These options, combined
with the 'timeoutlen' and 'ttimeoutlen' options, may fix the problem.

The preceding procedure will not work correctly if your terminal sends key
codes that Vim does not understand. In this situation, your best option is
to map your key sequence to a matching cursor movement command and save
these mappings in a file. You can then ":source" the file whenever you work
from that terminal.

For more information, read 

    |'timeout'|
    |'ttimeout'|
    |'timeoutlen'|
    |'ttimeoutlen'|
    |:map|
    |vt100-cursor-keys|

から:h vt100-cursor-keys:

Other terminals (e.g., vt100 and xterm) have cursor keys that send <Esc>OA,
<Esc>OB, etc. ...

したがって、おそらくnnoremap矢印Escのキーシーケンスでファイルを保存し、残りの文字は単独で解釈されているため、A挿入モードに入っています。

オプション'autowriteall'を使用するか、別のマッピングを使用してファイルを保存することを検討できます。これらは で定義されてい$VIMRUNTIME\mswin.vimます。

" Use CTRL-S for saving, also in Insert mode
noremap <C-S>       :update<CR>
vnoremap <C-S>      <C-C>:update<CR>
inoremap <C-S>      <C-O>:update<CR>

この:updateコマンドは に似て:wいますが、ファイルが変更されている場合にのみ書き込みます。

于 2013-07-05T16:28:57.923 に答える