Sublime Forum

Save Edited Tabs

#1

I have been searching on Google for an answer but can’t find any relevant results. In Sublime Text 3, I am going to be editing a large number of files using find and replace.

I would then like to save only the edited files since our file system records when the last change was made to each file and I do not want to update the last edited date for files that have not changed (so “save all” does not do what I require).

I could individually go through and manually save each tab with a dot next to it, but this is going to be a large number of files, so I would prefer to use a key binding.

0 Likes

#2

I am not sure if there is an efficient way for this but here is a plugin that does what you want.

import sublime
import sublime_plugin

class SaveDirtyViewsCommand(sublime_plugin.WindowCommand):

	def run(self):
		for view in self.window.views():
			if view.is_dirty():
				view.run_command("save")

Save this in the Users directory, (you can access it by going to Preferences -> Browse Packages...) as a .py (python) file. Now define a keybinding for this command in a .sublime-keymap file saved to the Users directory.

{ "keys": ["ctrl+shift+q"], "command": "save_dirty_views" }

(You can choose any key binding you want). Now whenever you press the said key, only the dirty views (the ones that have unsaved changes) will be saved & the non-dirty ones will not be saved again.

2 Likes

#3

Thank you very much, this is exactly what I needed! I have tested this and I can tell from the timestamps in the file system that this has only saved the files I edited. Thanks for the quick response.

0 Likes