# How to set filetype based on the file extension?

**URL:** <https://discuss.kakoune.com/t/how-to-set-filetype-based-on-the-file-extension/1129>\
**Category:** Help\
**Created:** [July 4, 2020, 9:52am UTC](https://discuss.kakoune.com/t/how-to-set-filetype-based-on-the-file-extension/1129 "2020-07-04T09:52:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SegFault](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/segfault/32/1478_2.png) [@SegFault](https://discuss.kakoune.com/u/SegFault)\
**Post date:** [July 4, 2020, 9:52am UTC](https://discuss.kakoune.com/t/how-to-set-filetype-based-on-the-file-extension/1129/1 "2020-07-04T09:52:11Z")

</div>

I work with two types of files that, I guess, is not defined internally in Kakoune: asymptote and glsl shader files. Asymptote is a vector graphics language, that is used to draw graphics and is mostly embedded in LaTeX/TeX and GLSL is OpenGL Shading Language. Both of these look very very similar to C source code file. So, for syntax highlighting and code highlighting, every time I open a new file, I have to the following,

```auto
:set buffer filetype c
```

How can I do this automatically, i.e, as soon as open a `.asy` or `.frag` file, kakoune executes the above command?

---

<div class="post-metadata">

**Author:** ![SolitudeSF](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/solitudesf/32/22_2.png) [@SolitudeSF](https://discuss.kakoune.com/u/SolitudeSF)\
**Post date:** [July 4, 2020, 12:07pm UTC](https://discuss.kakoune.com/t/how-to-set-filetype-based-on-the-file-extension/1129/2 "2020-07-04T12:07:16Z")

</div>

```auto
hook global BufCreate .*\.(asy|frag) %{ set buffer filetype c }

```

read about hooks
