I made in my vimrc an abbreviation because I want to only write "foo" to write "bar", and thence I mapped "bar" to "NOPE" so that I would be punished if I tried to write directly "bar".

iabbrev foo bar
inoremap bar NOPE

The result though is when I write "foo", vim replaces it with "NOPE". How can I work on my muscle memory and punish me if I write "bar", because the way I did it does not seem to work ? Note that I usually do not want to type "bar" alone, but "bar{}", and thence an abbreviation like "iabbrev bar NOPE" would not work for me.

  • Why wouldn't it work? What do you expect to happen when you type bar{}? – muru Feb 14 '15 at 17:36
  • Close voters: This question is perfectly on-topic. How is it not about Ubuntu? – Seth Feb 14 '15 at 21:33
  • Don't use Vim so don't have a clue - is this helpful/relevant? (N.B. for some reason your question is being voted as 'unclear' in the close vote queue) – Wilf Feb 21 '15 at 20:19

In trying this, I found typing bar would replace but barf would not. The f is a different type of character from {.

If you add { to non-keyword characters by :set iskeyword+={ it works. This may have other consequences as described by :help iskeyword.

Another way might be to write a function as described in :help abbreviations.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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