StAlRuth
StAlRuth

Reputation: 59

Set vim filetype script for c++ headers only

I basically want to have vim use a command on c++ header files, and only on c++ header files. How can I do this?

I have tried putting the commands in ~/.vim/ftplugin/hpp.vim to no avail as the hpp files are seen as cpp files by Vim.

Upvotes: 0

Views: 2091

Answers (2)

Sato Katsura
Sato Katsura

Reputation: 3086

In your ~/.vim/ftplugin/cpp.vim:

if expand('%:e') ==? 'hpp'
    " your script here
endif

Better yet:

if expand('%:e') =~? '\v^h%(pp|h|\+\+|xx)?$'
    " your script here
endif

Upvotes: 3

edi9999
edi9999

Reputation: 20574

You should add

autocmd BufEnter *.hpp :setlocal filetype=hpp

to your vimrc

So that the filetype of your hpp files is recognized as hpp.

You can then use ~/.vim/ftplugin/hpp.vim to put your specific commands

Upvotes: 0

Related Questions