2 Nano Questions?
blinux.list at thechases.com
Sat Jan 12 15:40:14 UTC 2008
> a way to search-and-get rid of blank lines in Nano?
I played around a bit in Nano and couldn't get anything easy that
resembled this behavior (though I was able to do it, the process
was convoluted and inconvenient; it would have been easier if
Nano supported multi-line regular expressions for
search-and-replace). In vi/vim, it's pretty easy:
and likely as easy in the "edbrowse" program that's popular here.
However, if you step outside of Nano, you can use sed or grep to
do it for you:
grep . myfile.txt >outfile.txt
sed -i.bak '/^$/d' myfile.txt
The sed version will edit myfile.txt in-place and remove all
blank lines and save the resulting file (keeping the original as
"myfile.txt.bak"...if you don't want a backup file, you can just
use "sed -i '/^$/d' myfile.txt" without the backup extension).
You can also use the sed version like grep:
sed '/^$/d' myfile.txt >outfile.txt
to pipe the output to a new file (in this case, "output.txt")
There's a TODO for Nano that includes filtering a selected range
through an external program, but I don't think that's yet in the
production version of Nano. Once that feature hits, you should
be able to select a range of lines in your file and then run it
through one of the above commands without the file IO parts:
This new ability will even allow you to run your text through any
of the filters in the "bsdgames" package, such as making your
text sound like a pirate, the Sweedish Chef, or turn your text
into pig-latin. This just demonstrates the power of being able
to have your editor run your text (or a portion there-of) through
an external filter program.
While the choice of an editor is a personal thing, and I'll admit
up-front that I'm a vi/vim junkie, you might want to investigate
switching to a more powerful editor that *does* offer the ability
pipe sections of your code through an external program. Nano is
nice for the beginner but one quickly hits its limitations.
> 2nd, I have an editor defined in LYNX, but I understand there's a way to launch
> Nano at the current line instead of the beginning of the file. In the man
> page, it list a +LINE but I notice no improvement.
There's a confounding bit of action going on here.
1) yes, Nano does allow you to use the form "nano +32 file.txt"
to jump to line 32 in the file.
2) yes, Lynx does support going to a designated line in a file
based on the current line in the "text-edit" control.
Unfortunately, Lynx only recognizes certain editors as allowing
this offset-format and Nano isn't among those.
If you're willing and able to rebuild Lynx from source, it looks
like it's an easy fix: in src/LYEdit.c the very first function
is called "editor_can_position()" with a static table of editors
it knows how to do positioning for (they should all use the "+32"
notation for offsetting to line 32). You can just add a line in
here for Nano and rebuild. I'm surprised that Debian doesn't
already do this for me, as it's got entries for emacs, jed,
jmacs, joe, jove, jpico, jstar, pico, rjoe, and vi. It would
seem that Nano is at least as popular in Debian as Pico or some
of the more obscure editors in that list.
I was able to fool Lynx into thinking that Nano was one of these
editors by creating a link between Nano and one of the editors
that I don't have on my machine
ln -s `which nano` jpico
and then setting my Lynx editor to "jpico". You'll want to make
sure that whatever you link to is accepted by Lynx and doesn't
tromp over an existing editor on your system. You can find these
by looking through the strings in the Lynx binary:
strings -td `which lynx` | grep -5 jpico
where "jpico" is one of the items on the list above that isn't
emacs or vi (or otherwise you'll get a flood of results). My
local install of Lynx is missing jed, joe, and pico from the list
above (which came straight from the Lynx code-base).
Hope this gives you some leads to try...
More information about the Blinux-list