How to auto-reload current file in sublime text - sublimetext3

Sometimes I would like to modify files in another text editor and switch back, but Sublime Text 3 wouldn't reload the current file that I edited before.
How do I get it to reload the file automatically?

There's a setting to control whether you get to see a prompt, but otherwise Sublime Text reloads the file automatically by default.
See the setting in Preferences.sublime-settings:
// Always prompt before reloading a file, even if the file hasn't been
// modified. The default behavior is to automatically reload a file if it
// hasn't been edited. If a file has unsaved changes, a prompt will always
// be shown.
"always_prompt_for_file_reload": false

I believe AutoReload should do the trick.
You can also reload file manually using menu File->Revert File

If the file is changed on disk, and is open in Sublime, the default behavior is a dialog window that prompts to see if you want to reload the file.
If you have previously selected "Ignore All" when prompted with that dialog for that particular file, then Sublime's behavior for that file will be changed. The file view setting will be changed from True to False for reload_file_on_change.[1]
You can get the current file view setting (for whichever file is open in your view) by typing this in the console[2]:
view.settings().get('reload_file_on_change')
And can you set the current file view setting back to True with this[3]:
view.settings().set('reload_file_on_change', True)
I searched ["ignore all" sublime reload save] to find this question/comment from thundt and the answer from bschaaf in the Sublime Forum: Ignore All when unsaved changes and file changed on disk is not helpful!
Found via Sublime Text Docs > Settings > Troubleshooting
Found via Sublime Text API Reference > Settings > .set

Related

Enable Autosave files plugin on Sublime Startup

How can the AutoSave plugin for Sublime Text be automatically enabled on Sublime Text 3 startup?
link to auto-save is here
This particular package doesn't naively support the idea of enabling itself automatically when Sublime starts, so in order to accomplish this a small plugin is needed to make this happen, which I've posted below.
In order to use this plugin, select Tools > Developer > New Plugin... from the menu, then replace the stub plugin code that is presented to you with the code below and save the file in the location that Sublime will default to (your User package) as a Python file, for example auto_save_on_startup.py
NOTE: See the edit below; this plugin requires that you add a setting in order to control whether it's enabled or not.
import sublime
import sublime_plugin
# Sublime executes this every time it loads the plugin, which includes when
# it first starts, as well as whenever the this file changes on disk.
def plugin_loaded():
settings = sublime.load_settings("auto_save.sublime-settings")
# See if auto_save_toggle_at_startup is turned on; default it to
# not being turned on if the setting is missing, because that is
# how the package would behave if you didn't add the setting.
if settings.get("auto_save_toggle_at_startup", False):
sublime.set_timeout(lambda: sublime.run_command("auto_save"), 1000)
Edit: The original version of this plugin called run_command directly; however Sublime invokes the plugin_loaded endpoint before it has fully added all of the command classes provided by plugins, so it was possible for this to try to run the command before it was available.
The code above has been modified so that there is a delay imposed before the command triggers to give the commands time to become available.
As the comment suggests, every time Sublime loads a plugin file, it will execute the plugin_loaded() function inside of that plugin file, if it happens to exist.
Here the code checks the auto save package settings to see if you have set the value auto_save_toggle_at_startup to true, and if you have it will invoke the command from the auto save package that turns it on.
As such, you also need to select Preferences > Package Settings > Auto-save > Settings - User from the menu and add the appropriate setting. Preferences is under Sublime Text in the menu if you're using MacOS.
If that brings up an empty file (because you're using the default settings), then you should enter the following into the file and save it. Otherwise you can just add the setting itself to the existing settings.
{
// Toggle auto save at startup (from User/auto_save_on_startup.py)
"auto_save_toggle_at_startup": true
}
Here the comment is a reminder that this setting is being provided by something outside of the package itself, in case you forget.
Since the plugin command will only toggle the state of the auto save when it's loaded, you either have to add the setting before you add the plugin, save the plugin file to get Sublime to reload it once the setting is in place, or restart Sublime.
Alternatively you can replace the plugin_loaded() function to contain only the run_command line to unconditionally always toggle the state at startup, but you may want to temporarily stop it from doing that at some point in the future, which you could easily do by just toggling the setting.

Sublime text editor doesn't auto-refreshes the file if it is modified by another program

Although Sublime is a really powerful text editor but I am facing an issue. I have been using sublime text editor to view logs of my application.Suppose I have already opened file in my editor. After the logs are modified by the app server.
Sublime doesn't give any popup like we get in other editors
Example:
NOtepad++ says:
Also it doesn't modify the file. I have to close the file explicitly and then I re-open the file to ready the modified logs.
Only options i get in my sublime preferences are :
Please help..!
You are using an extremely outdated version of sublime (1.4). You can enable this functionality by upgrading and performing a small settings tweak:
Download the new SublimeText
Install it and open it
Go to the preferences menu and select "settings"
This will open the settings files for sublime, scroll down to line 349 on the left panel and copy that line.
Paste in the copied line into the right pane and replace "false" with "true"
Save and restart SublimeText
This should fix your issue entirely while also upgrading you to the awesome new SublimeText :)
Happy coding!
Set the following setting to true.
Menu > Preferences > Settings
// Always prompt before reloading a file, even if the file hasn't been
// modified. The default behavior is to automatically reload a file if it
// hasn't been edited. If a file has unsaved changes, a prompt will always
// be shown.
"always_prompt_for_file_reload": true

Can't open multiple files in Sublime Text 3

Whether I'm in a Single or 2 Column mode, I am only able to have 2-3 open files (tabs) per window.
When I hit what appears to be a limit, attempts to open a file (by clicking in Sidebar View) will replace an already open file.
Is there a setting I can change or have I hit a working-as-designed limitation?
Environment:
Sublime Text 3 Stable Build 3103
OS X (El Capitan) 10.11.4
BTW: If I use File Open it does not appear to have the same problem as I can open may files that way.
When you open a file from the sidebar with a single click, its tab will only remain open, if you edit or save the file. If you want the tab to stay open, double-click on a file in the sidebar.
You can override this default behaviour in your settings:
{
"preview_on_click": false
}

Sublime Text 3 Newly opened file override existing file [duplicate]

Today my Sublime 3083 became corrupted! I don't know why but every time I click on a file it opens on the same tab!
I cannot open two tabs at the same time. Fist file opens in a new tab and another opens in the previous tab and so on!
I did not installed any plugins recently. I just selected "Close Other Tabs" on menu.
What can I do?
Thanks
You must open the file using double click. If you open it using single click then you're using a feature called file preview, and that file will be closed when you preview other file unless the file has changes.
In addition, in the settings file you can set the preview_on_click option to false to disable the preview option; if you do that a click on the file won't do nothing, and a double click will still open the file in a new tab. As far as I know there's no option to open the file with a single click, only you can 'preview' the file (it's similar to open but the file get closed if you preview another file). Example setting:
{
"preview_on_click": false
}
I was facing a similar but little different problem. I was not able to view any tabs I was opening, and it was always opening a new file.
I fixed it by "View" -> "Show Tabs".

Sublime Text: File remains in tab even after deleted

When I delete a file that I don't need anymore, but then I have to close the tab manually. It is irritating.
Every time, I have to delete the file and then close the tab by confirming the discard changes.
Is there a way to delete the file in one shot.
Please Note: This happens in my MacBook laptop.
If you use the Side​Bar​Enhancements plugin, there is an option for that:
{
"close_affected_buffers_when_deleting_even_if_dirty": true
}
Make sure to add this to the correct settings file:
Preferences >> Package Settings >> Side Bar
I am not 100% clear on the details of your question. Apologies if this answer does not match what you are trying to ask.
Assuming you do not already have the file open this behaviour is a side effect of the choice to preview the file on click.
If this is the use case you are asking about then there is an answer.
If you look in Preferences -> Settings - Default and search for preview you should find this:
// Preview file contents when clicking on a file in the side bar. Double
// clicking or editing the preview will open the file and assign it a tab.
"preview_on_click": true,
This means clicking on the file to delete it causes it to be opened for preview and after deleting the file you also need to close the preview tab.
If you wish to change this behaviour open this file Preferences -> Settings - User and add this line:
"preview_on_click": false,
Then you should not open a preview and therefore will not need to close it after deleting the file.
If you already have the file you are deleting open for editing this will not cause the behaviour you are looking for.
There is an issue, so in order to don't make a link-only answer, I just paste here the main info :
Sublime Forum Question : Close tab after delete file?
Sublime Forum : https://www.sublimetext.com/forum/viewtopic.php?f=2&t=11686
Sublime Forum Answer :
You can do this with a plugin. I didn't really test this much, so you
may want to test on non critical stuff first. It does just close the
view, so worst case is that you lose some existing work. That being
said, I'm pretty sure it works fine.
import sublime_plugin
import os
class MyEvents(sublime_plugin.EventListener):
def on_activated(self, view):
if view.file_name():
if not os.path.exists(view.file_name()):
view.set_scratch(True)
view.window().run_command("close")
There's a plugin for this:
Plugin's Github Page
Seems like it should be a toggleable option.
This was annoying me so much, I created a plugin for it
https://gist.github.com/michaelkonecny/bb5a0d1cf43698c0ebe8673f92324ea3
Just download the close_deleted_files.py file and save it to
%AppData%\Roaming\Sublime Text 3\Packages\User (or similar path on Mac).
This is how the plugin works:
whenever a view is focused, it goes through the filenames of all the tabs in that window and closes those, whose files do not exist.
Extending #jwpfox answer
Below works for me:
Go to -> Top Menu -> Sublime -> Preferences -> Settings
Here Primary Preferences.sublime-settings file is not editable
when you click on settings, so two pages will open, now add the flag on the second page like below .. it will override the primary setting.
Alternatively, you can add the flag in below location file as well directly :
Packages/User/Preferences.sublime-settings
Add flag as
"preview_on_click": false,
The entire file looks like the below:
{
"ignored_packages":
[
"Vintage",
],
"preview_on_click": false,
}

Resources