Sublime Forum

Unsaved TabName Bug?


I just came across this StackOverflow question asking how to name an unsaved tab.

I had previously noticed that sometimes my unsaved tabs would assume a name from the first line of text, while other times it would not.

Looking into it further to provide an answer for the question, I found that the first line tabname is unset when altering a document after changing the syntax:

Is there any reason for this?  It seems like a bug…

1 Like

Autoset tab name for new (unsaved) files for custom syntax

Similar issue:

1 Like


From FichteFoll on the previously linked issue:

that is the “expected” behavior. Unsaved view names are set in Default/


# Only set the name for plain text files
syntax = view.settings().get('syntax')
if syntax != 'Packages/Text/Plain text.tmLanguage':
    if cur_name:
        # Undo any previous name that was set
        if cur_name == view_name:

So it seems that it is intentional to only work on Plain Text files. But I think it would be better if ST3 unset the name immediately upon the syntax being changed, otherwise it does indeed look like a bug.

1 Like


That’s such a weird & specific behavior, I don’t see the benefit…

I know some languages have a mandatory first line, so you might have random code as your unsaved tab title in those scenarios, but I think in most cases it would be useful to maintain the first-line tab naming.  Having any number of untitled tabs is a bad UI move when they could just as easily use an existing feature for differentiation.

It’s easy enough to work around, but it would be nice to just be able to type it in without wondering why it works in some cases and not others ( for people who aren’t digging into the source code ).


import sublime, sublime_plugin

class NameUnsavedTabCommand( sublime_plugin.TextCommand ):
	def run( self, edit ):

		window = sublime.active_window()
		file   = self.view.file_name()

		if file == None:
			window.show_input_panel ( "Enter Tab Name", "", get_TabName, None, None )

def get_TabName( userInput ):

	view = sublime.active_window().active_view()

	unsavedTab_Prefix = "* "
	unsavedTab_Suffix = " *"

	view.set_name( unsavedTab_Prefix + userInput + unsavedTab_Suffix )

How can I start a new find_in_files tab with the old one exist?

It’s not a bug, it’s a feature. To disable, set_unsaved_view_name to false.



That just disables it completely.

The “bug-like” nature of it is that it only works on plain-text syntax and it requires the document to be altered before the tab name updates in some cases.

1 Like


Works for me.



In what context?

Did you try the steps to reproduce as shown in the GIF in the first post?



Actually, judging by the code in @kingkeith’s post, it shouldn’t work in any case.



This one’s easy. It’s because the tab name is only updated in a on_modified_asnyc callback. That’s why changing syntax does not automatically change the tab name. Adding on_activated_async should help.



I added the code from post 4 to my personal devtools plugin.

Pretty much solves both the on_modified & plaintext issues.

The on_modified update seems reasonable, but I don’t get why the default functionality is limited to plaintext.



Oh, by the way, I suggest including the syntax name to be used in the unsaved view name for non-text files. And then some counter, like other editors already do (think untitled1 (Python)).



I was able to resolve this by altering a single line in the file:

if syntax != 'Packages/Text/Plain text.tmLanguage':

changed to:

if syntax != 'Packages/Text/Plain text.tmLanguage' and syntax != 'Packages/User/myCustom.sublime-syntax':`

Adding other syntaxes the same way (using the and operator) will add the auto_name functionality to them as well.