I frequently work with text files that do not have an extension or which have a non-standard extension using Gedit (a .sample file for example, for which the mime type is not understood), and Gedit always defaults to Matlab syntax highlighting.

gedit highlight settings

I'd like to set a default syntax highlighting of 'Plain Text' for these files. Is this possible?

Nano can do this, and a similar question for files with extensions is here. I'm looking for an answer that allows me to set a catch-all style of plain text for all types without an extension or not already found in /usr/share/gtksourceview-3.0/language-specs/as described here

Requested info:

  • No local language spec file in ~/.local/share/gtksourceview-3.0/language-specs/
  • Output of file --mime-type -b <myfile> is correct text/plain
  • Yes, the #! construct in the first line, for example #!/bin/bash will make gedit recognize the file as a bash shellscript, and other script files are recognized too, for example python scripts. I have never tweaked this feature, but I am using it with gedit, and in a similar way with geany. I think someone will come with a solution to you :-)
    – sudodus
    Dec 28 '16 at 18:24
  • The behavior you're currently getting from Gedit seems like a bug, if I understand you correctly. At least with gedit 3.18.3-0ubuntu4 on Xenial (and every other version of Gedit or Pluma I can recall having used on any platform), files without an extension or whose extension is unrecognized are treated as plain text and not highlighted. I don't think I have previous experience opening .sample files, but when I make such a file on my Xenial machine and open it in Gedit, it's identified as plain text. Do all your files with unrecognized (or no) extensions get highlighted as Matlab source code? Dec 29 '16 at 22:44
  • Not currently on an Ubuntu machine, but have you tried changing the globbing parameter in /usr/share/gtksourceview-3.0/language-specs/mathlab.lang (or whatever the MathLab language file is exactly) to: <property name="globs">*</property>??? ;-) If that does the trick, I'll post a full answer...
    – Fabby
    Dec 30 '16 at 7:08
  • Interest, too, in this issue
    – mattia.b89
    Dec 30 '16 at 12:02
  • 1
    @EliahKagan I have automatic saving enabled in Gedit, which appears to trigger the Matlab syntax highlighting for plain text files with no extension. Open one up, save manually (or wait for the auto save to trigger) and then see the problem happen. If you manually switch it back to Plain Text it's okay after that, but if you never choose or intervene it uses Matlab. Dec 30 '16 at 13:29

Steps taken

In my gedit, from the top bar menu, I select View, Highlight mode... and "Plain Text" is the default as shown below:

gedit highlight mode

Using the file name "test.sample" and pasting in a few lines of Matlab code it still stays as "Plain Text" format unless I force it to "Matlab" format.

After saving and exiting I performed cp test.sample test.newbee followed by gedit test.newbee the default format is still "Plain Text".

Next I created a new file using gedit called noextention. I typed a sentence, saved the new file and exited. Then I reopened the file using gedit and this is the result:

enter image description here

Notice the bottom bar of gedit's window shows Plain Text option for highlighting.


This was done under Ubuntu 16.04, Kernel 4.4.0-53.

I can confirm that <property name="globs">*.m</property> exists within /usr/share/gtksourceview-3.0/language-specs/matlab.lang.

Because I can't break my system like yours, unless we find something on your system to fix, I suggest reinstalling gedit after removing and purging all it's files with apt-get.

Particulars about my version:

$ sudo apt install gedit
Reading package lists... Done
Building dependency tree       
Reading state information... Done
gedit is already the newest version (3.18.3-0ubuntu4).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
  • 2
    Thanks, this was helpful. I have discovered that the issue varies with the contents of the file. For a file with the contents "This is a plain text file" it does remain plain text. For a file beginning with '#' and in Markdown (I use it a lot as it's easy to read), I still see the highlighting switch to Matlab. Maybe I have to ask a new question "How to make Gedit recognize Markdown syntax". Jan 1 '17 at 11:27
  • 2
    You're most welcome. I did a quick google search and here is a start for gedit markdown format: github.com/jpfleury/gedit-markdown Jan 1 '17 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.