Original blog: https://jaxbot.me/articles/setting-up-vim-for-react-js-jsx-02-03-2015
React.js is gaining a lot of traction lately,but developing with its inline-XML-in-JS requires a few tweaks to Vim for a smooth experience.
Syntax highlighting
To get the Syntax highlighting to look right,use mxw’s Vim JSX highlighting.
If you use Vundle,add:
Plugin 'mxw/vim-jsx'
Other plugin loaders,see the GitHub page.
If you use JSX Syntax in .js files,which is now becoming standard,add:
let g:jsx_ext_required = 0 " Allow JSX in normal JS files
to your vimrc.
Syntax checking
If you use Syntastic,you’ll notice immediate errors wherever XML nodes appear,which is to be expected. Here’s a work around.
Update 3/30/15: I’ve added instructions on using ESLint instead of the old wrapper package.
Install eslint,babel-eslint (for ES6 support),and eslint-plugin-react:
npm install -g eslint
npm install -g babel-eslint
npm install -g eslint-plugin-react
Create a config like this in your project’s .eslintrc
,or do so globally by placing it in ~/.eslintrc
:
{
"parser": @H_404_60@"babel-eslint","env": @H_404_60@{ "browser": @H_404_60@true,"node": @H_404_60@true },"settings": @H_404_60@{ "ecmascript": @H_404_60@6,"jsx": @H_404_60@true },"plugins": @H_404_60@[ "react" ],"rules": @H_404_60@{ "strict": @H_404_60@0,"quotes": @H_404_60@0,"no-unused-vars": @H_404_60@0,"camelcase": @H_404_60@0,"no-underscore-dangle": @H_404_60@0 } }
Finally,configure Syntastic to use ESLint:
let g:syntastic_javascript_checkers = ['eslint']
You should be good to go,and JSX with ES6 features will Syntax check correctly! See this issue for more info.