In my .vimrc i have :imap .. .<C-x><C-o> and it work as it should (double dot to open menu with fields).

But I also want to be able type text like [1..MAX] as you can see here vim will try use Omnicoplet to find fields in 1 what is nonsense.

is there way to write this map as

:imap ..<wait> .<C-x><C-o>

Where <wait> mean no keys is pressed for some time, after two dots. Other solution I thought is like

:imap .. .<C-x><C-o> :imap ..<any> ..<any>
Where <any> mean any key after two dots will be replace to that key and two dots before.

  • 1
    Why not just use inoremap <C-O> <C-x><C-o>? By the way, you really should use noremap versions of mappings. Look into that
    – 3N4N
    Oct 21, 2019 at 12:08
  • I mean, I can. But I also wonder if such way i show is possible.
    – wytrzeszcz
    Oct 21, 2019 at 12:10
  • You will probably have to play with :h 'timeoutlen' and :h 'ttimeoutlen', however these are global settings they can't be applied to only one mapping. (I know that we already have a question about that, I'll have to find it)
    – statox
    Oct 21, 2019 at 12:33

1 Answer 1


To implement your stated use case, the :imap ..<any> ..<any> would leverage Vim's built-in 'timeoutlen'; it's implementation wouldn't be so outrageous, there's only a limited set of available keys and you can use metaprogramming with a :for loop to build all these mappings. The biggest challenge here is enumerating all desired keys.

However, I doubt that this would be very useful. The completion popup would only open after that delay, so it will slow you down (unless you only intend to trigger that mapping if you're contemplating about the possible values, anyway) - completion is as much about saving typing than it is about showing alternatives.

As an alternative approach, I'd home in on try use Omnicoplet to find fields in 1 is nonsense. With a :help :map-expression, you can check the text before the cursor, and then either trigger completion (without delay!) or (e.g. in case of a digit) just return a literal . there. That condition can be as complex as you'd like (you could even query the syntax group and leverage syntax parsing of identifiers vs. other stuff), and should "do what I mean" in many cases.

For those special exceptions (that will always exist), I personally find it okay to actively avoid triggering the mapping, either by making a short pause when typing (. <pause> . in your case), or escaping one of the characters via i_CTRL-V: .<C-v>.

Your Answer

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

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