Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have

cmap w!! %!sudo tee > /dev/null %

in my .vimrc.

When I type a w while writing in the vim command line (after :), the cursor stays over the w for a few seconds before moving right. This sometimes breaks my train of thought and confuses me for a few seconds. Is there a way to make the mapping happen when pressing enter after the command so that it doesn't temporarily "eat" the w every time I press it?

(Incidentally, this mapping also makes w!! expand when I'm typing a search query which isn't annoying in practice (except for the fact that the w is similarly delayed) but seems strange.)

share|improve this question
Is this from stackoverflow.com/a/7078429 by any chance? – Tshepang Mar 15 '13 at 9:58

I just tried:

cabbrev w!! %!sudo tee > /dev/null %

which delays the expansion until pressing space or enter, but strangely writes the password prompt on top of the expansion of the command, so the command line looks like

Password:ee > /dev/null %

(and works correctly if you ignore the display error).

share|improve this answer
(Anyone know why that happens?) – Ben Alpert Jun 6 '12 at 16:56

You can change this behaviour with the timeout and timeoutlen options. To quote the documentation:

If the 'timeout' option is on (which is the default) Vim will only wait for one second (or as long as specified with the 'timeoutlen' option). After that it assumes that the character is to be interpreted as such.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.