Sublime Forum

Apply operation to multiple files selected in open files

#1

Hi,

I’d like to be able to apply operations on files that I would select in the open files sidebar, so that I can do for instance a macro on every file without actually having to go through them all (open file, apply macro, save file). I want to select the files I want the macro applied on, have Sublime Text (I’m using the 2nd version) open the files and apply the macro and leave the files that have changed open and ready to be save, so that I can simply “Save all” to have the changes saved.

I’ve currently inherited a code base where the indentation is simply not consistent (tabs with spaces, tabs with tabs, inconsistent space size), and I would very much enjoy to capability to do something like View - Indentation - Convert indentation to Tabs on all the files I would have opened in the editor.

1 Like

#2

You can do this to some degree using the console, for example, to do a select_all in all open files, you can enter this in the console:

[v.run_command('select_all') for v in window.views()]

to convert indentation to tabs, you can use the ‘expand_tabs’ command instead.

0 Likes

#3

Hi jps,

Thanks for the answer!

I was wondering if there’s actually any way to drag and drop a project onto sublime and then have that command applied. From the bit of command you provided, I noticed that those files have to be actually in the open list, which is not the case if I just create a project from scratch. Furthermore, I would need to go through the folder structure (recursive) in order to apply it on all the files.

Is there a place where I could look at the current python available objects and methods?

0 Likes