2

here is an example of code inside of my .js file after gg=G command:

class ChannelSection extends React.Component{
    render(){
        return(
            <div>
            <ChannelList channels={channels} />
            <ChannelForm />
            </div>
        )   
    }   
}

As you can see html tags have the same indent. I wish it would be like in html files - nested blocks indented further. Some plugin that can help?

Again, I need to indent ONLY HTML tags in .js file, not in .html file.

3
  • 1
    This is a duplicate of stackoverflow.com/questions/815548/… Commented Jan 30, 2016 at 12:18
  • @MichaelHobbs , nope. Commented Jan 30, 2016 at 12:46
  • Your "JavaScript" is not "JavaScript" and your "HTML" is not HTML. Commented Jan 30, 2016 at 13:51

2 Answers 2

3

You may use mxw/vim-jsx. This plugin requires pangloss/vim-javascript, so you should install both of them.

This is a minimal .vimrc I used with vim-plug:

set nocompatible
filetype off

call plug#begin()
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
call plug#end()

let g:jsx_ext_required = 0

Note that I set g:jsx_ext_required to 0 because you want to edit JSX tags in .js files.

Sign up to request clarification or add additional context in comments.

2 Comments

Is this still the best answer in late 2020?
@AntonOfTheWoods According to mxw/vim-jsx's README, MaxMEllon/vim-jsx-pretty seems to be a next one. Personally, I use sheerun/vim-polyglot for filetype support, and it uses MaxMEllon/vim-jsx-pretty, too.
0

Without plugins and just as a temporary quick solution, I found the command :set filetype=html (alias as :set ft:html) to be quite effective. This worked very well for me due to my work on HTML being minimal but persistent.

Indent the whole file via gg=G or selected section using just =.

Done. Now revert to the previous filetype (in your case, js) doing the reverse :set ft=javascript and continue as you were.

If you didn't know your default filetype use :set filetype? before doing this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.