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

link|improve this question

73% accept rate
feedback

1 Answer

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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