vim-javascript
Vastly improved Javascript indentation and syntax support in Vim.
A Vim plugin that adds proper JavaScript syntax highlighting, smart indentation, and optional extras like JSDoc coloring, Flow type annotations, code folding, and character concealing for arrow functions and keywords.
vim-javascript is a plugin for the Vim text editor that adds JavaScript syntax highlighting and improved code indentation. It works with Vim 8 and later, installed through the native package manager or through popular plugin managers like pathogen or vim-plug.
The plugin includes several optional settings you can enable in your Vim configuration file. One adds color coding for JSDoc comments, which are a structured way to document JavaScript functions and their parameters. Another adds extra highlighting for AngularJS documentation comments (NGDocs), though it requires the JSDoc option to be active first. A third option adds highlighting for Flow, a system that lets developers annotate JavaScript with type information.
Code folding is another opt-in feature. When enabled, Vim can collapse blocks of code so only the structure of a file remains visible, making it easier to scan large files. The README notes this can slow Vim down considerably, especially when pasting text, and suggests switching to indentation-based folding if performance suffers.
The plugin also supports character concealing, a visual trick that replaces certain keywords or symbols with glyphs from your font. For example, the keyword "function" could appear as a special character, and arrow functions could display as an arrow symbol. This is purely cosmetic and requires a font that includes those glyphs. Concealing can be toggled on and off with a key binding.
The README references several built-in Vim indentation controls for fine-tuning how JavaScript code is indented, pointing to the relevant help pages without elaborating further. The project is distributed under the same license as Vim itself.
Where it fits
- Get proper color-coded JavaScript syntax highlighting inside Vim so code is easier to read at a glance.
- Enable JSDoc comment highlighting to make function documentation stand out while editing JavaScript files.
- Use code folding to collapse large JavaScript files down to their structure so you can navigate them quickly.
- Add Flow type annotation highlighting when working on type-checked JavaScript projects in Vim.