Sublime Forum

"trim trailing white space on save" only on modified lines?

#1

Is there a way to get the “trim_trailing_white_space_on_save” setting to apply only to lines that have been modified?

I’d like to avoid diffs that include lines that have nothing to do with the change being made.

As a side note: the forum would not let me post with a title that included ““trim_trailing_white_space_on_save” claiming “Title seems unclear, is it a complete sentence?”. Annoying as Hell.

0 Likes

#2

This isn’t possible in ST3 except possibly through a third party plugin that does some sort of tracking on edits to know where you’ve modified the file so it knows where to trim. I’m not aware of anything that does that though.

However, ST4 has enhanced white space trimming options available as outlined below. Builds of ST4 are currently available to licensed users only and are being distributed on the Discord Server currently.

	// Controls where trailing white space is removed on save.
	// - "none": Do not remove any trailing white space on save.
	// - "all": Remove all trailing white space on save.
	// - "not_on_caret": Only remove white space that won't affect the caret.
	//                   When used in conjunction with "save_on_focus_lost" and
	//                   certain desktop environments that frequently make the
	//                   application lose focus this avoids the caret jumping
	//                   around a lot.
	"trim_trailing_white_space_on_save": "none",

	// Only trim white space on save for the parts of a file that have been
	// modified by you. If there is trailing white space in other parts of the
	// file they are left alone.
	"trim_only_modified_white_space": true,
0 Likes

#3

Thanks.

I installed 4094 and after a little experimentation, the new "trim_only_modified_white_space" setting’s behavior isn’t quite what I’m looking for. But I’ll take it to the ST4 Discord forum.

0 Likes

#4

Hi.
This might not be a solution, but there’s a plugin called Delete Trailing Spaces. I’ve got it linked to a keybinding…

{ “keys”: [“alt+t”, “alt+s”], “command”: “delete_trailing_spaces” },

oh and it works in ST3

Loz

0 Likes

#5

Thanks so much! With my limited testing, this plugin can be configured to do exactly what I’m looking for.

0 Likes

#6

Wow amazing ! I’ve actually posted something useful. I’m off to have a celebratory drink !

Glad to hear it, though I deserve no credit, the writer of the plugin does, which could be Jean-Denis Vauguet…(info from the github distro)

0 Likes

#7

No, I just wrote Package Control, hence my name is in the footer of the site. Sorry for any confusion!

0 Likes