I use vim for writing code and often accidentally type this:

funciton() {}

instead of

function() {}

It's irritating and I know vim supports iabbrev for this purpose. But it doesn't work in this case since there is not a space after the word function. Blame our coding standards I guess. But is there a way either out-of-the-box or through a plugin to automatically correct such a thing?

  • It is strange, because iabbr funciton function works fine here when typing funciton( -- it doesn't requires any spaces.
    – mMontu
    Mar 4 '16 at 19:25
  • @mMontu it didn't work for me. Edit - worked with plugins/vimrc disabled.
    – Al.G.
    Mar 4 '16 at 19:32
  • @Al.G. maybe some plugin/configuration? Because it worked fine here even in vanilla vim. Try starting vim with vim -u NONE -U NONE -N -i NONE, them try the contents of my previous comment.
    – mMontu
    Mar 4 '16 at 19:34
  • In my case it's definitely a plugin, but it'd be hard to tell of 20 which one is causing it. Do you know about some quick way of disabling them one by one? (except set rtp-=~/.vim/pluginname)
    – Al.G.
    Mar 4 '16 at 19:57

As mentioned in the comments, the simple abbreviation iabbr funciton function works on my setup and in vanilla vim, without any need of type space -- it is triggered by the (.

Your problem is being caused by some specific configuration/plugin; thus you should follow the procedure described on Vim-FAQ 2.5:

2.5. I have a "xyz" (some) problem with Vim. How do I determine it is a problem with my setup or with Vim? / Have I found a bug in Vim?

First, you need to find out, whether the error is in the actual runtime files or any plugin that is distributed with Vim or whether it is a simple side effect of any configuration option from your .vimrc or .gvimrc. So first, start vim like this:

vim -u NONE -U NONE -N -i NONE

this starts Vim in nocompatible mode (-N), without reading your viminfo file (-i NONE), without reading any configuration file (-u NONE for not reading .vimrc file and -U NONE for not reading a .gvimrc file) or even plugin.

If the error does not occur when starting Vim this way, then the problem is either related to some plugin of yours or some setting in one of your local setup files. You need to find out, what triggers the error, you try starting Vim this way:

vim -u NONE -U NONE -N

If the error occurs, the problem is your .viminfo file. Simply delete the viminfo file then. If the error does not occur, try:

vim -u ~/.vimrc --noplugin -N -i NONE

This will simply use your .vimrc as configuration file, but not load any plugins. If the error occurs this time, the error is possibly caused by some configuration option inside your .vimrc file. Depending on the length of your vimrc file, it can be quite hard to trace the origin within that file.

The best way is to add :finish command in the middle of your .vimrc. Then restart again using the same command line. If the error still occurs, the bug must be caused because of a setting in the first half of your .vimrc. If it doesn't happen, the problematic setting must be in the second half of your .vimrc. So move the :finish command to the middle of that half, of which you know that triggers the error and move your way along, until you find the problematic option. If your .vimrc is 350 lines long, you need at a maximum 9 tries to find the offending line (in practise, this can often be further reduced, since often lines depend on each other).

If the problem does not occur, when only loading your .vimrc file, the error must be caused by a plugin or another runtime file (indent autoload or syntax script). Check the output of the :scriptnames command to see what files have been loaded and for each one try to disable each one by one and see which one triggers the bug. Often files that are loaded by vim, have a simple configuration variable to disable them, but you need to check inside each file separately.

  • For me, the culprit was vim-smartinput, which completes parentheses, brackets, etc. Not surprising I guess, but it leaves me without a way to do one thing or the other. Thanks for the help. It didn't occur to me that it could be a plugin until you mentioned it.
    – user37078
    Mar 4 '16 at 20:04
  • @user37078 glad you figured it out.
    – mMontu
    Mar 7 '16 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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