Adding Hard Word Wrap/Line Break Feature to Gedit [Tutorial]

A screenshot of the final settings for gedit word wrap (or line break)

A hard word wrap or line break feature isn’t included in gedit by default, but it’s easily added by using the ‘External Tools’ plugin and a two-liner shell script. This will allow you to format your documents with a line break at column 80, or whatever you’d like it to be, by selecting the text, paragraph, or entire document and applying the shell script. Here’s how…

1. Open gedit
2. Navigate to Edit -> Preferences -> Plugins
3. Enable “External Tools” and press “Configure Plugin”
4. Press “New” and enter “Line Break at Col 80” (or any name you like)
5. Paste the following script in the “command(s)” text area (you can choose to leave out the #comments, these are only here as a reminder in case you want to modify it to fit your needs):



# fmt [-WIDTH][OPTION]... [FILE]...
# --uniform-spacing -- one space between words, two after sentences
# --split-only -- split long lines, but do not refill
# --width=WIDTH -- maximum line width (default of 75 columns)
# when FILE is -, read standard input

fmt --uniform-spacing --split-only --width $BREAK -

6. Choose “Current selection” as Input
7. Choose “Replace current selection” as Output
8. At this point, you can choose to create a shortcut key such as “ctrl+m” for easy access.
8. Close “External Tools Manager” by pressing the “Close” button
9. Now this script is executable under the “Tools” menu. Alternatively, you can use your shortcut key for quick access.

The next step would be to somehow get gedit to automatically perform these hard wraps as your typing (like the evolution email client does). If anybody has a suggestion, I’d love to hear about it in the comments below. I’m very surprised that this isn’t included in the already many featured gedit program by default, but thankfully it’s very easily remedied with the method described above.

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 10 Comments So Far

  • [email protected]
    October 20th, 2010 at 1:06 pm

    Figured the TextWrap Gedit Plugin by hartmann-it-design.de deserves some attention since he mentioned my solution:

    Give it a whirl!

  • Yufeng
    February 7th, 2011 at 9:44 am

    Awesome! Thanks for sharing this!

  • Kenia
    March 6th, 2013 at 10:10 am

    I can’t believe I spent so many years NOT knowing that. 🙂
    Thank you.

  • Min
    March 23rd, 2013 at 8:00 am

    Thank you so much for such a perfect solution.
    It is exactly what I am looking for, concise but effective.

  • Fisher
    April 24th, 2013 at 3:03 pm

    Thank you for this! Saved my telecommunications assigment, where we had to limit all lines to 80. Removed the –split-only to make it suit my needs but otherwise perfect!

  • Larry Tate
    June 20th, 2013 at 7:15 pm

    Hm, I followed this explicitly, but when I select the text ad apply the tool, the text remains w/o any wrap.

    I’m using 3.6.2

  • Larry Tate
    June 20th, 2013 at 7:17 pm

    Wait. My fault. Got it!

  • Andrew P.
    September 21st, 2013 at 9:22 am

    The script doesn’t seem to do anything at all in Gedit 2.30, the version that came with Ubuntu 10.04. I can only set the wrap margin using the Edit -> Preferences menu, and text still doesn’t wrap to the margin setting unless I use the Rewrap plugin by Derek Veit.

    On which version of Gedit was the script developed and tested?

    By the way, the screenshot image for this tutorial is missing.

  • yann
    October 26th, 2016 at 2:47 am

    thanks for this nice and useful script. It works fine except for one thing : the shortcut key is inefficient. Other shortcuts are OK, but the one for this tool just does nothing.
    Running gedit 3.14.0.
    If any solution exists, I’ll be glad to know about.

Who Linked To This Post?

  1. gedit add word wrap « brontosaurusrex.69.mu

Share your thoughts, leave a comment!