Some command to replace tabs to spaces?

Is there any way to replace tabs with spaces on save in files that already have tabs?

You could simply replace all tabs with spaces, but that’s going under the assumption that you don’t have ANY tabs in your files that you actually want there (eg. in strings).

Here’s a simple macro that replaces all tab characters to 4 spaces:

var editor = require("ko/editor");
editor.setValue(
    editor.getValue().replace(/	/g, '    ')
);

You can set this macro to run “Before file save”.

Why are you using a tab character in the regex? I think it’s better to replace it with \t.

That is more explicit yeah. It’s just a quick macro to demonstrate a use-case, let’s not start picking it apart.

1 Like

You want it? Komodo’s got it! Code Menu > Untabify.

That should do what you’re looking for.

  • Carey
1 Like

Where you was?! Ahh damn, that could save a lot of time I spent on replacing tabs with spaces :frowning:
Anyway, thank you for mentioning of this feature :smile:

awesome. awesome to the max. thnaks guys.

1 Like

Don’t feel bad, I didn’t know about it either :stuck_out_tongue: