Sublime Text Default Save Options - sublimetext2

Why when I save a file in Sublime Text 3 is the default save location the Sublime install directory and why is the default file type nothing?
I want to set the default save location to the Desktop and the default file type to .txt, how can I do this?
Here are my settings:
{
"font_size": 9,
"hot_exit": false,
"ignored_packages": ["Vintage"],
"remember_open_files": false
}

Without no line of code:
Preferences -> Settings -> paste this "default_dir": "your/favorite/path"
And you are done.
More here: https://sublime-text-unofficial-documentation.readthedocs.io/en/latest/reference/settings.html#file-and-directory-settings

Doesn't (currently) address the default extension issue, but you can also try AdvancedNewFile. Rather than creating an unnamed buffer, this plugin creates a named file. The default location is configurable, though there is no default extension.
Disclaimer: I'm the maintainer of the AdvancedNewFile plugin.
Edit
I've updated AdvancedNewFile to support default file extensions.

You can install the Default File Type plugin manually. It's a very simple plugin, and while the Package Control page says that it's for Sublime Text 2 only, I just installed it under OSX and it works fine. To install, navigate to %APPDATA%\Sublime Text 3\Packages and run
git clone https://github.com/spadgos/sublime-DefaultFileType.git DefaultFileType
Then, copy Packages\DefaultFileType\default_file_type.sublime-settings to Packages\User and change its contents to the following:
{
"default_new_file_syntax": "Packages/Text/Plain text.tmLanguage",
"use_current_file_syntax": false
}
Save the file, and now whenever you hit CtrlN to create a new file, it will be set to plain text. The plugin only works with the key combo, not via the File -> New File menu option.
As far as the save location goes, I have a theory, but I haven't been able to find documentation to back it up. At least on Win7 (for me), it seems like the default save location is the directory which contains the file that was open when you hit CtrlN or File -> New File to create the new file. For example, I had my Packages\User\Preferences.sublime-settings file open when I created a new file, and hitting CtrlS opened the Save dialog in Packages\User. I saved the file to the Desktop, hit CtrlN for a new file, entered something, then hit CtrlS and the Save dialog opened in the Desktop.
So, while there isn't a preferences setting for default save location, at least on Windows you can tweak it by always keeping a Desktop file open, then creating new files while that Desktop file is focused.

This should be a built-in option, honestly, but it seems fairly simple to automate yourself. Hit Tools -> New Plugin
Then paste this over the file that's created, hit save and call it "DefaultLanguage.py" or something:
import sublime, sublime_plugin
class EverythingIsPowerShell(sublime_plugin.EventListener):
def on_new(self, view):
view.set_syntax_file('Packages/PowerShell/Support/PowershellSyntax.tmLanguage')
Of course, you can change the language from PowerShell to ... whatever you prefer. You just need the relative path to the tmLanguage. You can get that by opening a file in your favorite language and then open the console (View->Show Console) and type:
view.settings().get('syntax')

Related

Sublime Text Prompt to Save File

I often will have a scratch pad in ST that I then close via Ctrl-F4. It always prompts me to save it, which I find to be a pain.
Is there a setting in ST where I can either change to default of this dialog to "Close without saving", or do not even prompt me at all if it is a new file (i.e. has no name).
You can set a tab to be a scratch buffer (doesn't prompt to save when closed). With the desired tab opened, open the console with Ctrl` and type:
view.set_scratch(True)
then hit Enter, and close the console with Esc. You can now close the tab whenever you want without being prompted. Of course, you can manually save the contents if you wish.
If you would like to have all new buffers set to scratch by default, you'll need a plugin. Create a new Python file in Sublime with the following contents:
import sublime
import sublime_plugin
class SetNewScratchBuffer(sublime_plugin.EventListener):
def on_new(self, view):
view.set_scratch(True)
def on_save(self, view):
view.set_scratch(False)
Save the file as Packages/User/set_new_scratch_buffer.py where Packages is the folder opened when selecting Preferences -> Browse Packages... (~/.config/sublime-text-2/Packages on Linux with ST2). Once saved, it should automatically become active, although you can restart Sublime to make sure. Now, all new buffers created with CtrlN or File -> New File will automatically have the scratch attribute set. This will be disabled when the file is saved, so you don't accidentally destroy changes to an opened file.

Unable to Edit Sublime Text's Default Settings

I would like to edit my default settings in Sublime Text 3 (beta build 3059) to not ignore the Vintage package - via Preferences > Settings - Default. I am running Sublime Text on Windows 7 Pro x64.
The Vintage package's documentation says to edit and save the default settings file to enable Vintage mode:
When I click the Settings - Default menu item, the default Preferences.sublime-settings file opens with expected content; but I cannot edit it. For example, deleting or backspacing to remove "Vintage" in "ignored_packages": ["Vintage"] does nothing.
I thought maybe the default settings file was marked readonly and tried to check it: C:\Users\me\AppData\Roaming\Sublime Text 3\Packages\Default\Preferences.sublime-settings does not exist. C:\Users\me\AppData\Roaming\Sublime Text 3\Packages\Default does not exist either.
To work around this, I tried to save the default settings file that Sublime Text opened for me - to see if that would create the Default directory and Preferences.sublime-settings in it. Instead Sublime Text gave the following error:
Unable to save C:\Users\me\AppData\Roaming\Sublime Text 3\Packages\Default\Preferences.sublime-settings
Error: The system cannot find the path specified.
Has anyone encountered this issue with Sublime Text 3 (specifically in trying to enable Vintage mode or otherwise) and worked around it...or found an authoritative explanation for it?
I reason that next I could try to add the missing Default directory myself, create an empty Preferences.sublime-settings text file in it, and try again to save the default settings file that Sublime Text opened for me; but this is starting to feel kludgy.
You should not edit the default settings. Add the files you want to ignore to the file Packages/User/Preferences.sublime-settings. You can open this file by going to Preferences - >Settings - User. Anything you set here will override the default settings.
I understand that you want to Not ignore the Vintage rather.
This still can be done using the Preferences.sublime-setting-User. AFAIK, any value given in this file overwrites the entries in Preferences.sublime-setting-Default.
Simply add this line with the "Vintage" removed in it to your User preferences and you'll be fine. (Remember to save the file after you did the edit and the change will happen instantly)
Also, not that VI mode in sublime is on edit more by default so make sure you press Esc first to make sure VI is activated.
// Settings in here override those in "Default/Preferences.sublime-settings",
// and are overridden in turn by file type specific settings.
{
"ignored_packages": []
}
Update
The latest format is,
{
"ignored_packages":
[
// Line below is commented out to enable Vintage.
//"Vintage"
],
// To start Sublime in Command moder
// rather than Insert mode.
"vintage_start_in_command_mode": true
}
Install 'PackageResourceViewer' from 'Install Package' in the Command Palette.
Then use 'PackageResourceViewer' command in the Command Palette.
Use that to extract/open the default packages you previously were unable to.
More information here : https://github.com/skuroda/PackageResourceViewer
I use Sublime Text3 recently in Windows 10. I'm trying to change the file: Packages/User/Preferences.sublime-settings. And met your problem "Enable to sa ve Preferences.sublime-settings".
I solve this by changing file Preferences.sublime-settings's property, in Security, edit "user"'s permissions. Allowed to modify.
And then I can edit and save Preferences.sublime-settings
When I install Sublime Text in Linux, I report the message NOTADIRECTORYERROR: [ERRNO 20] NOT A DIRECTORY. At first I thought it was because the Defalut folder was missing, but later I realized it wasn't. I then checked the Settings of my SublimeREPL. Sublime-setings and deleted the contents after bin, and found that the program worked fine.
old: "default_extend_env": {"PATH": "{PATH}:/home/bgnv5/anaconda3/bin/python"},
new: "default_extend_env": {"PATH": "{PATH}:/home/bgnv5/anaconda3/bin/"},
Spent a lot of time to find problems, I hope to help you.

start opened file from sublimetext in associated program

i usually edit files in sublime text 2 that can also be edited and compiled with another program. As i have them already opened in sublimetext i do the following:
right click and choose "copy file path" (to clipboard)
Win+R to open windows run dialog
CTRL+V to paste the file path
hit enter to open the file with the associated program
i wonder some shortcut can be configured so it automatically starts the opened file with its associate program
thanks in advance
This can be done. I was in a very similar situation using Sublime as my editor of choice over the default SAS program editor. I was able to use the win32com.client.dynamic.Dispatch module to connect to SAS via OLE and pass text from Sublime directly to SAS using Sublime's build system to call my plugin. Making the connection was the easy part, it was the other processing that I had to do which was the time consuming part, but since you want to pass just a file name or the entire contents of your file, this should be a fairly straightforward plugin. Since I do not know what program you wish to open, here is the code that makes my implementation work. Maybe you caan glean something out of this.
def send_to_sas_via_ole(selected_code):
from win32com.client.dynamic import Dispatch
sasinstance = Dispatch("SAS.Application")
# submit the lines to sas
for selection in selected_code:
# for some reason cannot send as one big line to SAS, so split into
# multipe lines and send line by line
for line in selection.splitlines():
sasinstance.Submit(line)
and then the call in the run method of my plugin class:
class RunSasMakoCommand(sublime_plugin.TextCommand):
def run(self, edit):
try:
send_to_sas_via_ole(selected_code)
except Exception as e:
print "\n".join(selected_code)
print "Couldn't connect to SAS OLE"
print e
Good luck!
Open 'regedit.exe';
Navigate to
HKEY_CLASSES_ROOT\Applications\sublime_text.exe\shell\open\command
correct the path. Exit 'regedit.exe'
(optional) restart 'explorer.exe' or reboot your PC.
enjoy :p;
Right click on the file, press "Properties". You will see Opens with SomeProgram and then a change button. Click on the change button, and then look through the list for Sublime Text, if you can't find it, you can choose an application using the file explorer, from there you can navigate to C:\Program Files\Sublime Text 2 and choose sublime_text.exe

Sublime Text 2: How to make Sublime run a command (fold code) when opening a file by default?

I would like to make it so that whenever I open a file in Sublime it will automatically do "Fold Level 2" Coding which is command shortcut Ctrl-K,Ctrl-2 (or CMD-K, CMD-2). I use both mac and pc.
I don't want to enter that shortcut everytime, instead I would like Sublime to automatically run that on opening a file. Please let me know if there a way to do that.
I think that the best solution to your problem is Buffer Scroll plugin. It remembers and restores a lot of things, folding included.
If you don't want to install that plugin, you can create your own:
Create new plugin Tools / New Plugin...
Insert code
import sublime, sublime_plugin
class Folding(sublime_plugin.EventListener):
def on_load(self, view):
view.run_command("fold_by_level", {"level": 2})
Save it in your User directory with the filename you prefer.
This will set folding level to 2, for every file you open.

Sublime Text 2 Default File Type on new file

I was looking around and the questions and answers did not seem to match what I am looking for. Anytime I open a new file it defaults to a plan text file. I mostly work with HTML files so I was wondering if there is a setting that would be changed so that when I open a new file it will default to HTML? Hope this is possible.
Rob
Create a new plugin Tools > Developer > New Plugin...
Paste this in:
import sublime, sublime_plugin
class EverythingIsPowerShell(sublime_plugin.EventListener):
def on_new(self, view):
view.set_syntax_file('Packages/PowerShell/Support/PowershellSyntax.tmLanguage')
Save and call it NewTabSyntax.py. New tabs will now default to Powershell.
You can change the syntax to whatever you prefer. To find out the "path" of a particular syntax, simply open a file of that syntax, open the console (View > Show Console) and type:
view.settings().get('syntax')
pls install Package sublime-DefaultFileType https://github.com/spadgos/sublime-DefaultFileType
which will automatically sets the syntax for new files.
It is possible with the ApplySyntax Plugin. Once it is installed (e.g. via PackageControl), you can set the ApplySyntax User Settings like that:
"new_file_syntax": "HTML",
Now if you open a new file, your default syntax will be HTML. Of course you can set every Syntax you have installed.