If you open the file from gedit (Ctrl+O, or use the big 'Open' button shown) it will open the new file in a new tab. If you open new files from Nautilus (or another file manager), it may or may not. Also, as @harisibrahimkv points out, files with different permissions/users will be handled differently.
![gedit file open dialog](https://i.stack.imgur.com/YHf0x.png)
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
- in the same screen number and display name
- in the same workspace
- 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...
How...
The following is a quick way to get a consistent way of opening gedit... it will always open a new instance.
install the basic development tools
sudo apt-get install devscripts build-essential fakeroot
get the source
cd ~/Downloads
mkdir build
cd build
apt-get source gedit
cd gedit-3.2*
make the change
Open gedit-app.c
gedit gedit/gedit-app.c
![enter image description here](https://i.stack.imgur.com/XyS2K.png)
add return FALSE;
as shown and save.
What this does is to always exit the routine saying "i'm not running in a viewport and therefore always open a new instance"
If you use return TRUE;
this will always open in an existing instance of gedit in a new tab...
give it a unique package name
OK, we need to give the package a unique name to prevent repository updates from overwriting your changed package
gedit debian/changelog
now append +yourname
to the top line version and save the file i.e.
Note - to be absolutely sure - after installing the modified package below, lock the version as per the linked question below.
![enter image description here](https://i.stack.imgur.com/qqaMO.png)
build the package
sudo apt-get build-dep gedit
debuild -i -us -uc -b
Go for a coffee...
cd ..
sudo dpkg -i gedit*.deb
Linked Question:
- How to prevent updating of a specific package?
Best Answer
There's also a Session Saver plugin to save and restore working sessions.