Search code examples
vimvim-plugin

Creating imaps in vim that don't cause to much of a delay


I'm working on a little vim plugin for a new language. I'm currently working on some cool effects to change some characters and words into badass unicode character such as \ turns into λ.

I now want to make not turn into ¬ but this causes some complications since I cant just match on not since that would cause a word like nottingham to turn into ¬tingham so I created the imap:

inoremap <space>not<space> ¬

But this causes an annoying delay every time space is pressed. Is there anyway to fix this?

NOTE: I'm not using conceal since it causes the characters to flip back and fourth and it messes with the highlighting.


Solution

  • Use an abbreviation for this:

    :abbrev not ¬
    

    For the "space before 'not' part":
    from :help abbreviations ('not' is a full-id abbreviation, see the help for all abbreviation types):

    The characters before the cursor must match the abbreviation.  Each type has
    an additional rule:
    
    full-id   In front of the match is a non-keyword character, or this is where
              the line or insertion starts.  Exception: When the abbreviation is
              only one character, it is not recognized if there is a non-keyword
              character in front of it, other than a space or a tab.
    

    For the "space after 'not' part":

    An abbreviation is only recognized when you type a non-keyword character.
    This can also be the <Esc> that ends insert mode or the <CR> that ends a
    command.