mxw / vim-jsx

React JSX syntax highlighting and indenting for vim.
1.59k stars 95 forks source link

Enabling different shiftwidth in JSX indentation #73

Closed danielepiccone closed 8 years ago

danielepiccone commented 8 years ago

Hi, I appreciate this plugin a lot in my everyday work. I am writing quite a lot of JSX markup in my js files, with intentation 4, which makes the file unreadable on small viewports due to line breaks.

I understand that on JSX syntax the plugin enables the same rules as XML, I was wondering how difficult it should be to enable set sw=2 only for the JSX syntax. Thanks

mxw commented 8 years ago

I don't know how to achieve this, besides customizing the indenter to intentionally halve the shiftwidth when in XML contexts. Have you ever achieved anything similar for another language? For instance, tried to make it so that C indented half the shiftwidth for function calls, but the normal amount for blocks, or something?

danielepiccone commented 8 years ago

Never tried, but I see this to be simpler because the different settings is belonging to different language context.

I imagine it would be something like this just for XML syntax when called inside jsx.vim

setlocal sw=2

the value could also be set as a parameter.

mxw commented 8 years ago

setlocal sets a value that's local to a buffer, not local to a vim source file.

danielepiccone commented 8 years ago

yes, it doesn't have to be it. right now I am using it as an autocommand for .jsx files

mxw commented 8 years ago

Feel free to hack this up for your own use, but it's not clear to me that support is necessary in the package for different shiftwidths in JS vs. JSX.