I'm new to vim and trying to configure vim for my coding learning course. I tried these very basic inoremap lines in my ~/.vimrc, and there are also similar lines for <>'", but none of them works.

inoremap { {}<ESC>i<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap {{ {
inoremap {} {}

I even deleted all the lines in the .vimrc except these inoremap lines, still no effect, meaning when I hit {, I don't get its pair }. I know there are plugins that may be more powerful, but I don't want my .vimrc to be messy and become unmanageable therefore I'd really like the native features work out for me, as a starting point. After all I don't need very fancy functions at the moment. Helps are appreciated.

By the way, I use FreeBSD, but I don't expect the vim configuration is so much system dependent.

  • If ypu keep only the first do you have the problem? One "problem' I see with your mapping is that it forces vim to wait for more keystroke to know what to do. Apr 10, 2022 at 3:46
  • Yes. Keeping only first line gives me no difference, still no closing brace.
    – D.W
    Apr 10, 2022 at 6:06
  • Could you add the set nocompatible line at the start of your .vimrc file? Apr 10, 2022 at 6:19
  • Your first map would put cursor before {, while I think you want it to be inside curly braces. For that, following should do the job inoremap { {}<ESC>i
    – Maxim Kim
    Apr 10, 2022 at 6:28
  • It seems to work fine on vim 8.2. Can you tell us which version of vim you are using? You can get that information by typing the command :version Apr 10, 2022 at 6:35

1 Answer 1


It turns out the problem is with the system wide vimrc that I tweaked not long ago, which I think overrides the user level .vimrc. I just replaced the system wide vimrc with default one now the auto completion in ~/.vimrc works as desired. Don't know which settings in the /usr/local/etc/vim/vimrc were causing the problem though. Now I have following mapping lines in .vimrc:

inoremap { {}<ESC>i
inoremap {<CR> {<CR>}<ESC>O
inoremap {{ {
inoremap {} {}

Similar goes for []()"'.

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.