Sublime Text Default Save Options

谁说胖子不能爱 提交于 2019-12-11 03:59:34

问题


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
}

回答1:


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.




回答2:


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.




回答3:


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')


来源:https://stackoverflow.com/questions/18672029/sublime-text-default-save-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!