PDA

View Full Version : Some command to replace tabs to spaces?



samstewiefisher
10-09-2015,
Is there any way to replace tabs with spaces on save in files that already have tabs?

sanshiro
10-10-2015,
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".

Scarlett
10-11-2015,
Why are you using a tab character in the regex? I think it's better to replace it with \t.

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

sevlad
10-14-2015,