Sublime Forum

Feature Request: "Blank Operations"

#1

Notepad++ has a submenu which I find very useful: “Edit » Blank Operations”, which offers the following tools:

  • Trim Trailing Space
  • Trim Leading Space
  • Trim Leading and Trailing Space
  • EOL to Space
  • Remove Unnecessary Blank and EOL
  • Tab to Space
  • Space to Tab (All)
  • Space to Tab (Leading)

I find these very handy when porting code from one language to another, or when building a document by cutting and pasting from multiple sources, etc.

Especially, I use a lot the “Tab to Space” tool in plain text files.

I would really like to see this tools in SublimeText 3 — ie: as built-in tools, not as a third party package. I think they are useful in so many contexts that they deserve to be part of the built-in functionality. Do others agree on this?

Currently, I don’t know of any way to achive these other than using RegEx search-&-replace (which isn’t very practical), so I often end-up opening the same file also in Notepad++ in order to have quick access to these tools. But I admit that I am not a very experienced ST user, so if anyone can point out to me a quick way to achieve these blank operations in ST3 (including a package that might offer these) I’d really appreciate it.

Tristano

1 Like

#2

I agree that that functionality could be handy. But why do you think it should be builtin? A plugin for that would be fine, wouldn’t it?

0 Likes

#3

But why do you think it should be builtin? A plugin for that would be fine, wouldn’t it?

I think they should be built in because they belong to very common text operations, that can be applied to any type of source code or text (I’d define them “context agnostic”). I guess these are the same reasons NP++ devs choes to make them built-in, rather than a plug-in.

ST already offers a “View » Indentation » Convert Indentation to Spaces/Tabs” built-in tool. I’d say these tools I’m proposing fall more or less in the same category of general editing tools.

But I obviously would like to read others opinion on this; maybe not everyone sees them as crucial functions the same way I do.

Would there be advantages in having them as part of a third party package vs having them as built-in tools?

I haven’t yet grasped the philosophy of ST development — ie: where the line is drawn between what is considered essential (and deserves to be built-in) and what is rather left open to users customization. I appreciate that ST doesn’t impose any kind of language-specific workflow (at the expenses of other langs), but rather focuses on being a language agnostic editor and leaves to the users the freedom of customizing their way of working with code and text. I just thought that these type of text operations belong to a category generic enough to derserve their own place in the built-in menu.

Since there aren’t many ways to go about these simple tasks, there might not be a case of letting them be better handled by custom packages (ie: each package taking a different approach). But I might be wrong on this, overlooking other ways to approach blank operations — and I’d like to ear about them from other ST users.

0 Likes

#4

I use RegReplace for these kind of things: https://github.com/facelessuser/RegReplace.

Just some examples:

Rules

{
	"format": "3.0",
	"replacements":
	{
		"ensure_newline_at_file_end":
		{
			"find": "(?P<eof>([^\\n\\r])(?![\\s\\S\\r\\n]))",
			"replace": "\\g<eof>\\n"
		},
		"remove_trailing_spaces":
		{
			"find": "[ \\t]+$",
			"greedy": true,
			"name": "remove_trailing_spaces",
			"replace": ""
		},
		"trim_excessive_newlines":
		{
			"find": "(((\\r?\\n)+)(?=(\\r?\\n){1}(?![\\s\\S\\r\\n]))|(?<![\\s\\S\\r\\n])((\\r?\\n)+))",
			"replace": ""
		}
	}
}

Commands

    {
        "caption": "Remove: Trailing Spaces",
        "command": "reg_replace",
        "args": {"replacements": ["remove_trailing_spaces"], "find_only": true}
    },
    {
        "caption": "Remove: Excessive Newlines",
        "command": "reg_replace",
        "args": {"replacements": ["trim_excessive_newlines", "ensure_newline_at_file_end"], "find_only": true, "regex_full_file_with_selections": true}
    },

Really Now I have simple commands to remove trailing whitespace and to remove newline padding at the start of a file and ensures only 1 newline at the file end.

1 Like

#5

This is built-in

Made by search & replace or StringUtilities

Trimmer does it and more very well, even with main menu entries for those who still need them.

0 Likes

#6

This is a really cool package!

Thanks for the link @facelessuser … I’ll be needing this for quite a few reccurent RegEx tasks I use for markdown editing/conversion!

0 Likes

#7

Thanks! It is one of my more favorite plugins as I use it all the time. If you run into any bugs let me know.

0 Likes

#8

I didn’t realize that the Indentation menu covered it — I even mentioned it in my post, but I thought this would handle only tabs at the beginning of a line, not just any tabs anywhere.

Thanks for the tip @deathaxe!

0 Likes