Vim bind compile key depending on document type

0

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

vonhogen

Posted 2010-09-19T05:36:55.987

Reputation: 1 949

Answers

1

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

garyjohn

Posted 2010-09-19T05:36:55.987

Reputation: 29 085