7

I have a text file. I created the content of the text file by copying from some webpage into it. During the creation, I was completely under gedit. I then saved the file and exited gedit. But since then, I haven't been able to open the file in gedit (although I could open it in Emacs). I tried to open it in gedit, but fails because "Unexpected error: Invalid byte sequence in conversion input".

  1. How shall I open such a file successfully, if without changing the content of the file?
  2. I guess there are some "bad" characters in it, and want to see what they are and remove them if they are not important. How shall I identify those culprit characters?

Thanks!

3
  • 1
    Try opening it with vim - it will open anything, I believe. It may warn you if it's got binary data, but I think it will still open it. If you need to edit the file, and totally don't know how to use vim, type this to get help: :help tutorial Jul 7, 2012 at 20:06
  • This happens for me, too, with Quantal. Files that could previously (in Precise) be opened by gEdit are now showing this error instead. bugs.launchpad.net/ubuntu/+source/gedit/+bug/1067915
    – Matt White
    Nov 12, 2012 at 15:52
  • As I occasionally reproduced it: the problem most probably is the state of variable XMODIFIERS="@im=none", it ought to be XMODIFIERS="@im=xim" if you use xim input method. Substitute it with ibus or whatever IM you use.
    – Hi-Angel
    Jul 18, 2016 at 5:25

2 Answers 2

2

I’ve been facing the same issue. For me the problem was that the encoding of the file had changed since it was last opened with Gedit (from WINDOWS-1252 to UTF-8). As I had manually set the encoding when first opening the file, Gedit had saved this information and tried to reuse it the next time I opened the file after the encoding change; this resulted in said error message.

To fix the problem, I had to remove the saved encoding information from the gvfs metadata like so:

gvfs-set-attribute --type unset MY_FILE.txt 'metadata::gedit-encoding'

You can always find out what Gedit has saved about a particular file:

gvfs-info MY_FILE.txt | grep 'metadata::gedit'

For example, before issuing the above command, the output for my file was this:

  metadata::gedit-encoding: WINDOWS-1252
  metadata::gedit-position: 0
  metadata::gedit-spell-language: de_DE

After I had removed the encoding attribute, the output was just this:

  metadata::gedit-position: 0
  metadata::gedit-spell-language: de_DE
4
  • Thanks Chiki! For gvfs-info MY_FILE.txt | grep 'metadata::gedit', my plain text file returns metadata::gedit-position: 8189, nothing about gedit-encoding. So gvfs-set-attribute --type unset MY_FILE.txt 'metadata::gedit-encoding' doesn't change any attribute. I still encountered the same error as before.
    – Tim
    Apr 12, 2013 at 20:34
  • @Tim Ok, then we are probably facing different issues. What might help you track down your issue is this: you could copy the content of your text file into a new file via a command line (to hopefully circumvent gvfs and friends), e.g., with cat MY_FILE.txt > MY_NEW_FILE.txt. Then try to open MY_NEW_FILE.txt in Gedit. If the error persists, then it’s probably really a content problem. Otherwise, there is some (other) metadata problem.
    – Chriki
    Apr 13, 2013 at 7:18
  • the problem persists after cat MY_FILE.txt > MY_NEW_FILE.txt. So it might be because of some strange characters in the text file. I created the content of the text file by copying from some webpage into it. During the creation, I was completely under gedit. I then saved the file and exited gedit. But since then, I haven't been able to open the file in gedit (although I could open it in Emacs). Do you happen to know what other solutions I can try, and/or how to find out those characters?
    – Tim
    Apr 13, 2013 at 12:15
  • @Tim Perhaps the file has an unusual encoding which differs from your default system encoding (probably UTF-8). You can try to auto-detect the encoding with chardet MY_FILE.txt (chardet is available in the package python-chardet). Then you could convert the file to UTF-8, e.g., via iconv -f MY_FILE_ENCODING -t utf-8 MY_FILE.txt > MY_NEW_FILE.txt. Hopefully MY_NEW_FILE.txt can then be opened by Gedit. An alternative to converting the encoding would be to go to Gedit’s file ”Open” dialog and to manually select the encoding at the bottom of the dialog before actually opening the file.
    – Chriki
    Apr 14, 2013 at 8:34
1

type this in terminal

gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .