1

I have a .txt file whith quite a long text content.

I noticed whenever I read the content up to a certain line and close the file, if I re-open the file later (right away, hours later, or days later), the file opens always displaying me the same region where I ended my previous reading and closed the file.

Do you have any explanation of this behavior? (any hints, implementation ...)

I open the file with Gedit.

terdon
  • 242,166

1 Answers1

7

Many text editors store your last cursor position in files you have edited. The information is often only stored for files you have saved with the editor, and different editors may behave differently in this regard. But it is not stored in the file you edited. It is stored somewhere else instead, because inside a plain text file, there is no good place to put it. Gedit uses gvfs to store and retrieve this information for each file.

As explained in CrazyApe84's own answer to Where does gedit store the last cursor position? (on Ask Ubuntu), gedit remembers where you were in each file by writing your cursor positions to ~/.local/share/gvfs-metadata/home. It reads them back when you reopen the file. Rather than containing explicit code to open, write, and read that file, gedit uses gvfs and that file is where these particular gvfs data happen to be stored. The information is stored in the metadata::gedit-position gvfs attribute of each file you edit. The reason that is not a contradiction is that a file's gvfs attributes aren't part of the file or even its regular filesystem metadata. They are stored in files the gvfs-metadata directory, like home.

If you want to view--or even edit--this information yourself, install the gvfs-bin package:

sudo apt update
sudo apt install gvfs-bin

(That's for Debian and its derivatives, such as Ubuntu, which you are using. Also, depending what desktop environment you are using, commands like gvfs-info may be installed already. But gedit does not use these command-line utilities itself and installing gedit on a non-GNOME desktop environment does not install gvfs-bin.)

Then you can use the gvfs-info command to view the attribute. Suppose the file you edited was called your-file and it is in the current directory. Then run:

gvfs-info -a metadata::gedit-position your-file

Or, as CrazyApe84's answer explains, you could grep for metadata::gedit-position (or just position, if you're willing to have a few extra lines) in the output of gvfs-info your-file:

gvfs-info your-file | grep metadata::gedit-position

There is a popular fork of gedit called pluma, which comes with the MATE desktop environment (and which, like gedit, can be installed separately if you use a different desktop environment). If you're using pluma instead of gedit, the attribute is metadata::pluma-position rather than metadata::gedit-position. In case you've ever wondered why gedit and pluma don't share information about where you were in a file, that's why.

Eliah Kagan
  • 4,155