0

How do I auto-convert HTML indentation from four spaces to two spaces?

For now, I have to:

  1. convert indentation to tab
  2. set tab size to 2
  3. convert indentation to space

file by file.

Is there any easy way to auto-convert the indentation when I edit/create a HTML file? Install a package or add some settings?

1 Answer 1

2

I'm not sure whether there's a way to run a Sublime Text package (or macro) on multiple files, so this is not really a Sublime Text solution.

You could use gulp-indent and run your Gulp task using this package. Here's an example configuration for Gulpfile.js:

var indent = require("gulp-indent");    

gulp.src("./src/*.html")
.pipe(indent({
    tabs: false,
    amount: 2
}))
.pipe(gulp.dest("./dist"));
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, it is a good way.But I realize should not use "all" in the question, just because I want sublime auto detect current edit/create file, if it is html, then convert the indent, other code still use space 4. Wouldn't need execute another command in this way.
Why not simply use an indentation package, e.g. HTML-CSS-JS Prettify?

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.