This is a patch to create a separate json filetype and use it for *.json files instead of using javascript. It currently just forwards indent and syntax settings to the javascript filetype, but it does define its own ftplugin/json.vim file since most of the settings in ftplugin/javascript.vim don't apply to JSON. I'd like to submit it to be integrated in vim under the Vim license.
My reasons for wanting to do this instead of just using the javascript filetype are: * JSON is not JavaScript, it's a very small subset of the language. Comments and many other details of JavaScript syntax are completely invalid in a JavaScript file, so it's misleading to treat them as the same filetype. * Several plugins (syntastic, vim-snippets, vim-addon-manager) refer to a "json" filetype that doesn't actually exist unless you install some third-party plugin to apply it. This leads to vim unexpectedly triggering "javascript" actions on "json" files, and in the case of vim-addon-manager means addon-info.json files aren't syntax highlighted at all (https://github.com/MarcWeber/vim-addon-manager/issues/163). David -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
diff -r 0efec12f52ac runtime/filetype.vim --- a/runtime/filetype.vim Thu Jul 10 22:01:47 2014 +0200 +++ b/runtime/filetype.vim Thu Jul 10 22:20:25 2014 -0700 @@ -989,7 +989,7 @@ au BufNewFile,BufRead *.jj,*.jjt setf javacc " JavaScript, ECMAScript -au BufNewFile,BufRead *.js,*.javascript,*.es,*.jsx,*.json setf javascript +au BufNewFile,BufRead *.js,*.javascript,*.es,*.jsx setf javascript " Java Server Pages au BufNewFile,BufRead *.jsp setf jsp @@ -1007,6 +1007,9 @@ " Jovial au BufNewFile,BufRead *.jov,*.j73,*.jovial setf jovial +" JSON +au BufNewFile,BufRead *.json setf json + " Kixtart au BufNewFile,BufRead *.kix setf kix diff -r 0efec12f52ac runtime/ftplugin/json.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/ftplugin/json.vim Thu Jul 10 22:20:25 2014 -0700 @@ -0,0 +1,17 @@ +" Vim filetype plugin +" Language: JSON +" Maintainer: David Barnett <daviebdawg+...@gmail.com> +" Last Change: 2014 Jul 10 + +if exists('b:did_ftplugin') + finish +endif +let b:did_ftplugin = 1 + +let b:undo_ftplugin = 'setlocal formatoptions< comments< commentstring<' + +setlocal formatoptions-=t + +" JSON has no comments. +setlocal comments= +setlocal commentstring= diff -r 0efec12f52ac runtime/indent/json.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/indent/json.vim Thu Jul 10 22:20:25 2014 -0700 @@ -0,0 +1,13 @@ +" Vim indent file +" Language: JSON +" Maintainer: David Barnett <daviebdawg+...@gmail.com> +" Last Change: 2014 Jul 10 + +if exists('b:did_indent') + finish +endif + +" JSON is a subset of JavaScript. JavaScript indenting should work fine. +runtime! indent/javascript.vim + +let b:did_indent = 1 diff -r 0efec12f52ac runtime/syntax/json.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/syntax/json.vim Thu Jul 10 22:20:25 2014 -0700 @@ -0,0 +1,23 @@ +" Vim syntax file +" Language: JSON +" Maintainer: David Barnett <daviebdawg+...@gmail.com> +" Last Change: 2014 Jul 10 + +" For version 5.x: Clear all syntax items. +" For version 6.x and later: Quit when a syntax file was already loaded. +if v:version < 600 + syntax clear +elseif exists('b:current_syntax') + finish +endif + + +" Use JavaScript syntax. JSON is a subset of JavaScript. +if version < 600 + source <sfile>:p:h/javascript.vim +else + runtime! syntax/javascript.vim + unlet b:current_syntax +endif + +let b:current_syntax = 'json'