How can I programmatically save a Sublime Text 3 workspace (without a dialog box)? - sublimetext3

I really want a way to switch programming contexts quickly without hunting for windows that I've left strewn about. What would be nice is a command line tool to let me switch between different patches that I might be working on, and automatically open the sublime text workspace that I had open the last time I was working on that patch. The issue is that in order for the tool to know about the workspaces associated with said patches, it either needs to be told about them explicitly, or it needs to be able to tell sublime to save the current workspace with a specific file path.
Sublime does have a save_workspace_as command, but it opens a saveAs dialog, which is not what I want, and I can't seem to find any documentation that suggests that save_workspace_as can take an argument.
Any ideas?

Related

Auto refresh in Sublime Text 3

I want Sublime Text to auto reload files when they are changed in the hard disk (by some process else). Although I am not expecting to have my code open in different places, I use the editor to see resulting files, which is why this feature is crucial to my coding setup. I’ve figured out the option to prompt for the reload as below. But my issue is, it takes a long time for Sublime Text to realize the file has changed and give me the prompt. The files are in a Linux server and I am accessing them through Samba in Windows. Previously I've used Notepad++ which instantly recognize the change and prompt me to reload - so this is not to do with the file systems or hardware. Is there a way to achieve this in Sublime Text or VSCode?
"always_prompt_for_file_reload": true

Cannot add Sublime project preferences after opening repo via Github Desktop

I have been happy to notice that Github Desktop lets me open a repo in Sublime Text. It seems to open the repo as a project but I have a hard time figuring out how to edit the project preferences for the repo. Specifically, I would like to add file_exclude_patterns.
I have tried Project > Save Project As... in Sublime, but then when I open the repo through Github Desktop it opens two Sublime windows: one that respects my project preferences and one that ignores them.
From your problem description, it sounds like you might be running into issues with the hot_exit setting. When that setting is turned on (which is the default), then whenever you quit Sublime, it saves the state of all open windows into a session file before it quits.
That session file contains a list of every window that's open, what files are open in each, their scroll position, selection, any unsaved changes to files, and so on. When you restart Sublime, it loads the session file and restores its state back to what it was previously, seamlessly putting you back to where you were before.
One of the potentially unintended side effects of this is that the session is always restored every time you start Sublime. So if you have a project open in a window, and you quit, Sublime keeps a record that you had one window containing that project. If you start it and tell it to open the same project, it will first restore the session and then open the project, resulting in two windows.
As such, turning off hot_exit may solve this problem for you. When it's off, the session information isn't saved, and Sublime starts in a more or less "fresh" state every time. The downside to this is that you will be prompted to save all unsaved files, your list of open files is lost, etc. Depending on your use case, this may or may not be an issue.
If you already have that setting off and this still happens, then the issue would be that GitHub for Windows is opening both the project and the folder, which would result in two windows. In that case there's not a lot to do but poke the people in charge of GitHub for Windows and tell them to fix their code.
On the other hand, if you turn off hot_exit and you get one window, but it doesn't respect your project preferences, then the problem is that GitHub for Windows is only opening the folder, not the sublime-project file.
In that case, there's not a whole lot to be done, unfortunately. Sublime won't load a sublime-project file just because it happens to be contained in a folder, since there can conceivably be many of them in there (many people keep their project files in a single folder, for example).
If Sublime is associated with sublime-project files, then opening the sublime-project file would result in Sublime opening the project for you, so that may be a possibility as well.
Beyond that, you're more or less in the realm of things like using Project > Switch Project or Project > Quick Switch Project to get the window to display what you want; that's not very handy with regards to just opening the project, though.

In vscode, how to put editor regions inside tabs, and not the other way around?

I've been trying Visual Studio Code for a few days, and it's the first editor that I used in years that makes me feel I could switch from my beloved vim.
Now, it's hard to get used to new habits when you have years of muscle memory, but I'm trying to keep an open mind. There's one thing that's bugging me, though, and I could not find a way to get around: it's the fact that editor regions and tabs are "swapped". Let me explain:
In vscode, you define editor regions by splitting your screen, then each region can contain as many tabs as you want.
My problem is, that does not fit my workflow. Here's what my workflow used to be with vim, where regions are inside a single set of tabs (I mainly work with Django):
In a first tab, I've split my editor in half and I'm editing my models.py and forms.py side by side.
In a second tab, I've split the editor in half, I'm editing my views.py on the left hand side, and the right hand side is again split horizontaly, allowing me to edit multiple templatetags files.
In a third tab, I'm editing my main template, and I don't split the editor since the file may contain very long lines.
In a fourth tab, I'm editing several html files and the editor is split multiple times.
Etc.
That way, I can very quickly go to edit my models, then my views, then the templates, and start over in quick iterations.
With vscode, where the tabs are inside the fixed regions, not so much.
So my question is, what solution could I use? Am I missing a big feature here? Are there any extension that would allow me to get my old workflow back?
I'm also open to suggestions about new workflows.
As #romainl pointed out: the workflow is different, it doesn't work that way with VS Code (and I know, I'm a vim user, too).
The best you can get that is vaguely close to what you're used to is to consider VS Code windows as you did with vim tabs.
To give you an idea using your example:
You open a VS Code window and open side by side models.py and forms.py
You hit Ctrl+Shift+N (or Command+Shift+N on a Mac) and open a new window. There you open your views.py on the left and split the right one horizontally for the templates.
You open a new window again and repeat.
This way you can switch between different layouts with Alt+Tab
(or Command+Tab).
You could speed this up a bit by saving different workspace files for different files that you want open, because I think (not 100% sure) that saving the workspace also saves the layout.
There's a couple of annoying things with this approach though:
If you have multiple windows open in general (say, a browser, slack app and so on), they'll also appear in the list when you try to switch.
I'm not sure if the open folder will be remembered when opening a new window, but you can work around that by saving the workspace and opening it.
It's annoying but at least there's already a feature request about this ( https://github.com/Microsoft/vscode/issues/41486 )

Run code on file open in Sublime Text

I'd like to run some code in Sublime Text every time I open a file. Is there any way of doing this?
The background, if you want more context: I recently started using Sublime Text as my main editor, and although I love having Vim mode available through the Vintageous plug-in, I just want it to be available, not forcing its way into being turned on every time I open a file.
The author does not seem open to adding an option for being turned off by default--which is entirely okay: I'm not trying to be critical of his choices, and I'm glad he's made his code available to me--so it occurred to me that Sublime Text might offer some way of running some code every time you open a file. If so, I would simply run something that sets the mode to the normal Sublime Text mode (as opposed to Vim's "normal" mode).
You can run code in response to various events by creating a plugin and subclassing sublime_plugin.EventListener. The methods you would be most interested in are on_load() and on_new(). From there, you can either run an existing command, or you can make your own in a different class (probably subclassing sublime_plugin.TextCommand).

"Registering" GVim in Windows XP

This is probably bordering off-topic-ness here, but not a lot of people on SuperUser use GVim, as opposed to here, so I'm leaving it here.
The problem is simple - I'm using GVim 7.3. from vim.org, downloaded it in the form of archived binaries (the two archive files) like always and replaced the older version. However, I can't get Windows to recognize it and to associate a file extension to it.
From windows explorer go to, let's say, .py file, Open with ... / Browse / gvim.exe in its directory and ... nothing. Like it never happened.
Does anyone have any idea what could be causing this behaviour? It's mighty annoying to have to open every file from within Vim manually.
I think the default installer ("self-installing executable") from vim.org lets you register shell associations; this means you get an entry "open with vim" in every context menu from the explorer. Did you not use this file?
I'm looking at this page and I'm thinking about this download.
This doesn't answer your question, but it's a different way to edit with gvim from the context menu.
Create a .reg file with the contents below (adjusting your path to gvim.exe) and execute it. Then whenever you right-click on a file in explorer you will have an "Open with GVIM" option.
REGEDIT4
[HKEY_CLASSES_ROOT\Unknown\shell]
#="Open with GVIM"
[HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell]
[HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with &GVim]
#="Open with GVIM"
[HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with &GVim\command]
#="C:\\Vim\\gvim.exe \"%1\""
I gave up trying all kinds of tricks through the registry, but this solution works for me just fine. I might add, I'm having the same issue on Windows 7. Since Windows seems to be able to do the association with vim.exe just fine, and this is apparently tied to the file name, I moved vim.exe off as say vim.ex$ and made a copy of gvim.exe to vim.exe. Cheap and easy way around this goofy problem, and I can't say I ever use vim.exe on purpose.

Resources