Vscode: Unsaved tab labels should preview text instead of "Untitled-#"

Created on 1 Nov 2017  ·  52Comments  ·  Source: microsoft/vscode

Tabs that haven't been saved could use their first line of text as the label instead of being called "Untitled-1," "Untitled-2," etc.

This would be helpful for finding the right tab without clicking through all of them, and would mimic Sublime Text's behavior:

preview text edit

feature-request on-testplan workbench-editors

Most helpful comment

Pushed a change to use up to 50 characters of the first line of the untitled document as title:

video

Some notes:

  • the title will also be used when saving as a suggested file name
  • if the first line is empty, the title will be shown as it used to be
  • there is no extra setting planned currently to enable or disable this (leaving the first line empty would be a way to force the old behaviour)

All 52 comments

If multiple unsaved files start with the same text (think of those comment blocks with a license or simply a JS' import statement) the title would be pretty useless.

@fabiospampinato I find not having this feature really frustrating coming from sublime. I often want to jot down a few ideas about various things I'm working on, and it was incredibly helpful to be able to title them for easy access like this. Right now I have to remember which idea Untitled-8 corresponds to, and most of the time end up relying on their order in the tabs anyway. Even having several files named with a JS "import" statement like you describe helps identify them compared to other filetypes, and whereas Untitled-X is totally unhelpful!

I think this would be a very useful feature especially for throw away SQL that I work on as I don't need a file name, a tab name would be brilliant if I'm moving back and forth between multi tabs. Instead of having multiple 'import' tab titles (like described by fabiospampinato for JS files), the tab name could be a decoded comment on line 1 in the editor else default to the preview text.

I also think this would be extremely useful. While I see that for some files, this could be 'useless' , I definitely think it becomes helpful when taking notes or when you need to quickly need to open a new file and don't want to save the currently opened one. Having something to quickly reference when looking for the correct tab would be great.

As I mentioned in #46204, this is incredibly useful for unsaved Markdown files. I often make notes in several unsaved files, and I give them headings like # Notes for X, so having this text in the tab's label would obviously be very useful. I did this all the time in Sublime.

Still would really like this feature :)

Also there is related issue here with saving multiple Untitled-# tabs during Ctrl + S (Save All).

Currently you cannot convenient save multiple untitled files because you should consistently enter names for Untitled-# files, but you don't know what the next file corresponds to because FOCUS REMAINS on last open tab.

Not sure, maybe this need to extract to separate issue (if it does not exists)

Steps for reproduce:

  1. Create several Untitled-# tabs
  2. Ctrl + S (Save All)

OS: Ubuntu 16.04 (Unity)

I have extracted https://github.com/Microsoft/vscode/issues/58799 so that untitled buffers get active when the save dialog shows up so that the file name can be determined by looking at the contents.

While @bpasero changes are a great addition (and fixes @mrkeuz commented issue), I still agree with OP that the tab name should be an excerpt of the first line, like Sublime.

Consider the use in conjunction with #101, where we hot exit, meaning we are just using some tabs as scratchpads for, let's say, a to-do list, or a server json response, and so on. When having multiple tabs, tabs named Untitled-∞ are hard to navigate, having to click through each to remember what was in which.

that's one of the things I miss from Sublime, like OP.

that's one of the things I miss from Sublime, like OP.

Same

I guess it is a matter of changing the OnFocus function, or equivalent, to update the tab name when it is OnFocus to the text in Line 1.

Obviously there should be a limit to the length of text it populates.

I don't see two similar Line 1's being a "train smash" as the user can still find which of the tabs they are after quicker than going through all the untitled's.

Lastly, I guess it could actually be a feature/option of auto-save instead to change the name to Line 1. That could accomplish both. Auto-Save and "Rename tab to Line 1".

coming from sublime, +1 to adding this simple feature

working 80% of my day (private and business) with VSC 1+

I've tried VSCode a few times, but I'm not going to use it over anything else until unsaved buffers have some sort of naming like Sublime does. Half of what I do day to day is creating a new buffer and putting text, code snippets, urls, etc in and out, and having 10 "Untitled-N" does not work. I don't understand why this issue persists, it can't be difficult to do.

Hi, I would like to try implementing this feature.

Hi @bpasero, where should my entry point be? The suggestFileName() function seems like a good spot.

I have no idea how this could be done, but it would be a game changer for me. I used Sublime for coding as much as a spare scratch pad to take notes. I started using VSCode and the multiple "Untitled" tabs make me cycle through most of the tabs until I find the right one.

+1 for this feature. This is the literally the only reason I'm sticking with Sublime Text.
Like everyone mentioned ☝️, knowing contents of the tab without having to toggle through all the Untitled-# will be immensely helpful.

I'd be more than happy to test this feature when ready. Also found this post from 2017 where someone tried writing an extension for this:
https://stackoverflow.com/questions/45876887/change-title-of-untitled-tab-in-visual-studio-code

Relevant @ndngo?

+1

Strongly Agree. It is for this reason that vscode has not become my only development tool, I am using it with sublime at the same time.

If this gets implemented, I'd also really like to see a configuration option for a character length to truncate the tab title too. EG

First line of text happens to be some nifty shell pipeline that goes on and on

Results in a title:

First line of tex...

Where the truncation is controlled by a config option.

I would strongly encourage #41909 to be considered along-side this issue. If #41909 were implemented, this solution could be quite easily implemented by the community as an extension.

Late to the (original) party, but... yeah, that's a feature that would help a lot. I like Code, more than Sublime, but that's one feature I miss the most from Sublime. At least, I've got the icon that tells me if it's a text, SQL, Python, etc. file, but that's about it.

ETA: I agree that #41909 might be the most efficient way to it. However we get there, as long as we do, I'm happy.

+1

I would love to see this added. I'm also coming over from Sublime Text and found this helpful for quickly locating an open, unsaved file among the list.

+1
Former Sublime User here too. Loved that functionality.

+1

+1 too

+1

Another ex-ST3 user here.

+1

I'd also like this considered for addition.
Very frequently I will want to save whatever I have in my clipboard buffer for later review.
My workflow is usually like this:

  • Find interesting snippet of text, code, etc.
  • Switch to my editor, Ctrl+N to open a new document, Ctrl+V to paste the information I want to keep.
    Knowing that VSCode will keep unsaved documents even across restarts.
  • When I have time, catalogue and index the snippets and process them further.

And it's that last step that becomes difficult, because I have no information about the content of those "Untitled-n" documents. (See attached screenshot)
It would help my workflow to no end having a glimpse inside the document to help me find information again.

Screenshot_20191209_062828

+1

+1

In addition to the default Sublime Text way (automatic title added, e.g. the first line of the file), it would be nice to be able to edit it (clicking on the "Untitled-xx" title and change it) - this is currently possible on Notepad++ (although you have to right-click on the tab name, and select the "Rename" option, screenshot below). So the optimal way would be to have the default Sublime Text way merged with the Notepad++ way (in a more practical way).

image

+1

And another +1 for onearmedscissor's reply

Yes, please add this. I query our database within vscode and sometimes have many tabs open with various sql queries I'm using to check data with during development. I don't need or want to save all those queries, so having a preview text in the tab, being able to rename it, and having the current tab name accessible through ctrl+p goto anything would be extremely helpful.

Pushed a change to use up to 50 characters of the first line of the untitled document as title:

video

Some notes:

  • the title will also be used when saving as a suggested file name
  • if the first line is empty, the title will be shown as it used to be
  • there is no extra setting planned currently to enable or disable this (leaving the first line empty would be a way to force the old behaviour)

Quick question: would people expect that this feature is only enabled for untitled files that are of mode "Plain Text" and once you change the mode it would turn back to how it was? The rationale would be that e.g. if you had a JS file the first line may often be just an opening { and then editor titles would not be very helpful.

An argument against this would be an untitled file of mode markdown where it could still work well if the first line is a paragraph title.

@bpasero I assume files are initially plaintext on a new buffer, when does it decide that they're another file type, if the user saves the file as something known and/or when they set it manually? Curious when it would realize when a file is no longer plain text. Would it then revert it back to unsaved buffer, say if the user picked JavaScript as the filetype? Unless it'd cause bugs, I don't think it's the end of the world for it to always have the first line, although I do understand the concern. IMO it would be no worse than it is and in most cases better.

@bpasero Personally, I would love to have the feature available for all language modes. This would allow me to add a short description or reminder on the first line followed with a snippet of code in the appropriate language underneath.

Quick question: would people expect that this feature is only enabled for untitled files that are of mode "Plain Text" and once you change the mode it would turn back to how it was? The rationale would be that e.g. if you had a JS file the first line may often be just an opening { and then editor titles would not be very helpful.

An argument against this would be an untitled file of mode markdown where it could still work well if the first line is a paragraph title.

Yes I second @StrangePeanut. I am thinking of using this especially in the case of many open and unsaved SQL queries. I would put a comment on the first line (--some description of file/query), and ideally that would both

  1. Show up as the title, and
  2. Be accessible through the ctrl+p goto anything feature.

@khaytsus

@bpasero I assume files are initially plaintext on a new buffer, when does it decide that they're another file type, if the user saves the file as something known and/or when they set it manually? Curious when it would realize when a file is no longer plain text. Would it then revert it back to unsaved buffer, say if the user picked JavaScript as the filetype? Unless it'd cause bugs, I don't think it's the end of the world for it to always have the first line, although I do understand the concern. IMO it would be no worse than it is and in most cases better.

This would only play a role if the user changed the language mode of the untitled file from the status bar.

But I think given https://github.com/microsoft/vscode/issues/37414#issuecomment-576382328 and https://github.com/microsoft/vscode/issues/37414#issuecomment-576421011 there are good arguments to not depend on the language mode.

I brought this up because of https://github.com/microsoft/vscode/issues/88971

With https://github.com/microsoft/vscode/commit/b7a8a4aaf502a92e5e48a6dd91f172550db8b43b I pushed an additional change that will NOT take the first line content unless it contains words. This helps if e.g. the first line only contains characters like a bracket:

image

image

I still feel no matter what this is an improvement over previous behavior, but I have no strong feelings either way. For me 99% of the time my unsaved buffers are more or less scratchpad kind of things. If it's code, it'll be saved to disk and then it'll be a filename. But my use case is not everyones use case, and thank you for implementing this! I quickly looked at the insiders build yesterday and saw it in action, but have not done anything beyond a quick peek.

I heavily used this feature in Sublime (where it only works for plaintext), but I think the "show if it has words" approach is great, and may even some usecases enabled by Notepad++ (see https://github.com/microsoft/vscode/issues/37414#issuecomment-567011738).

@bpasero any plans to allow for regex or otherwise "excludes"? It was brought up as a good point that some people will have 10 tabs of just "include react from react". Ideally it would be both a user setting and a language file contribution so languages like Powershell could set their own parameters around what should initially be included in a file "title"

We still have https://github.com/microsoft/vscode/issues/88971 opened to provide a setting to disable this feature and if we add such a thing, it would be a language specific setting.

I am not sure about introducing regex or similar for configuring the editor title, however I would certainly see some value in having a similar setting such as window.title (e.g. editor.title) where you could configure the editor title with some variables.

I want to gather a bit more feedback from users before making a move though.

Here is an idea that came to my mind: show the actual untitled identifier as the description:

image

Discussed in our standup today, we will go with that model: every untitled file will show this as description next to the label.

Just saw this feature when I updated today. Delighted to see it implemented! Just wondering for a second iteration, if the custom titles can be made accessible to "go to anything"? So in the gif below, the files would be found according to the displayed name.

ezgif com-video-to-gif (1)

Soooooo good to see this live!

how to turn off this feature? I often edit very long text, the first line is too long to be title, and cover too much space to show this tab.

There is https://github.com/microsoft/vscode/issues/90378 that asks for a setting and as a workaround, leaving the first line empty will also get you there.

how to turn off this feature? I often edit very long text, the first line is too long to be title, and cover too much space to show this tab.

It would be great if we could simply rename unsaved files as well.

I typically keep various files open, set to various syntaxes, to use as a quick code snippet scratchpad.
Having simple utility titles like Javascript,PHP,CSS,SQL, etc. for quick identification and use is helpful.

I'm gaming this feature at the moment by inserting these labels in the first line - but this is a user frustration when all I need to do is iterate on versions of code quickly and I can't simply Ctrl+A & copy everything there is to add to another environment because there's non-essential content included as a weird workaround to a feature I can't currently opt-out of.

At the time of this posting, the fileName is set to readonly in the Typescript declaration file (vscode.d.ts): https://github.com/Microsoft/vscode/blob/1.31.0/src/vs/vscode.d.ts#L105

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omidgolparvar picture omidgolparvar  ·  3Comments

villiv picture villiv  ·  3Comments

curtw picture curtw  ·  3Comments

trstringer picture trstringer  ·  3Comments

sirius1024 picture sirius1024  ·  3Comments