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

Is there a way to bind a key by document type?

For example, if the document is a .tex file, I want f5 to call PdfLatex, but it is a .c file, I want it to call make

share|improve this question
up vote 1 down vote accepted

You can use the <buffer> option to the map command to specify that a mapping be used only in the current buffer, then apply that mapping only in buffers of a particular file type using an autocommand, like this.

au FileType tex map <buffer> <F5> :PdfLatex<CR>
au FileType c   map <buffer> <F5> :make<CR>

For more, see

:help map-<buffer>
:help autocmd.txt
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.