One Method to Convert Code Indentation

No Comments

A query:

When you copy a code pattern that makes use of two-space indentation and also you wish to convert it to four-space indentation, what’s the *quickest* and best possibility?

Matt Stauffer, Twitter

I wrote about doing this in Elegant Textual content a number of years again. It’s not terribly completely different in VS Code, I don’t assume.

However right here’s one other manner: Use CodePen.

Step 1: Copy and paste to CodePen

Say you discovered some code elsewhere, simply copy and paste it in:

Step 2: Modify code indentation settings

If you have already got a CodePen account, you’ve most likely already obtained it arrange, so the default is the way you prefer it. But when it’s not but, regulate it within the Pen Settings space:

The code was 2-spaces as copy/pasted, and now we’re altering that to 4-spaces as a setting.

Step 3: Format the code

You may manually do it right here:

It’s possible you’ll not have to make use of that possibility in any respect for those who save the Pen and have the “Format on Save” possibility on, as it’ll mechanically occur.

It’ll kick over to that new 4-space choice proper fast:

CodePen makes use of Prettier beneath the hood to do that. So you might do that wherever you’ve gotten entry to a working model of Prettier, but it surely could be simpler on CodePen since there’s nothing like enhancing config or something to regulate the way you need it. Prettier has its personal playground as effectively, which is probably going simply as straightforward as CodePen, besides that on CodePen you would possibly have already got your preferences arrange, saving a step.

The publish One Method to Convert Code Indentation appeared first on CSS-Methods. You may help CSS-Methods by being an MVP Supporter.

    About Marketing Solution Australia

    We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

    Request a free quote

    We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

    Subscribe to our newsletter!

    More from our blog

    See all posts

    Leave a Comment