You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
5.0 KiB
Markdown

vim-jsx
=======
Syntax highlighting and indenting for JSX. JSX is a JavaScript syntax
transformer which translates inline XML document fragments into JavaScript
objects. It was developed by Facebook alongside [React][1].
vim-jsx is _not_ a JavaScript syntax package, so in order to use it, you will
also need to choose a base JS highlighter. [pangloss/vim-javascript][2] is the
recommended package---it is vim-jsx's "official" dependency, and the only
package against which it is regularly tested. However, vim-jsx makes a best
effort to support other JavaScript syntax packages, including:
- pangloss/vim-javascript
- jelera/vim-javascript-syntax
- othree/yajs
Notably, the system vim JavaScript syntax is _not_ supported, due to its
over-simplicity. However, the system XML syntax package is an implicit
dependency.
Vim support for inline XML in JS is remarkably similar to the same for PHP,
which you can find [here][3].
Troubleshooting
---------------
If you're experiencing incorrect highlighting or indenting in your JSX code,
please file a GitHub issue which includes the following:
- A brief affirmation that you've read the README and have installed one of the
supported dependencies (and the name of the one you're using).
- A minimal ~/.vimrc which repros the issue you're having, as well as both a
paste and a screenshot of the issue (a paste alone is insufficient, since it
doesn't illustrate the specific highlighting or indenting problem). To
obtain a minimal ~/.vimrc, simply bisect your ~/.vimrc by adding `finish` at
various points in the file. (You can likewise bisect your included plugins
by selectively including only half of them, then a quarter, etc.).
Most of the issues filed result from failures to install vim-javascript or
conflicts with existing JS syntax or indent files---so failing to indicate that
you've ruled those issues out may result in your issue being closed with
minimal comment.
(Please feel free to disregard all this for feature requests.)
Usage
-----
By default, JSX syntax highlighting and indenting will be enabled only for
files with the `.jsx` extension. If you would like JSX in `.js` files, add
Squashed 'vim/bundle/jsx/' changes from 1886ffabc..c6d0fd7d4 c6d0fd7d4 Merge pull request #61 from simonratner/feature/yajs-no-reserved bc86a24c3 Allow reserved words in jsxRegion; fixes #60 b1047b075 Merge pull request #59 from maniart/patch-1 cc7641169 Add syntax highlighting to readme code snippets 82773e7be Update README to indicate lack of folding support bfe7f1bc9 Stop accepting string literals as JSX node children 6e761f4e6 Merge pull request #44 from mike-hearn/patch-2 a146429e1 Escape file path e762712b9 Merge pull request #39 from lencioni/suffixesadd 53b4fc978 Merge pull request #40 from othree/master bebf5b834 Add Vim's default js syntax support and general naming support 0e11958e5 Add `setlocal suffixesadd+=.jsx` to ftplugin c8fc9ec2e Set multiple filetypes: javascript.jsx efb24f487 Merge pull request #24 from ingara/master faf509a8b Escape filename when sourcing config file e7784d17b Fix ext detection in syntax 6118a4d4a Enable JSX syntax/indent for .jsx files d6bb935a8 Merge pull request #12 from jbaiter/namespaces c9add7fef Add support for namespaced JSX Tags (available since React 0.11) 5b454c3a4 Merge pull request #15 from baskerville/master 400628d13 Call the search function with the wrapping flag on 3b20d44e2 Cleanup 0eeb47fb6 Merge pull request #14 from baskerville/master 042daddd0 Use the *search* function to detect the pragma 1e50d3fd1 Add option to disable requiring @jsx pragma matching 795c2a74e Look for @jsx pragma natively, rather than with grep 467353fd6 Merge pull request #8 from dchest/letter 5436b498e Tags cannot start with a digit. 465480a32 Merge pull request #6 from dchest/patch-1 d04fd5ec4 Enable JSX syntax/indent only when @jsx pragma is found 58cba8d23 Do not consider << as a start tag. 890afd41c Merge pull request #4 from golmansax/master c09f9b5c7 Fixing Pathogen link 72926560b Merge pull request #2 from justinj/matchit 69f3f3a51 Enable using '%' to jump to matching tags 005282cfa Get rid of `xhp' instances in README 5b08c8732 Use default indentation when we leave a JSX context db237b957 Remove some indentkeys; execute less code 2893c4edc Much more robust indenting 292955d8f Better indent interactions with {}\n</x> and \n/>\n</x> 1aa4c15ed Add Depends comment line to indent c4f2d5976 Initial commit: JSX syntax and indenting REVERT: 1886ffabc Squashed 'vim/bundle/jsx/' content from commit 82773e7 git-subtree-dir: vim/bundle/jsx git-subtree-split: c6d0fd7d4d9d1e26c7643d02bb9abe5db91903c8
9 years ago
```viml
let g:jsx_ext_required = 0
```
to your .vimrc or somewhere in your include path. If you wish to restrict JSX
to files with the pre-v0.12 `@jsx React.DOM` pragma, add
Squashed 'vim/bundle/jsx/' changes from 1886ffabc..c6d0fd7d4 c6d0fd7d4 Merge pull request #61 from simonratner/feature/yajs-no-reserved bc86a24c3 Allow reserved words in jsxRegion; fixes #60 b1047b075 Merge pull request #59 from maniart/patch-1 cc7641169 Add syntax highlighting to readme code snippets 82773e7be Update README to indicate lack of folding support bfe7f1bc9 Stop accepting string literals as JSX node children 6e761f4e6 Merge pull request #44 from mike-hearn/patch-2 a146429e1 Escape file path e762712b9 Merge pull request #39 from lencioni/suffixesadd 53b4fc978 Merge pull request #40 from othree/master bebf5b834 Add Vim's default js syntax support and general naming support 0e11958e5 Add `setlocal suffixesadd+=.jsx` to ftplugin c8fc9ec2e Set multiple filetypes: javascript.jsx efb24f487 Merge pull request #24 from ingara/master faf509a8b Escape filename when sourcing config file e7784d17b Fix ext detection in syntax 6118a4d4a Enable JSX syntax/indent for .jsx files d6bb935a8 Merge pull request #12 from jbaiter/namespaces c9add7fef Add support for namespaced JSX Tags (available since React 0.11) 5b454c3a4 Merge pull request #15 from baskerville/master 400628d13 Call the search function with the wrapping flag on 3b20d44e2 Cleanup 0eeb47fb6 Merge pull request #14 from baskerville/master 042daddd0 Use the *search* function to detect the pragma 1e50d3fd1 Add option to disable requiring @jsx pragma matching 795c2a74e Look for @jsx pragma natively, rather than with grep 467353fd6 Merge pull request #8 from dchest/letter 5436b498e Tags cannot start with a digit. 465480a32 Merge pull request #6 from dchest/patch-1 d04fd5ec4 Enable JSX syntax/indent only when @jsx pragma is found 58cba8d23 Do not consider << as a start tag. 890afd41c Merge pull request #4 from golmansax/master c09f9b5c7 Fixing Pathogen link 72926560b Merge pull request #2 from justinj/matchit 69f3f3a51 Enable using '%' to jump to matching tags 005282cfa Get rid of `xhp' instances in README 5b08c8732 Use default indentation when we leave a JSX context db237b957 Remove some indentkeys; execute less code 2893c4edc Much more robust indenting 292955d8f Better indent interactions with {}\n</x> and \n/>\n</x> 1aa4c15ed Add Depends comment line to indent c4f2d5976 Initial commit: JSX syntax and indenting REVERT: 1886ffabc Squashed 'vim/bundle/jsx/' content from commit 82773e7 git-subtree-dir: vim/bundle/jsx git-subtree-split: c6d0fd7d4d9d1e26c7643d02bb9abe5db91903c8
9 years ago
```viml
let g:jsx_pragma_required = 1
```
to your .vimrc or somewhere in your include path.
Frequently Asked Questions
--------------------------
- _How come syntax highlighting doesn't work at all?_
This is the only question I'll answer with another question---Which do you
think is more likely: (a) this package fails completely and utterly in serving
its most fundamental purpose, or (b) user error?
- _Why are my end tags colored differently than my start tags?_
vim-jsx is basically the glue that holds JavaScript and XML syntax packages
together in blissful harmony. This means that any XML syntax defaults carry
over to the XML portions of vim, and it's common for many colorschemes to
highlight start and end tags differently due to the system XML syntax defaults.
- _Syntax highlighting seems to work, but breaks highlighting and indenting
further down in the file. What's wrong?_
This often results from trying to enable XML folding in one's `~/.vimrc` (i.e.,
via `let g:xml_syntax_folding = 1`). vim-jsx does not support syntax folding,
and is not tested with either JavaScript or XML folding enabled.
Installation
------------
### Pathogen
The recommended installation method is via [Pathogen][4]. Then simply execute
git clone https://github.com/mxw/vim-jsx.git ~/.vim/bundle/vim-jsx
(You can install [vim-javascript][2] in an analogous manner.)
### Vundle
You can also add vim-jsx using [Vundle][5]---just add the following lines to
your `~/.vimrc`:
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
To install from within vim, use the commands below.
:so ~/.vimrc
:PluginInstall
Alternatively, use the command below to install the plugins from the command
line.
vim +PluginInstall +qall
### Manual Installation
If you have no `~/.vim/after` directory, you can download the tarball or zip
and copy the contents to `~/.vim`.
If you have existing `~/.vim/after` files, copy the syntax and indent files
directly into their respective destinations. If you have existing after syntax
or indent files for Javascript, you'll probably want to do something like
mkdir -p ~/.vim/after/syntax/javascript
cp path/to/vim-jsx/after/syntax/jsx.vim ~/.vim/after/syntax/javascript/jsx.vim
mkdir -p ~/.vim/after/indent/javascript
cp path/to/vim-jsx/after/indent/jsx.vim ~/.vim/after/indent/javascript/jsx.vim
[1]: http://facebook.github.io/react/ "React"
[2]: https://github.com/pangloss/vim-javascript "pangloss: vim-javascript"
[3]: https://github.com/mxw/vim-xhp "mxw: vim-xhp"
[4]: https://github.com/tpope/vim-pathogen "tpope: vim-pathogen"
[5]: https://github.com/VundleVim/Vundle.vim "VundleVim: Vundle.vim"