gedit modelines – What are they? How do they work?

There is a gedit plugin called Modelines and the plugin is described as

Emacs, Kate and Vim-style modelines support for gedit.

What are modelines? And how do they work in gedit?


Modelines allow you to set preferences on a file-by-file basis, and allow you to mimic some of the preference-setting options of a few other popular editors (Vim, Emacs, and Kate).

For example, if you have your gedit preferences set to use 4 spaces per indentation, you can use modelines to override this and set only 2 spaces per indentation on that particular file.

Actually creating modelines in your documents is another matter, though. It can be rather complex (look at the documentation for the Kate modelines), and is generally suited to people who are intimately familiar with their editors of choice. This is why the gedit documentation links out to the various manuals for Vim, Emacs, and Kate, rather than describing their modelines in detail within the documentation.

Here is a sample vim-style modeline in a python file. Let's call it test.py. The line at the end turns on the modelines, sets the tab spaces at 24 spaces (clearly a bad python coding practice, but done just for effect here), and turns off the expanded tabs feature.

print "hello"
print "say what?"

# ex:set ts=24 noet:

Give it a try in gedit and let me know if it works for you. The vim modeline options are documented fairly well here. If you would like to wade through the Emacs documentation to find their modeline options, you are welcome to do so. :)


Gedit modelines are described here.

In text file (in source code comments for example) you can add some configuration customization hints for the editor (like display tab as 4 spaces in this this file).