Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I make some additions to the regular runtime in my vim configuration. I add to rtp a directory where there are ftplugin directory, in which I have two files: c.vim and cpp.vim. In these files I determine a couple commands with the same name but different content which depends on the file, is it c and cpp file.

In c.vim:

execute "nnoremap <silent> ".g:formatterTrigger." :call Formatters#Uncrustify#C()<Cr>"

In cpp.vim:

execute "nnoremap <silent> ".g:formatterTrigger." :call Formatters#Uncrustify#Cpp()<Cr>"

But I see by scriptnames command that both these ft files are loaded. And the c.vim is loaded the first so in cpp files I have c commands. How to solve this?

share|improve this question
up vote 0 down vote accepted

Don't use runtimepath for that, the after directory (:h after-directory) is what you need.

Place those two files in ~/.vim/after/ftplugin.

share|improve this answer
The problem is that vim loads both c.vim and cpp.vim for cpp sources. – user14416 May 4 '13 at 0:21
Did you try it before writing that comment? Since you use the same shortcut (g:formatterTrigger), the cpp mapping overwrites the c mapping so you get only the cpp mapping in cpp and only the c mapping in c. – romainl May 4 '13 at 5:56

Due to their similarity, the cpp filetype is based on the c one. Therefore, both files are sourced, as you've noted. But that's no problem, because the cpp one comes last, and will override the c one; you can check with

:verbose execute 'nnoremap' g:formatterTrigger

In general, this is nothing to worry about (unless you define :map <unique>, which would complain in that case), and you already know the commands like :scriptnames to troubleshoot this issue.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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