Recently I've started up with vuejs and I'm currently trying to set up my editor for using it. Vue uses a similar approach with React - keeping the HTML, Javascript & CSS in the same file - it does so by marking the various chunks of code with some XML tags. I'd like to change the filetype based on area of the file that I'm currently editing.
Long story short, given the anatomy of a .vue, file what I'd like to do is:
<template>
<!--
when the cursor is here, execute
:set ft=html
-->
</template>
<script>
/**
* when the cursor is here, execute
* :set ft=javascript
*/
</script>
<style>
/**
* when the cursor is here, execute
* :set ft=css
*/
</style>
I know there's a plugin called vim-vue, which is awesome, but it only changes the syntax for correct highlighting, and I would like to change the filetype, so all other plugins (autocomplete with ternjs for javascript, linters, multi-line commenters, etc.) to work correctly in their respective areas.
I have to avenues of attacking this:
- using the aforementioned plugin and somehow monitor for changes of the syntax and update the filetype accordingly. AFAIK vim does not trigger an event when the syntax is changed.
- have something similar with
syntax region
but for filetype
But so far I could not find a solution. Any suggestions are welcome.
PS: I use neovim in CLI mode, but I don't think that's particularly relevant.
synIDattr(synID(line("."), col("."), 0), "name")
That depends however, that the cursor is on a specific syntax item