Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
/ vim-jsonc Public archive

⚠️Deprecated⚠️: Vim syntax highlighting plugin for JSON with C-style line (//) and block (/* */) comments.

License

Notifications You must be signed in to change notification settings

kevinoid/vim-jsonc

Repository files navigation

⚠️ Deprecated ⚠️

Support for the jsonc filetype is included in Vim 8.2.3117 and later (#8500) and NeoVim 0.6.0 and later (#15494). Using the built-in jsonc filetype plugin is recommended.

Note: The built-in jsonc filetype is currently only applied to files with the .jsonc extension. To use the filetype for additional files, consider adding a modeline comment and/or copying ftdetect/jsonc.vim from this plugin into 'runtimepath'.

JSON with Comments for Vim

Vim syntax highlighting plugin for JSON with C-style line (//) and block (/* */) comments.

It defines a filetype named jsonc (matching the name used in VS Code, a Microsoft parser library, .mocharc.jsonc, and the jsonc npm package) which can be applied to files using set ft=jsonc or a modeline.

Installation

This plugin can be installed in the usual ways:

git clone https://github.com/kevinoid/vim-jsonc.git ~/.vim/pack/git-plugins/start/vim-jsonc

Using Pathogen

git clone https://github.com/kevinoid/vim-jsonc.git ~/.vim/bundle/vim-jsonc

Using Vundle

Add the following to .vimrc:

Plugin 'kevinoid/vim-jsonc'

Then run :PluginInstall.

Using vim-plug

Add the following to .vimrc between plug#begin() and plug#end():

Plug 'kevinoid/vim-jsonc'

Implementation

This plugin loads the JSON syntax plugin, clears the syntax group for comments as errors, then defines additional syntax to match C-style comments.

This project was inspired by, and the code is based on, elzr/vim-json#61 by @TheLocehiliosan.

Filetype Detection

Once installed, the jsonc filetype is automatically used for files named *.jsonc, *.cjson, and *.cjsn. Additionally, some configuration files known to support JSON with comments are recognized by name. See ftdetect/jsonc.vim for the complete list.

To use the jsonc filetype for additional file names/paths, consider using an :autocmd. For example, to treat files with the extension mycjson as jsonc by adding the following to vimrc:

autocmd BufRead,BufNewFile *.mycjson set filetype=jsonc

Note: Users with large or complex configurations may want to consider placing the :autocmd in after/filetype.vim or ftdetect/mycjson.vim for performance and to keep vimrc manageable. See :filetype, new-filetype, and after-directory for details.

If the file name or extension is widely used for JSON with comments, please consider sending a pull request to add it to ftdetect/jsonc.vim.

Contributing

Contributions are appreciated! Please add tests where possible and ensure ./run-tests.sh passes.

If the desired change is large, complex, backwards-incompatible, can have significantly differing implementations, or may not be in scope for this project, opening an issue before writing the code can avoid frustration and save a lot of time and effort.

License

This package is available under the terms of the MIT License.

About

⚠️Deprecated⚠️: Vim syntax highlighting plugin for JSON with C-style line (//) and block (/* */) comments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published