7

If a file is open in Sublime text 2, and then branch is switched which has changes to the file in the terminal, the file contents are not updated in the Sublime text 2 until the editor is selected by clicking on it.

How to auto-magically change it?

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
  • 1
    It's probably a setting in Sublime Text to control silently updating files that are opened in the editor, it shouldn't have anything to do with Git. –  Aug 20 '13 at 18:40
  • They automatically change for me. Are you sure the specific file you are looking at is really different on the other branch? Try *Project -> Refresh Folders*, but that shouldn't be required. – d_rail Aug 20 '13 at 19:18
  • @d_rail Clarified the problem in question. – Gaurav Agarwal Aug 20 '13 at 19:57
  • Ok, same for me. Then it's probably the os. Does another text editor act differently? – d_rail Aug 20 '13 at 20:05
  • @d_rail I am on Ubuntu 12.04. I have not tried other editors. But this is a nice feature if we have it on Sublime therefore the question. – Gaurav Agarwal Aug 20 '13 at 20:12
  • Try it on gedit to see if any other text editors act differently. If it is a feature request, I suggest adding it to [sublime text user echo](http://sublimetext.userecho.com/) – d_rail Aug 20 '13 at 20:39
  • Everyone, note that the problem is that “file contents are not updated […] *until the editor is selected* by clicking on it”. Sublime Text already silently updates the frontmost file when you give the app focus. The asker wants to avoid having to switch to the app to trigger the reload. – Rory O'Kane Aug 20 '13 at 20:43

3 Answers3

3

Sublime Text does not have any built-in way to do this. Though perhaps a Sublime Text plugin could do it by combining the file refresher plugin in the forum thread with a Python equivalent to watchr.

This Sublime Forum thread asks how to make a file in a different tab update automatically, given that Sublime Text is already frontmost. The asker couldn't find a way to make Sublime Text do that, but as a workaround, wrote a plugin that lets them hit a hotkey to reload all open tabs.

You could try to solve this with the same principle, by making a system-wide hotkey to switch to ST2 and back. You could implement the hotkey with AutoHotkey for Windows or Quicksilver or Keyboard Maestro for Mac. It's not as good as automatic updating, but it's the next best thing. You could hit the hotkey every time you expect the file to have changed.

You could even use a tool like watchr to monitor for changes in the files you plan to edit, and automatically triggers an AutoHotkey script or AppleScript that switches to Sublime Text and back when a file is updated. It would be even better to dispense with the GUI scripting and using Sublime Text's Python interface to reload the view without switching to it, but I don't know if Sublime Text allows you to run Python in the app from a program outside the app.

Community
  • 1
  • 1
Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
  • Can we conclude it is not possible in Sublime? – Gaurav Agarwal Aug 20 '13 at 21:47
  • @codingcrow I don’t see any related settings in “Preferences” > “Settings – Default”. So I think yes, Sublime Text does not have any built-in way to do this. Though perhaps a Sublime Text plugin could do it by combining the file refresher plugin in the [forum thread](http://www.sublimetext.com/forum/viewtopic.php?f=2&t=11752) with a [Python equivalent to watchr](http://stackoverflow.com/q/5816346/578288). – Rory O'Kane Aug 20 '13 at 21:50
  • @MattDMo That’s not what this question is about. You described ST’s behavior “if any file is changed … and you activate the tab the file is displayed on”, but this question [is about](http://stackoverflow.com/questions/18342382/file-content-in-sublime-does-not-change-on-git-branch-change#comment26928972_18342382) refreshing the tab *without* having to activate it. – Rory O'Kane Jun 27 '14 at 04:43
  • @RoryO'Kane you're right, I completely missed that. I came to this question from [this one](http://stackoverflow.com/q/24412876/1426065), where the OP couldn't get the code to update regardless of any manipulations. My bad... comments deleted. – MattDMo Jun 27 '14 at 04:46
-1

I had the same issue. Go to the git tab above and manually change the branch. that should revert the files back to any branch you want. The git tab above will work without typing anything into the terminal and will update with these git changes from sublime automatically.

Mark Antony
  • 91
  • 2
  • 1
-3

This just works in Sublime Text 2 and 3 on Mac.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Joel Z.
  • 543
  • 1
  • 7
  • 14
  • Please reread the question. OP is trying to get the changed code to update in Sublime **without** reactivating the window or changing the tab. Sublime's auto-reload function only works if you interact with the editor in some way, it doesn't do it on its own. – MattDMo Jun 27 '14 at 04:50