Re-install sublime, the mouse on the file right-click, there is no “open with sublime Text” option, and how to set up back
Right-click the file and do not have the "open with sublime Text" option
- Press windows+r
- write
regedit
and press enter, this should open a window with a tree structure on the right - unfold
HKEY_CLASSES_ROOT/*/shell
- right click on shell and select New > Key and name it “Open with Sublime Text”
- right click on that key and again select New > Key and name it “command” and select it with left click
- On the right side there should be something like (standard) on the top. Double click on this to change the value.
- Insert
C:\Program Files\Sublime Text 3\sublime_text.exe "%1"
(you may need to adapt the path to your installation).
Now you should have the command and it should work.
If you also want to have an icon you:
- select the “Open with Sublime Text” key
- right click and select New > string/char array and call it
Icon
- insert the value
C:\Program Files\Sublime Text 3\sublime_text.exe,0
Short version:
- create a file
sublimetext.reg
with the content:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text]
@="Open with &Sublime Text"
"Icon"="C:\\Program Files\\Sublime Text 3\\sublime_text.exe,0"
[HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\command]
@="C:\\Program Files\\Sublime Text 3\\sublime_text.exe \"%1\""
double click on it to execute it
Everything works fine.
But I have one problem and that is if we select a directory and open in Sublime Text.
The probme is that it open’s that directory in new sublime window.
I want to append that directory in the existing sublime window.
In that case you need to specifically tell Sublime that it’s supposed to add the folder to the current window instead of opening a new one, which you can do by adding the --add
command line option (see below).
For example, sublime_text c:\myFolder
will open the folder in a new window while sublime_text --add c:\myfolder
will add it to the existing window.
You may want to work it so that you get both options (one with the --add
and one without) in case you want it to work both ways.
C:\Users\tmartin>subl --help
Sublime Text build 3147
Usage: subl [arguments] [files] edit the given files
or: subl [arguments] [directories] open the given directories
Arguments:
--project : Load the given project
--command : Run the given command
-n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit
Filenames may be given a :line or :line:column suffix to open at a specific
location.
When you run Sublime from a terminal, it interacts with the running copy of Sublime and tells it what you asked it to do, and then quits, leaving the already running copy of Sublime to carry out your instructions. If there’s not already a copy of Sublime running, it starts it running and then passes the command along before quitting.
Those arguments are only of use to you if you’re using the command prompt; if you’re just setting up Windows or your OS to open files, including creating shortcuts or what have you, you don’t need to worry about them.
That said, those arguments change what the command line portion of Sublime does in addition to passing the command along.
-w or --wait: Wait for the files to be closed before returning
Normally if you said subl test.txt
, the command would tell Sublime to open the file, and then it would quit. Saying subl -w test.txt
instead tells it to wait until you’ve closed the file, and then quit. This is useful if you’re using Sublime in a script or process that should not continue until you’re done editing the file (for example, using Sublime as the editor for your git
commit messages).
-b or --background: Don't activate the application
Normally subl test.txt
would tell Sublime to open the file, and then give Sublime the input focus so that you can immediately start editing. Saying subl -b test.txt
tells it to open the file, but the focus remains where it was; Sublime is now sitting with the file open for you, but you can continue in the command line. You might use that if you want to queue up a file for editing but you’re still doing something else and not ready to get to editing yet.
-s or --stay: Keep the application activated after closing the file
It’s not mentioned here, but this command only does anything if you’re also using -w
or --wait
command to wait for the file to be closed before exiting.
Normally (in most cases, but see below) if you say subl -w test.txt
, it will open the file, and when you close it focus goes back to the terminal that you used to run subl
. If you instead say subl -ws test.txt
, then when you close the file, the waiting process still exits, but Sublime remains in the foreground instead.
Note also that this doesn’t always work, I think based on platform. On my Linux box, Sublime always remains in the foreground whether I use that command option or not, although it is respected on my Windows and Mac computers. Possibly the distribution of Linux that you’re using might have something to do with this, but I only have the one version so I don’t know.
Is there any way that if we use -n
argument.
And we have a directory opened in the sublime text worked on it and then close the sublime windows and if we open another directory (generally what happen, the previous sublime window also shows up with the new window).
I want that previous window should not open, only the new window should open.
Can that be possible?
You can change the state of this setting, which defaults to true
:
// Exiting the application with hot_exit enabled will cause it to close
// immediately without prompting. Unsaved modifications and open files will
// be preserved and restored when next starting.
//
// Closing a window with an associated project will also close the window
// without prompting, preserving unsaved changes in the workspace file
// alongside the project.
"hot_exit": true,
When it’s turned on, Sublime remembers the state of the application when you quit it and restores it again the next time you start. This includes any windows that you had open, the files that were open, and even goes so far as to remember changes to files that haven’t been saved yet so that you don’t lose work or have to save them before it quits.
So if you open a folder in a new window, then quit, then open another folder, first it starts and restores the previous state (including all windows) and then it creates a new one to open the file.
If you turn this off, this state isn’t remembered (although the panel layout is), so you only get the window you asked for. This also means that if you close a window or quit with unsaved files, you will be prompted to save them or lose your changes.
This is an all-or-nothing setting though. You either get it to keep your session data and get old windows back when you might not want them, or you never get your windows back and lose the ability to save session information.