Why Does Gedit Keep Randomly Opening New Instances When Opening Files from Nautilus?

Oh how I love Ubuntu and all its features, but this "bug" has been making me angry for so long and I've finally decided to ask for help here.

I've assigned all .php files to be opened with gedit whenever I double-click them in nautilus. Now, the behavior is strange.

  1. I have no gedit running
  2. I double click a file to be opened
  3. A gedit window opens and the file loads
  4. I double click another file to be opened

Now, there are 2 possible outcomes:

5A) The file opens in the same gedit window in a new tab

5B) The file opens in a new gedit window, resulting in 2 gedits running.

Whether A or B happens seems to be totally random and keeps on going infinitely. That means I double click on 100 files and I might end up with 60 gedits, some of which will have 1 tab, some will have 2 tabs, some will have 3 tabs...

This is extremely annoying and a fix for this would be very appreciated. Anyone ever tried to fix this problem?

This has happened in Ubuntu 10.04, 10.10 and 11.10. All Ubuntu versions I've ever tested.

5 Answers

Why...

gedit has quite an interesting algorithm to determine whether it opens a new instance or if it opens in a tab in an existing instance.

Located in the source file gedit-app.c in the function static boolean is_in_viewport, the algorithm tests if the current gedit instance is

  1. in the same screen number and display name
  2. in the same workspace
  3. greater than 25% of the edges of the view port

If all are true then gedit opens in the same instance in a new tab otherwise it opens in a new window.

In summary - the only realistic way of changing the behaviour is to change the algorithm...

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.