Author Topic: any linux text editors that do an auto-word wrap sorta thing?  (Read 6762 times)

0 Members and 1 Guest are viewing this topic.

Offline FunkTrooper

  • Thread Starter
  • Posts: 44
    • http://funktrooper.t35.com/
any linux text editors that do an auto-word wrap sorta thing?
« on: Sun, 21 December 2008, 20:01:36 »
Hi guys!  I've recently switched my laptop over to using Linux Mint.  It's lovely; I do like not having Windows, I have to say :)

There's one thing I miss, though. And no, this isn't anything complicated at all -- it's something incredibly simple: metapad.

metapad is a wonderful text editor for Windows that is unfortunately not open source.  It has one particularly useful feature that I would like to have in Linux, but I don't really know what to search for in order to find it.

In metapad, if you enable word wrap, you can type away all on the same line of text, and if you want it to be saved as it appears with word wrap turned on, you can use the 'commit word wrap' feature, which puts in newlines at the end of each 'line' on the screen. This is really handy -- you can, for example, resize the window so that 80 characters fit per line, then use the 'commit word wrap' feature, then the docuement will look right no matter what size the window is.

So, does anyone know of any Linux text editors that offer something similar?

Thanks guys!
P.S. I'm getting a Unicomp Customizer, for Christmas.  Detailed review and keyboard pr0nz will be posted!

Offline cchan

  • Posts: 223
  • Location: Michigan
any linux text editors that do an auto-word wrap sorta thing?
« Reply #1 on: Sun, 21 December 2008, 20:17:12 »
fmt(1) commits a word wrap, but that's a command line tool.
HP Envy17: Core i7-2760QM, 8GB DDR3, 128GB Crucial m4 + 750GB Hitachi, Windows 7 Home Premium x64, Cherry ML4100, Logitech M500, HP zr22w
IBM Thinkpad X60: Core Duo T2400, 2GB DDR2, 128GB Samsung 830, Xubuntu 12.04 x86, Cherry ML4100, Logitech M205, HP zr22w
Raspberry Pi Model B: BCM2835, 0.25GB DDR2, 8GB Samsung SD card, Raspbian Wheezy, human interaction devices as above

Offline secularzarathustra

  • Posts: 34
any linux text editors that do an auto-word wrap sorta thing?
« Reply #2 on: Sun, 21 December 2008, 21:32:38 »
emacs does, just set the default number of characters per line.
Dark and the Desert and Destriers me ken,
And the Glaive and the Joust, and Paper and Pen.

Offline andb

  • Posts: 69
any linux text editors that do an auto-word wrap sorta thing?
« Reply #3 on: Mon, 22 December 2008, 03:58:03 »
Quote from: secularzarathustra;15745
emacs does, just set the default number of characters per line.

Somehow, I doubt he wants to use emacs in his foray into linux. VIM!

Seriously, I dont recall Gedit offering this. I'd look into Eclipse, with its modular nature it offers about anything you can think of (Ive never used it though). Maybe not the easiest editor in the world to use, but at least its graphical, which will be easier for a new Windows convert.

Funktrooper, you ought so specify that you want a noobie friendly editor ;)
 
Personally, I'd probably use Gedit or whatever the KDE base editor is and the use 'fmt' on the command line to get what you want. Thats the thing about Linux, you can often get the result you want through a series of small apps instead of needing some monolithic monster which offers thousands of unused options (can you say 'MS Word'?). Go look into what pipes are and the whole building block concept should be more clear.

BTW, if you want to learn whats going on 'under the hood', I recommend http://learnlinux.tsf.org.za/, which was set up by Mark Shuttleworth of Ubuntu fame a few years back. As its about the base system, its all still valid. Look for the Linux Courses tab at the top.

Offline iMav

  • geekhack creator/founder
  • Location: Valley City, ND
  • "Τα εργαλεία σας είναι σημαντικά."
any linux text editors that do an auto-word wrap sorta thing?
« Reply #4 on: Mon, 22 December 2008, 04:39:11 »
If you really love metapad, why not use it??  Runs fine under WINE.

Alternatively, you should have nano and/or pico.  Both do this easily.  Resize your terminal window and then hit Ctrl-J.  Does exactly what you are looking for.

If you are looking for a more graphical editor, I believe Abiword has some decent word wrap features as well.

Offline D-EJ915

  • Posts: 489
  • Location: USA
any linux text editors that do an auto-word wrap sorta thing?
« Reply #5 on: Mon, 22 December 2008, 14:52:47 »
FTE has 3 word wrap settings; wily only word wraps.  Nedit has a few settings as well.

Offline cmr

  • Posts: 295
any linux text editors that do an auto-word wrap sorta thing?
« Reply #6 on: Mon, 22 December 2008, 17:13:29 »
vim does this... sort of.
:set wm=4 should produce the wrapping behavior you want.

unfortunately it's not smart enough to auto-reformat after you make an edit and screw up the wrapping; you need to issue the 'gq' command over a range of text to re-wrap it.

unfortunately, i don't know of any other editors that work as you describe (or if there's a way to make vim behave that way).

Offline FunkTrooper

  • Thread Starter
  • Posts: 44
    • http://funktrooper.t35.com/
any linux text editors that do an auto-word wrap sorta thing?
« Reply #7 on: Mon, 22 December 2008, 19:12:09 »
Wow, thanks for all the responses guys :)

Quote from: iMav;15766
If you really love metapad, why not use it??  Runs fine under WINE.


I did try Wine, but when it loads, it loads with a variable width font. Any attempts at changing this will result in the program suddenly exiting, with no explanation or error message. (tried on the latest development version of Wine and the stable version)  So basically I can't get it to use a fixed width font.

Anyway, I'll try out some of your other suggestions when I get a chance.  My next bit of free time won't be till Christmas Day though, I'm in work *constantly* till then. (I work at Marks and Spencer at the moment, and it's absolutely crazy there around Christmas).

I know I really am a noob with Linux at the moment, but that's something I'd really like to change.  I am something of a 'power user' with Windows, but I'd like to get to a stage where I don't need to depend on Windows just to be good at using my computer.  So I'm trying to get there... slowly... but I'll get there eventually :)

Offline lam47

  • Posts: 688
any linux text editors that do an auto-word wrap sorta thing?
« Reply #8 on: Mon, 22 December 2008, 19:23:09 »
Hey funktrooper.
I have just started to use Linux too.
I tried about 10 distros (live cds are great) but settled with Ubuntu.
Good luck with it and I know you will love the new keyboard.

BTW what did Unicomp ask for in shipping to Ireland?
Keyboards. Happy Hacking pro 2 x2. One white one black. IBM model M US layout. SGI silicone Graphics with rubber dampened ALPS. IBM model F. ALPS apple board, I forget what it is. And some more I forget what I have.

Typewriters. Olivetti Valentine. Imperial Good Companion Model T. Olympia SM3

Offline megarat

  • Posts: 202
  • Location: Squirt Island, WA, USA
  • (Not My Real Name)
    • http://www.megarat.com
any linux text editors that do an auto-word wrap sorta thing?
« Reply #9 on: Mon, 22 December 2008, 19:59:13 »
Quote from: D-EJ915;15826
FTE has 3 word wrap settings; wily only word wraps.  Nedit has a few settings as well.


I would recommend looking at Nedit as well.  I use that routinely, and it has four wrap settings (including "None").

Home/Work:  Custom Filco FKBN87Z/EB and SGI 041-0136-001 chimera (original white ALPS, not simplified, rubber-dampened)
Gaming:  Wolfking Warrior with custom-colored layout, HHKB Lite 2 (Rubber dome)

Offline FunkTrooper

  • Thread Starter
  • Posts: 44
    • http://funktrooper.t35.com/
any linux text editors that do an auto-word wrap sorta thing?
« Reply #10 on: Mon, 22 December 2008, 20:09:39 »
Quote from: lam47;15865

BTW what did Unicomp ask for in shipping to Ireland?


It was $40 using FedEx. There were no additional fees or import duty or customs payments or anything like that. It was just $69 for the keyboard and $40 shipping.

Offline lam47

  • Posts: 688
any linux text editors that do an auto-word wrap sorta thing?
« Reply #11 on: Tue, 23 December 2008, 05:38:57 »
Quote from: FunkTrooper;15872
It was $40 using FedEx. There were no additional fees or import duty or customs payments or anything like that. It was just $69 for the keyboard and $40 shipping.


Thanks man. Not too bad.
Keyboards. Happy Hacking pro 2 x2. One white one black. IBM model M US layout. SGI silicone Graphics with rubber dampened ALPS. IBM model F. ALPS apple board, I forget what it is. And some more I forget what I have.

Typewriters. Olivetti Valentine. Imperial Good Companion Model T. Olympia SM3

Offline lal

  • Posts: 360
any linux text editors that do an auto-word wrap sorta thing?
« Reply #12 on: Tue, 23 December 2008, 06:03:15 »
May I suggest to just not write lines longer than at most 80 characters? Practically every half sane Unix text editor can wrap lines after a configurable amount of characters. Set it to something like 76 and just type away. More decent editors can even rearrange text so that all lines are as long as possible (handy if you delete something and want to make the lines equally long).
BS: Customizer, Model Ms; Alps: CSK-2101, FK-2002, AT-101 (SGI & Dell), MCK-860, FKBN87Z/EB; Cherry: Poker X, FKBN87MC/EB, WY60, G80-3000, G84-4100, TDV 5010

Offline karlito

  • Posts: 157
    • http://altitudegame.com
any linux text editors that do an auto-word wrap sorta thing?
« Reply #13 on: Wed, 24 December 2008, 01:11:15 »
jEdit (http://www.jedit.org) does what you're asking. It's no longer maintained but still a pretty decent text editor.  Use 4.3 pre 16 (what ever latest dev version is) if you try it.

I dont think Eclipse really does what you're asking out of the box. But im not 100% since I only use eclipse for coding which has formatters...

Offline Therac-25

  • Posts: 84
any linux text editors that do an auto-word wrap sorta thing?
« Reply #14 on: Sat, 27 December 2008, 22:51:29 »
As mentioned above, nedit can do this (Fill, Ctrl+J), but nedit uses Motif and Motif looks like crap on a modern Linux desktop -- no aa or font smoothing or anything.  Emacs can also do it, but then again Emacs can do anything.  jEdit can do it, but I was never a fan of jEdit (or any Java software for that matter).

If you're learning vi(m), then there's certainly a way to write a macro in there that will do this.  The manual way is :%!fmt -w 62, but I'm fairly certain you can ask vim how wide it's terminal is in a macro.

I cracked open gedit (the default Gnome editor -- if you have a vanilla Ubuntu install, it'll be called "Text Editor", not gedit or anything).  Here's how you can set up something that should be close enough, assuming you don't mind playing with the parameters somewhat.

gedit contains a plugin called "External Tools" -- you have to enable this plugin in the preferences pane first.  After you enable External Tools, then either go to Configure, or do Tools->External Tools...

Anyway, create a new external tool called whatever, and then paste this into the external Command(s): window.  You'll have to mess with the M and B things to get it right, and if you have the side pane open, it'll throw off the calculations.  But it does work, and does roughly what you want.  Oh yeah, for the new tool, set Input to "Current Document", and output to "Replace Current Document".

Code: [Select]
#!/bin/sh

M=9
B=13
CURRENT_WINDOW_ID=`xprop -root|awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'`
CURRENT_WINDOW_X=`xwininfo -id $CURRENT_WINDOW_ID | awk '/Width: / {print $2}'`
# bash can't do floating point math.  it is teh suck.
CHARACTERS=`echo "scale=4; ($CURRENT_WINDOW_X-$B)/$M" | bc | awk -F"." '{print $1}'`

echo Running fmt -u -w $CHARACTERS > /dev/stderr
fmt -u -w $CHARACTERS

Note that this just runs it through fmt -- don't use this for code or anything.  Also, if you change your font size constantly, that's going to mess it up too.  I'm assuming you're using a fixed-width font here.  The settings there are ones I figured out for my own setup.  You'll have to fine tune them for your font and resolution and so forth.

If fmt doesn't behave well enough for you, you can replace the call to fmt with a convoluted perl one-liner that loads Text::Wrap and get finer control over how things are wrapped.

It would probably be very possible to formalize this into a Fill plugin for gedit, as the main weakness of this one is the inability to get the width of the editing buffer from the External Tools plugin (it does pass some variables in the environment to the script, but they mostly deal with the document's name).  The only choice we have is to ask the X server what the active window is, and estimate the character width of the buffer from the window's physical size.

Quote
I know I really am a noob with Linux at the moment, but that's something I'd really like to change. I am something of a 'power user' with Windows, but I'd like to get to a stage where I don't need to depend on Windows just to be good at using my computer. So I'm trying to get there... slowly... but I'll get there eventually

Welcome to Unix.  I've been doing this for 15 years or so (I migrated from Windows 3.1), and I'm still learning new stuff.  If you have the mindset of a programmer, and don't mind taking the opportunity to do things yourself, you'll get on fine.  Many, many Unix programs aren't powerful because of how many features they have built in, but because they hook into the environment and allow you to do stuff like the above fairly easily.  Despite the teeth gnashing and hand waving about making Linux "easy", Unix is still fundamentally an environment built by programmers for programmers.

Learning how to program bash scripts, and to a greater extent, learning some perl, will help you in doing things that would be inconceivable on Windows with the same level of effort.  

This post is getting a bit long, but as an example to illustrate the point, I wrote a twitter client last week to fetch the top 5 things and put them into files that conky can read so it shows up on my desktop:

Code: [Select]
#!/usr/bin/perl

use strict;
use Net::Twitter;
use Text::Wrap;
use HTML::Entities;
use File::Slurp;

$Text::Wrap::columns = 33;
my $filebase = "/home/iwarford/.conktwit/ct.";
my $account = Net::Twitter->new(username=>"iwarford", password=>"doilooklikeanidiot?" );
my $twits = $account->friends_timeline( { count => 5 } );

for (my $y = 0 ; $y < scalar @{$twits} ; $y++) {
       write_file($filebase."$y.n.txt", $twits->[$y]->{user}->{screen_name} . "\n");

       my @lines = split("\n", fill("","",decode_entities($twits->[$y]->{text})));
       push @lines, ("") x (5 - scalar @lines);

       for (my $f = 0 ; $f < scalar @lines ; $f++) {
               write_file($filebase."$y.$f.txt", $lines[$f] . "\n");
       }
}

(The reason it splits every line into it's own file has to do with how Conky reads stuff.  That's the best way to do it that I'm aware of.)  Anyway, after a conkyrc to read the above, it comes out looking like this on my desktop.  

That took like an hour or two to do -- to do that on Windows, you would basically have to hope that someone else had already written a plugin for a widget thing that you could use.  It wouldn't be nearly as easy to get what you wanted.  It would certainly be possible, but unless someone had already done it, it would be alot more work.
das keyboard model s professional
HyperX Alloy FPS Pro Tenkeyless Blue
Model M Mini