views:

147

answers:

7

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?

+4  A: 

Try to remember to always leave vim in normal mode.

Drew Wagner
+2  A: 

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.

Drew Wagner
+7  A: 

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
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.
Drew Wagner
+11  A: 

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
This is soooo coool.... +1 million
Stefano Borini
And if that's not enough, replace `set [no]cursorline` with `colors [desert|default]`
too much php
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.
Drew Wagner
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!
Drew Wagner
+1  A: 

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
+2  A: 

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
A: 

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
Drew Wagner