11

Vim supports syntax highlighting for embedded languages or fenced code in markdown (:h :syn-include).

However, you usually want that other vim settings and mappings are adjusted for embedded languages as well. These are for example

  • load/unload ftplugins containing settings for example for
    • b:match_words used by matchit's %
    • commentstring (e.g. for vim-commentary)
    • square bracket motions (e.g. done in VIMRUNTIME/ftplugin/[vim,ruby,python,...].vim)
  • folds (foldmethod or foldexpr)
  • indentation scripts in $VIMRUNTIME/indent/<language>.vim (indentexpr)
  • formatting (formatprg or dedicated plugins autoformat, neoformat)
  • 'intellisense' completion (omnifunc or dedicated plugins ycm, deoplete, ncm2)
  • linting (run compiler for code region or dedicated plugins ale, neomake or syntastic)
  • ft snippets (ultisnips or snipmate)
  • ...

Plugins

I know which are dedicated to this or have builtin support are

Relevant Tools

It is one thing to adjust a single setting as done by https://github.com/suy/vim-context-commentstring but I miss support for the adjustments done in $VIMRUNTIME/ftplugin and the $VIMRUNTIME/indent/.

Afaik, this is something which vim does not really cover. For example, I use the plugin SimpylFold which defines folds for python as I want it and vimtex for LaTeX files. However, I would not know if vim can combine this for a single latex file using pythontex.

I am not familiar with other editors and their solutions for this. A quick search revealed for Visual Studio Code that vscode supports out of the box adjusted syntax highlighting and commenting.

Did I miss something in vim itself supporting loading/unloading ftplugin/indent or do you occasionally change the filetype by yourself?

Today many tasks (e.g. autocompletion, linting, snippets, formatting) are provided by dedicated plugins: Which of the major plugins i.e. ycm, deoplete, ale, syntastic, tagbar, ultisnips, snipmate, autoformat and neoformat support this?

3
  • For syntax there is SyntaxRange. If you expect a generic solution that works out of the box with any template and / or embedded languages, you're chasing the pie in the sky. It's a hard problem, that can be solved (given enough effort) for particular languages. Solving it generically is not possible.
    – lcd047
    Commented Oct 28, 2018 at 17:51
  • 2
    SyntaxRange was not what I was looking for. vimtex already does this automatically for latex environments which contain different languages (python, lua, gnuplot, graphviz, asymptote, minted-languages). I would expect the same from other ftplugins which can contain embedded languages, e.g. html/css/javascript. But there is another plugin mentioned: OnSyntaxChange. So thanks for pointing me into this direction. I certainly agree that a generic solution is not feasible. I was interested in the experience of others and their take on this.
    – Hotschke
    Commented Oct 29, 2018 at 6:32
  • I thought the recommended way to source several files was to use a "combined" filetype, separated by ., e.g. :set ft=php.sql (just a silly example, as I don't know if those actually work) Commented Jun 23, 2021 at 12:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.