I saw this wonderful video and really love the config of it, which is why I wanted to replicate it.

The following line implements a double space keymapping which searches for the next <++>, deletes it and moves the cursor there while not putting it into the internal vim buffer.

inoremap <Space><Space> <Esc>/<++><Enter>"_c4l

It works perfectly, but there is one thing I would like to change: After pressing space once, it waits for approximately one second before actually moving the cursor in order to receive the second space. What I would like is that it does not wait for the second space but always runs the replacing "command" as soon as there are two spaces in a row. Is that possible somehow?

Thanks in advance,

Alexander Schoch

1 Answer 1


I don't think there's a really good solution for this: Vim doesn't keep track of previous keystrokes, so if you want your initial press to insert a space character immediately, Vim will have no idea that it did so by the second press.

You can tweak the length of time that Vim waits keypresses within mappings by changing the 'timeoutlen' option: if SpaceSpace is your only insert mode mapping you could probably even set this to a pretty low value as part of an InsertEnter autocommand, resetting it on InsertLeave. (See :help autocommand for details of these.)

Alternatively, you could set up an expression mapping for a single Space that checks to see if it is the second press by inspecting the contents of the buffer around the cursor, or you could set up a mapping that inserts a space character when you press the space bar but waits for the next keypress to see if it is also a space character before it returns.

If you want to attempt the former, you'll want to read:

  • :help :map-expression
  • :help getcurpos()
  • :help getline()

And for the latter, the following will be helpful:

  • :help feedkeys()
  • :help getchar()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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