4

I frequently make mode errors while using vim, i.e. I'll start typing text while in Normal mode, or start typing commands while in Insert mode. I understand this goes away with time as vim's quirks seep into your bones, but are there any ways to speed the process?

Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
  • 2
    I usually just mash Escape any time I'm not sure what state I'm in. It never really hurts! – Mike Daniels Oct 11 '10 at 19:36
  • possible duplicate of [What is the best way to force yourself to master vi?](http://stackoverflow.com/questions/74625/what-is-the-best-way-to-force-yourself-to-master-vi) – richq Oct 11 '10 at 19:36
  • 2
    I don't think it's a duplicate. This question is very specific, the other is more general. – Stefano Borini Oct 11 '10 at 19:41

7 Answers7

13

I use these autocmd's to highlight the entire line containing the cursor while in insert mode, and not while in normal mode:

if v:version >= 700
  autocmd InsertEnter * set cursorline
  autocmd InsertLeave * set nocursorline
endif

This provides a little bit more visual feedback about the mode.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
  • 1
    And if that's not enough, replace `set [no]cursorline` with `colors [desert|default]` – too much php Oct 11 '10 at 22:46
  • ooo... that's a neat idea. I think there will be a lot of variations on this. The autocmd InsertEnter, InsertLeave autocommands could be used to trigger a lot. – Andrew Wagner Oct 12 '10 at 00:11
  • I voted this up and selected it as the answer, but will have to post my variant as a separate answer since comments can't contain multi-line code blocks. Thanks! – Andrew Wagner Oct 13 '10 at 14:16
8

If you haven't done so already you can display the current mode by using :set showmode. That'll display -- INSERT -- in the status bar when in insert mode.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
  • I think this might be in the default configuration... I've never seen a vim that did not display the current mode in the status bar. – Andrew Wagner Oct 12 '10 at 00:09
5

Try to remember to always leave vim in normal mode.

Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
3

Switch "Esc" and "Caps Lock" keys.

If you accidentally click on "Caps Lock" you will start inputing commands that has nothing to do with what you like to do. It is annoying if you are an experienced user; if you are a beginner it may be a hassle to understand what went wrong.

Every time you need to press the Esc key you have to move you entire hand and to get your pinky finger to touch the Esc key and then replace the entire hand again. Some Vim users will tell you that after a while you get used to doing that and it is not a big deal. I think that argument falls short because you can pretty much get used to mapping any key any where. It is a matter of efficiency.

I believe "Esc" is used very frequently and "Caps Lock" is used seldomly if it is used at all.

So switching the two makes sense as it prevents errors and increases typing speed.

3hugger
  • 31
  • 1
2

With gvim, the cursor changes from a block to a vertical bar when going between modes. This at least gives you a little visual feedback.

Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
2

Insert mode should only be temporary. Normal mode is, as its name tells, the favourite mode for edition tasks.

Usually, you should spend more time in normal mode, and always hit ESC when you are done inserting something.

Maybe I speak only for myself, but now I have the habit of assuming that I am in normal mode at all times, and I am almost never wrong.

Benoit
  • 76,634
  • 23
  • 210
  • 236
0

Here is my variant of Ned's Answer. It toggles on window switches (window focus is another modal behavior that provides little visual feedback).

if v:version >= 700
    set cursorline cursorcolumn
    au WinLeave * set nocursorline nocursorcolumn
    au WinEnter * set cursorline cursorcolumn
    au InsertEnter * set nocursorline nocursorcolumn
    au InsertLeave * set cursorline cursorcolumn
endif

I use it with the zenburn color scheme, and I also turn off cursor blink:

if has("gui_running")
    colorscheme zenburn
    set guicursor+=a:blinkon0
endif
Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100