When I write something in the empty canvas of Sublime Text and try to save it, it defaults to / (macOS) which can get irritating.
How can I change the default save dialog location or current working directory of sublime text to say ~/Downloads/Test ?
I normally launch the app by GUI, but if a CLI solution (like environment variable) is there, which I can use as an alias, it'd be okay too.
For a GUI solution on macOS, in Sublime Text go to Preferences -> Settings, then paste "default_dir": "your/favorite/path"
And you are done.
More info here: https://sublime-text-unofficial-documentation.readthedocs.io/en/latest/reference/settings.html#file-and-directory-settings
In this page they address a similar question to yours https://forum.sublimetext.com/t/setting-to-change-the-default-save-location/50989. You can make minimal sublime text plugin to save files to a fixed path, you can then bind this it to a any key, even override the default save key.
import sublime
import sublime_plugin
class CustomSaveCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Replace the my_custom_path with the absolute path you want.
self.view.settings().set("default_dir", "my_custom_path")
self.view.run_command("save")
Then bind it to the same keys as save: command+s
Also this plugin can help you AdvancedNewFile, you can set aliases to get to the path you want faster, or modify in the plugin settings default_path to the path you want.
Related
I want to increase the default font Lucida Console from 9pt to 12pt and adjust the blue color quality. Currently the only way I can find to do it is by right-clicking the Cygwin window and selecting Options & Text and Apply as described in this answer.
I tried to edit .minttyrc to change the font size and color as suggested here. Settings are shown below. But when I relaunch the Cygwin shortcut the default window reappears.
C:\cygwin64\home>cat .minttyrc
FontHeight=12
Blue=127,127,255
BoldBlue=191,191,255
Is there a way to set .minttyrc programmatically ? Surely there is a way to change the default settings without doing this manually every time.
EDIT.
I have Cygwin configured like this ( a screen shot of the window opened by the DOS batch file).
Here is the code suggested by me_and
C:\cygwin64\home\Greg\Work\CMI>cat ~/.minttyrc
cat: '~/.minttyrc': No such file or directory
I can get .bashrc to find .CMI_functions in a sub-directory but I don't know how to get it to find .minttyrc in the same directory
CONCLUSION.
Best results came from editing the Cygwin batch file to relocate all .executable bash files, together with .minttyrc, into C:\cygwin64\home\%USERNAME%.
cd %USERPROFILE%\Desktop\Archive\UTIL
xcopy . C:\cygwin64\home\%USERNAME%\Work\CMI\UTIL /E /I
copy Misc\* C:\cygwin64\home\%USERNAME%\Work\CMI
copy Bash\.* C:\cygwin64\home\%USERNAME%
copy Scripts\*.sh C:\cygwin64\home\%USERNAME%\Work\CMI
The Super User question you've linked to talks about putting the .minttyrc file as ~/.minttyrc, which as a Windows path (at least with default settings) would be something like C:\cygwin64\home\Greg\.minttyrc, but you have it as C:\cygwin64\home\.minttyrc. That's the wrong place, so it's never going to work.
To change the settings for Mintty, you need to have the file in the right location, otherwise it won't be able to load them. Try moving the file to the correct location, and see if that resolves things for you.
In almost any desktop application that I've used, it's possible to select a path to open or save files using what appears to be a standard file navigator that looks just like Finder. For example, if I go to save this webpage,
this menu comes up, and I can select where to save it, create a new folder, etc. Is there a system call to start this menu from my own program, and presumably return a path to the selected file or folder?
Have a look at NSOpenPanel.
It does exactly what you seem to be looking for:
The NSOpenPanel class provides the Open panel for the Cocoa user interface. Applications use the Open panel as a convenient way to query the user for the name of a file to open.
If anyone else sees this, Johannes Weiß's answer is correct: NSOpenPanel is exactly what I was looking for. In Python, the code for it looks like this:
from AppKit import NSOpenPanel
# the following import is only used to prevent multiselect and directory select
from objc import NO
panel = NSOpenPanel.openPanel()
# set the title (not required)
panel.setTitle("open file")
# prevent multiselect and directory select (not required)
panel.setAllowsMultipleSelection_(NO)
panel.setCanChooseDirectories_(NO)
# open the panel
panel.runModal()
# get the path
path = panel.filenames()[0]
A longer example can be found here.
I would like to set up two separate themes in ST3. One theme would be for local files, while the second would be for any file opened via my FTP app (Transmit). Is this possible?
The simplest solution may be to override any file coming from the FTP's cache folders. But I have no idea if this is possible.
Yes, this is possible with a fairly simple plugin. Open a new Python file in Sublime, and add the following to it:
import sublime
import sublime_plugin
class TransmitColorSchemeCommand(sublime_plugin.TextCommand):
def run(self, edit):
if "/path/to/transmit/tempfiles" in self.view.file_name():
self.view.settings().set("color_scheme", "Packages/Color Scheme - Default/Monokai.tmTheme")
class TransmitEventListener(sublime_plugin.EventListener):
def on_load_async(self, view):
view.run_command("transmit_color_scheme")
Make sure you adjust "/path/to/transmit/tempfiles" to the actual path you want, and change the "color_scheme" setting to the color scheme you want to use for Transmit files. Save the file as Packages/User/transmit_color_scheme.py where Packages is the folder opened when selecting the Preferences -> Browse Packages... menu option. On OS X, it's ~/Library/Application Support/Sublime Text 3/Packages.
Once saved, the event listener will start up immediately, and any file you open that contains the specified path will have the color scheme set to whatever you indicate. All other files from other paths will use your default color scheme.
Have fun!
Please note that this plugin will only work in ST3. To make it work in ST2, change def on_load_async to def on_load.
On Linux, Sublime Text shows the full path of my currently open file in the title bar by default, but on OS X, it only shows the name of the file.
How can I configure Sublime on OS X to show the full path to the currently open file in the title bar?
With Sublime Text 3, all that's necessary is to edit your Sublime user preferences (Preferences -> Settings - User) to include:
{
// ... other settings
"show_full_path": true
}
Then, restart sublime so the new settings are loaded.
This will override the OS X-specific default value for this option, which is false.
Should be the same for Sublime Text 2/3
(Tested on OSX Yosemite)
While in sublime go to your "Sublime Text 2/3" menu and move down to "Preferences ->" then go down to "Settings - User" this will open your user settings in Sublime
If you have never added any user setting it should just contain some comments. If so you can just paste in the following:
One setting
// Settings in here override those in "Default/Preferences.sublime-settings", and
// are overridden in turn by file type specific settings.
{
"show_full_path": true
}
Two settings
( one setting per line and separated by a , )
// Settings in here override those in "Default/Preferences.sublime-settings", and
// are overridden in turn by file type specific settings.
{
"show_full_path": true,
"save_on_focus_lost": true
}
Now save this settings file.
Now you should be able to see the full path in the title bar.
(NOTE: for me I didn't need to restart Sublime see the path in the title bar, but I think I had to when I was using the Windows version of the program)
FYI in Sublime's full screen mode/distraction free mode, you need to move your pointer to the top of the screen to see the title bar.
I usually just run Sublime where I have manually sized my window to be the full size of the screen so I can always see the title bar.
Just for clarification when you read:
//Show the full path to files in the title bar.
// On OS X, this value is overridden in the platform specific settings, so
// you'll need to place this line in your user settings to override it."
It was trying to tell you to modify the Sublime Text User Settings not any OSX system settings.
In Sublime Text 3 for Mac OS X:
1) Add "show_full_path": true to your Sublime Text / Preferences / Settings - User file. Add this line even though it already appears as true in the default prefs. Terminate the line with a comma (,) if you include it among other prefs. Save your changes.
2) Quit and relaunch Sublime.
Unlike other user prefs, you won't see this change until you relaunch the app.
How can I map Open Recent, or "open last file" to a keyboard shortcut?
This is my pitiful attempt so far:
{ "keys": ["super+shift+r"], "command": "open_recent"}
I tried looking at the console (Ctrl-`) while using Open Recent but it doesn't display anything.
In general, how does one go about adding key bindings? And is there a more appropriate place that Stack Overflow for this question?
Thanks!
Key bindings should be added to the User key-binding preferences. Adding to the default settings will also work, but the settings will be overwritten when a new version of Sublime Text 2 is installed.
Your attempt matches the general structure of a Sublime Text key-binding, but "open_recent" isn't a valid command. From what I can find in the documentation, I think the Open Recent menu keeps track of the different file names then calls open on whichever file is selected, instead of calling an open_recent command.
If there isn't a way to get the name of the most recent file, you could probably write an extension that kept track of the most recent file and then opened it, but that probably be a fairly kludgy solution.
The command is reopen_last_file. So you should add something like this:
{ "keys": ["ctrl+shift+r"], "command": "reopen_last_file" },
Little PS: I'm using ctrl+shift+t, so that the shortcut for reopening the last document is consistent across my browser, IDE and editor.
I suggest you try out a couple of packages:
https://github.com/spadgos/sublime-OpenRecentFiles
or:
https://github.com/paccator/GotoRecent
And the easiest way to install them is with this package control, package:
http://wbond.net/sublime_packages/package_control/installation
That should give you what you want...