I know about

autocmd FileType <TYPE> inoremap <MAPPING> 

for files like *.html. But i would like to create some keybinds for within my .vimrc like this:

autocmd FileType vimrc inoremap ;; autocmd<Space>FileType ...

This should obviously only work inside the vimrc File as it does not make sense elsewhere. Using vimrc as FileType does not work though. Any suggestions?


I have also tried

au Bufread,BufNewFile *.vimrc setfiletype vimrc


au Bufread,BufNewFile .vimrc setfiletype vimrc

which works fine for some custom filetypes I use, but not for .vimrc. I am aware that dot-files are not the same as file endings, but it was worth a shot.

1 Answer 1


You're almost there.

First, you need to know that unless you are creating a new filetype (for example, as a subtype of the vim filetype) there is no "vimrc" filetype. .vimrc files are Vim scripts, and should already automatically be detected as such.

This means you want to use one of the autocmd triggers in the last half of your question, but with the command in the first half. You also probably want to make the mapping buffer-local:

au Bufread,BufNewFile .vimrc inoremap <buffer> ;; autocmd<Space>FileType ...

See: :help :map-<buffer>

  • Thank you very much, this is exactly what I was looking for. Still new to vim, but I am already amazed by what one can do with it.
    – omnesia
    Jul 26, 2017 at 7:49

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.