Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > emacs meta key?!

emacs meta key?!
Thread Tools
kman42
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Aug 7, 2002, 11:02 PM
 
I'm trying to learn to use emacs, but I can't figure out what the meta key is. It doesn't appear to be the option (alt) key or the command key. Can someone help out an emacs newbie?

I'm trying to learn emacs for editing Perl scripts, so if someone can recommend something else, that would be cool too.,

thanks,
kman
     
fitter
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Aug 7, 2002, 11:21 PM
 
Use esc instead. (Don't hold it down, though: tap it, then hit the key associated with the command. Normally you'd hold the meta key while hitting the other key.)

But don't waste your time. Learn vi instead
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Aug 7, 2002, 11:28 PM
 
Originally posted by fitter:
Use esc instead. (Don't hold it down, though: tap it, then hit the key associated with the command. Normally you'd hold the meta key while hitting the other key.)

But don't waste your time. Learn vi instead
Why do you suggest vi? Is this one of those huge debates? emacs vs. vi? Do other people have opinions? What would be best for Perl/Python/general purpose UNIX use?

thanks
kman
     
jayg
Junior Member
Join Date: Feb 2000
Status: Offline
Reply With Quote
Aug 8, 2002, 12:05 AM
 
Go to Terminal->Preferences->Emulation and there's an option for using the option key as meta.
     
nickm
Mac Enthusiast
Join Date: Dec 2001
Status: Offline
Reply With Quote
Aug 8, 2002, 11:52 AM
 
Is this one of those huge debates? emacs vs. vi?
Good god yes! Don't get started on it. Emacs is probably easier for a new user to use, and comes with more powerful features out of the box. Either way, if you want to learn to use either one, nothing you know about any other program can help you --- they each operate in their own way that is different from everything else on the planet except their decendents. (I suppose vi is kind of like ed, but that about it).
     
mudmonkey
Dedicated MacNNer
Join Date: Jan 2000
Location: Other side of your screen
Status: Offline
Reply With Quote
Aug 8, 2002, 02:15 PM
 
Originally posted by nickm:


Good god yes! Don't get started on it. Emacs is probably easier for a new user to use, and comes with more powerful features out of the box. Either way, if you want to learn to use either one, nothing you know about any other program can help you --- they each operate in their own way that is different from everything else on the planet except their decendents. (I suppose vi is kind of like ed, but that about it).
Actually, you can switch emacs to vi-mode and then, you can use the arcane vi syntax. I know, I know, I've heard every vi argument since 1986, so, it doesn't matter. The fact is, I use vi for most "quick" editing. I used to use emacs for most of my "hardcore" editing. Now, I just use the Project Builder's editor with Cocoa TextExtras loaded and Cocoa keymappings defined for emacs bindings. I like BBEdit, but, being craphole Carbon, I can't configure it like all Cocoa apps...

Okay, I probably irritated at least 3 groups in there...
Meh
     
fitter
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Aug 8, 2002, 02:16 PM
 
Agreed: Emacs is probably easier for a new user. But its advantages, in your case, begin to end about there.

Emacs is enormous: ten times the size of vi. Over the years, Emacs has accrued dozens of extra features, a number of which are rarely used (did you know, for example, that there are several text-based games that run in Emacs?). It tries to do and to be too much: what started out as a text editor (Editor Macros) is now an IDE, a command prompt (of sorts), a vehicle for the GNU Manifesto, and more besides. You'll likely never want or need half the features it offers.

Vi, on the other, doesn't try to do much more than edit text. Neither emacs nor vi is especially intuitive (compare the commands to quit: Emacs: ctrl-X + ctrl-C ; Vi: ZZ or :q), but vi, once you've got the basics down, is extremely fast and makes searching and replacing a breeze. Additionally, some form of vi comes with just about every form of Unix-like OS out there. Emacs, due to its size, does not. (This is less often the case the larger harddrives get and the faster processors get; but there are still small distributions which do not include emacs.)

I'm not suggesting that you ignore emacs entirely--it is powerful, and if you're planning to work on sizable projects in C, the C mode is very useful--but it's overkill for what you want to do.

Hopefully this won't erupt into the typical holy war that characterizes the debate between two text editors. There's no denying I prefer vi, but I'm willing to admit emacs has its place.
     
jdm5
Fresh-Faced Recruit
Join Date: Aug 2002
Location: Earth
Status: Offline
Reply With Quote
Aug 8, 2002, 06:44 PM
 
I suggest O'Reilly's Learning Gnu Emacs as a starter for emacs -- it covers just about everything you could want to learn in a relatively easy format (it's about exciting as a book about an editor could be).

[I have no affiliation with O'Reilly or Amazon. And yes, this is my first post -- I'm considering a Powerbook purchase and love the fact that OS X is UNIX based!]

As discussed earlier, the syntax of both vi and emacs are not necessarily intuitive...
     
theory
Dedicated MacNNer
Join Date: May 2002
Status: Offline
Reply With Quote
Aug 8, 2002, 07:26 PM
 
If you want to use emacs without the terminal and don't want to use X windows go to
http://wsidecar.apple.com/cgi-bin/np...cs-21.1.tar.gz

It is quit nice and the meta key is command.
     
sadie
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status: Offline
Reply With Quote
Aug 9, 2002, 07:35 AM
 
OK, perhaps somebody could explain to me, because I really don't understand. Why the fsck would you rather use a text editor like emacs or vi in the terminal, rather than a real text editing application like BBEdit or Pepper?
All words are lies. Including these ones.
     
fitter
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Aug 9, 2002, 09:03 AM
 
Originally posted by sadie:
OK, perhaps somebody could explain to me, because I really don't understand. Why the fsck would you rather use a text editor like emacs or vi in the terminal, rather than a real text editing application like BBEdit or Pepper?
Speed: vi can open a text file over 120000 lines long (in my recent experience) in about five seconds. It takes BBEdit and Pepper at least that long just to launch (depending on your hardware). Pepper also has some problems rendering text when using ATSUI (if I recall correctly), making the GUI slower. Point and click interfaces, while more intuitive, are also more cumbersome to navigate. Once you have vi down, a GUI can't compete for speed of insertion, replacing and navigation.

Compatibility: Both Pepper and BBEdit can corrupt text files if the liue-ending preferences aren't exactly as they should be. (In my experience, it's easier to do this with BBEdit.) Additionally, vi will open any file. This includes files with metadata, files without metadata and binaries, which you can actually edit (if you know what you're doing) right from within vi.

Availability: vi is found on every release of a unix-like operating system. This means if I'm a sysadmin I can ssh to any of my servers and edit config files, or view logs, or write scripts, or write code, all with one text editor that I know will be on the system. I don't have to transfer files back and forth; I don't have to copy my (incompatible Mac PPC GUI) text editor to the (headless, Sparc-based) server.

Price: vi is free. A BBEdit single user license is $119; $79 Academic price. Pepper is $35, which is better, but could never compete with free.

I hope this fscking answers your fscking question.
     
schmoe
Forum Regular
Join Date: Oct 2001
Status: Offline
Reply With Quote
Aug 9, 2002, 01:12 PM
 
If you are familiar with building unix programs, you can get the latest version of GNU Emacs from CVS @ http://savannah.gnu.org and build it yourself. That will produce a very nice Aqua GUI-ified Emacs. I use that on a daily basis and am indebted to Andrew Choi for his hard work on the port.

Oh, and it supports a setting to use Cmd as meta.
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Aug 14, 2002, 12:26 PM
 
Originally posted by schmoe:
If you are familiar with building unix programs, you can get the latest version of GNU Emacs from CVS @ http://savannah.gnu.org and build it yourself. That will produce a very nice Aqua GUI-ified Emacs. I use that on a daily basis and am indebted to Andrew Choi for his hard work on the port.

Oh, and it supports a setting to use Cmd as meta.
Oooohhh...Auqafied...

Well, I started the vi tutorial as suggested and the emacs tutorial just to compare. They are both incredibly counter-intuitive! Why in the world would someone design an editor that has separate insertion/command modes? Is there a good reason to not allow the use of the delete key, arrow keys, cntl functions while in insertion mode? Maybe there is and I'm just not aware. Can someone explain?

Also, what about BBEdit?

kman
     
gorgonzola
Admin Emeritus
Join Date: Nov 2000
Location: New Yawk
Status: Offline
Reply With Quote
Aug 14, 2002, 01:49 PM
 
Originally posted by kman42:


Oooohhh...Auqafied...

Well, I started the vi tutorial as suggested and the emacs tutorial just to compare. They are both incredibly counter-intuitive! Why in the world would someone design an editor that has separate insertion/command modes? Is there a good reason to not allow the use of the delete key, arrow keys, cntl functions while in insertion mode? Maybe there is and I'm just not aware. Can someone explain?

Also, what about BBEdit?

kman
vi does it so that it can make commands shorter by not having a "command" key at all; it just uses things like "dd" to delete a line. Once you get a bit used to it, you'll find that this is a good system, because it's just incredibly fast.

As for the delete/arrow keys, I'm able to use them fine in vi when in insertion mode...I don't recall having to enable this separately.

BBEdit is great for Perl scripting. It's really very good, and being able to lookup perl documentation right inside the app is very convenient. But for editing system files, vi is better. And if you ssh to a remote server, BBEdit isn't even an option. When you're on your local machine, you might just want to use BBEdit, but console clients are useful for other situations as well.

By the way, if you're learning vi, you should really check out Vim. Vim is a vi clone, but it has an insane number of added features. The syntax hilighting, for one, is pretty amazing -- it has syntax coloring modules for specific configuration files (it has one for BIND conf files, for Sendmail, for httpd.conf, shell scripting, and almost any programming language you can think of). Also, the visual mode option allows you to "graphically" select a region of text and then perform an action on it (i.e. instead of having to count the number of lines you want to copy and then do #yy, you can just select it and do yy). This is especially useful when you take into account the fact that you can easily run external shell commands on selected text in vim. For example, I often select a rather long list of subdomains in a DNS config file and then use !sort (the ! means run the external command) and it'll alphabetically sort it. The search and replace features are quite powerful, and so on and so forth.

Vim also has some crazy features like "folding," which I haven't seen in any other editor (although I might just not have noticed it), which lets you collapse a block of code into one line for easier viewing and organization.

You can't depend on Vim being available on any Unix system, but the vi commands are all the same (Vim is just vi + extra stuff), so even if you can't use the fancy extra stuff, you can edit files and get your stuff done. With Emacs, you just spend so long with those ridiculously long key combos that it gets to be a real hassle. (Example: to save and quit in Emacs, you do C-x C-s C-x C-c. In vi(m) you do ZZ.)

You can also get a carbon version of gvim (a GUI version) that has a bunch of stuff in menu items (and one REALLY cool thing is that it can generate an HTML file from a code file with all the syntax coloring and stuff put in). That's available here. (It's gvim, period. It happens to be Carbon, but it's totally compliant and such. It's current, too.)

Anyway, this is definitely a holy war, and to be frank you should learn both Emacs and Vi(m), use them both, and then decide for yourself which one to use. To be honest, though, most more advanced users/admins of Unix that I know use vi(m) and not Emacs, but this has just been my experience.

My 2¢.

HTH
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
     
gorgonzola
Admin Emeritus
Join Date: Nov 2000
Location: New Yawk
Status: Offline
Reply With Quote
Aug 14, 2002, 01:51 PM
 
Oh yes, I should move this to the Unix forum. Moving...
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
     
fitter
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Aug 14, 2002, 03:38 PM
 
Originally posted by kman42:

Is there a good reason to not allow the use of the delete key, arrow keys, cntl functions while in insertion mode? Maybe there is and I'm just not aware. Can someone explain?

Also, what about BBEdit?
When vi was originally written, there weren't any arrow keys on the keyboards being used. Ctrl characters can be inserted as text. In some cases, you do actually want this, as in a .cshrc file containing this line:

stty erase ^?

In this case, the ^? is considered one character, not two, and the only way to enter it is using escape characters while in insert mode.
     
Mactoid
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Aug 14, 2002, 04:27 PM
 
Originally posted by gorgonzola:
Vim also has some crazy features like "folding," which I haven't seen in any other editor (although I might just not have noticed it), which lets you collapse a block of code into one line for easier viewing and organization.
I hear that the old NeXT text editor had that feature. Occasionally on the Project Builder mailing list you see requests for the Project Builder team to resurrect that feature.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
bradoesch
Professional Poster
Join Date: Jun 2000
Status: Offline
Reply With Quote
Aug 14, 2002, 06:44 PM
 
Have you ever used Pico? My limited knowledge tells me that Pico would work fine for editing Perl scripts.

Anyway, I find that Pico is much easier to use for simple tasks.

Brad
     
Mactoid
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Aug 14, 2002, 07:02 PM
 
Originally posted by bradoesch:
Have you ever used Pico? My limited knowledge tells me that Pico would work fine for editing Perl scripts.

Anyway, I find that Pico is much easier to use for simple tasks.
*blech* I personally can't stand pico. I can't see why it would be any easier than vi for simple jobs. I see pico as the Windows Notepad.exe of unix editors. If you liked notepad, than I suppose you might like pico, but I can't stand either.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
butter71
Forum Regular
Join Date: Mar 2001
Status: Offline
Reply With Quote
Aug 14, 2002, 07:58 PM
 
just wanted to second the opinion that andrew choi did a wonderful job on gnu emacs on os x. furthermore, projectbuilder seems to behave nicely with external editors (like emacs).
     
Paul McCann
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Aug 15, 2002, 05:45 AM
 
jEdit can do folding (and works pretty well on OSX). Slight java mushiness, but that's what you get for having a cross platform GUI: it really *is* GUI.

For perl scripts you're going to have to go a long way to better BBEdit, though the price is something of a stumbling block (and they're not averse to charging for upgrades). Of course no one should be paying more than $US79 for it, since that's the charge for the "cross grade" from the free BBEdit-Lite. Why they even bother with the "full price" is beyond me: it just makes people's jaws drop and starts them hunting elsewhere. $79 is still far from cheap, but I still think it's worth it if you spend a lot of time mangling text files. One downside of the current version is that they ***still*** haven't done anything about the default keyboard bindings not working in save dialogs. I guess they're waiting for 10.2, but that bug has been present for *way* too long in what's touted as the premier text editor.

Anyway, cool things about bbedit+perl: (1) perl palette, which includes syntax checking, one click access to perl documentation, and lots more (2) perl filters, which are *incredibly* useful, particularly in concert with the little bit of GUI goodness provided by the osxmacperl perl module.

http://www.versiontracker.com/morein...d=13658&db=mac

[[Hey, I'm the only one who's commented on it, so ignore the reviews!!]]

When BBEdit's not around I'm strictly a vi man; take the time to learn it, regardless of what you settle with. And make no mistake, it really *does* take some time to learn properly, and the time as a newbie vi user is not particularly pleasant, particularly when the arrow keys aren't set up correctly. That tends to be less of a problem nowadays, and everything seems to work fine in OSX's terminal. Today's cool vi-ism. You're using less to look at a file, and notice a stupid error that needs changing. Do you (a) quit less, then open up the file in the editor of your choice, and then make the change, or (b) hit the v key on your keyboard and find yourself editing the file in vi, and placed at the same line that you were reading in "less". I'll take (b) any day.

Cheers,
Paul
     
charleschuck
Junior Member
Join Date: Nov 2000
Location: Kalamazoo, Michigan, USA
Status: Offline
Reply With Quote
Aug 15, 2002, 05:58 AM
 
The real flame war isn't emacs vs. vi, it's ed vs. everyone else.

But first you have to find someone who uses ed. :-)

-Charles
     
Paul McCann
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Aug 15, 2002, 11:05 AM
 
"Hello, I'm Mister Ed"

A horse is a horse of course of course,
And no one can talk to a horse of course.
That is of course unless the horse
Is the famous Mister Ed!

Go right to the source and ask the horse.
He'll give you the answer that you'll endorse
He's always on a steady course.
Talk to Mister Ed!

People yakkity-yak a streak
And waste your time of day,
but Mister Ed will never speak
Unless he has something to say!

A horse is a horse of course of course,
And this one'll talk 'til his voice is hoarse.
You never heard of a talking horse?

Well, listen to this...

" I am Mister Ed!"

[[Mumble, mumble,... someone had to do it, mumble, mumble]]
     
diamondsw
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status: Offline
Reply With Quote
Aug 15, 2002, 11:55 AM
 
Originally posted by Mactoid:


*blech* I personally can't stand pico. I can't see why it would be any easier than vi for simple jobs. I see pico as the Windows Notepad.exe of unix editors. If you liked notepad, than I suppose you might like pico, but I can't stand either.
Meanwhile, I love pico, because I don't have to remember arcane syntax. Anyone can sit down in pico and do work - no manuals, no tutorials. The basic commands are presented right at the bottom of the window. Sure, if you're coding and such, you will need more features than pico offers. But if you're just adding a couple lines to a config file or whatnot, it's perfect for the job.

Sometimes all you need is a small tack-hammer...

Also, a great reason to use a command-line editor is if you are logged in remotely (but you really should have OSXvnc anyway), or stuck in single user mode trying to fix something.
     
diamondsw
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status: Offline
Reply With Quote
Aug 15, 2002, 11:58 AM
 
Originally posted by Paul McCann:
For perl scripts you're going to have to go a long way to better BBEdit, though the price is something of a stumbling block (and they're not averse to charging for upgrades). Of course no one should be paying more than $US79 for it, since that's the charge for the "cross grade" from the free BBEdit-Lite. Why they even bother with the "full price" is beyond me: it just makes people's jaws drop and starts them hunting elsewhere. $79 is still far from cheap, but I still think it's worth it if you spend a lot of time mangling text files. One downside of the current version is that they ***still*** haven't done anything about the default keyboard bindings not working in save dialogs. I guess they're waiting for 10.2, but that bug has been present for *way* too long in what's touted as the premier text editor.
Actually, the cross-grade only applies if you paid for the shareware BBEdit Lite, not the free one. I tried to use that loophole myself.

Also, the bugs in the open/save dialogs are OS bugs, and show up in a lot of programs, not just BBEdit. Most Carbon ports will display the same keyboard bugs.
     
fitter
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Aug 15, 2002, 01:20 PM
 
Originally posted by diamondsw:


Meanwhile, I love pico...if you're just adding a couple lines to a config file or whatnot, it's perfect for the job.
Actually, using pico to edit config files is dangerous, because it can corrupt them very easily. Pico (Pine Composer) hardwraps lines of text, inserting line breaks where there were none if a line extends beyond the width of the window. You can turn this off with the -w flag, but then the longer lines extend past the width of the window, and you have to scroll the line to see the end of it.

If you use pico to edit, say, /etc/ttys to add a loginhook or logouthook command, very likely the entire file will be corrupted, because line breaks will have been inserted at intervals throughout the text, making the file unintelligible to the system.

Moral of the story: pico is great for composing mail messages in pine. You can take notes with it, too. If you must use it, use the -w flag. Don't use it to edit important system files.
     
Gary Kerbaugh
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status: Offline
Reply With Quote
Aug 15, 2002, 10:26 PM
 
Hi all,

   For anyone that has made it to the end of this thread, you might need a bit of levity. This battle is being fought on many fronts; here's a war correspondence on one of them.

http://segfault.org/stories/3b3b46fb-005dd860.html
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
     
Paul McCann
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Aug 15, 2002, 11:50 PM
 
Originally posted by diamondsw:


Actually, the cross-grade only applies if you paid for the shareware BBEdit Lite, not the free one. I tried to use that loophole myself.

Also, the bugs in the open/save dialogs are OS bugs, and show up in a lot of programs, not just BBEdit. Most Carbon ports will display the same keyboard bugs.
As far as I can tell there's no such thing as BBEdit Lite "Shareware". It's freeware all the way isn't it? If not they'll have to come sniffing around my place for some more money, and I know I'm not the only one!!

[[re: save dialogs etc]] Yuck: thankfully I've only met the keyboard bugs in BBEdit: Barebones' FAQ touts the fact that they have a workaround in reserve, but are hoping for apple to fix the bug. I'll be happy with either solution.

Cheers,
Paul
     
gorgonzola
Admin Emeritus
Join Date: Nov 2000
Location: New Yawk
Status: Offline
Reply With Quote
Aug 16, 2002, 01:47 AM
 
Today's cool vi-ism. You're using less to look at a file, and notice a stupid error that needs changing. Do you (a) quit less, then open up the file in the editor of your choice, and then make the change, or (b) hit the v key on your keyboard and find yourself editing the file in vi, and placed at the same line that you were reading in "less". I'll take (b) any day.
That's freaking slick. Got any more?
"Do not be too positive about things. You may be in error." (C. F. Lawlor, The Mixicologist)
     
Paul McCann
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Aug 16, 2002, 01:09 PM
 
Originally posted by gorgonzola:


That's freaking slick. Got any more?
Nothing so cute (or memorable), unfortunately. I'm never sure exactly *where* everyone learns how to use vi with any degree of proficiency, so some --indeed, all-- of what's below might induce a sense of "yeah, yeah" in some of you, but for what it's worth...

Just to set the scene: I'll assume that we're always in command mode in what follows, and "regexp" means any regular expression that's valid in vi: you should probably add the line

set extended

to your .exrc so that vi uses extended regexps. That means you can, for example, use "s+" to mean "one or more s's" instead of having to type the horrible "ss*".

OK, so get on with it already...
--------

d/regexp

deletes everything up to the next occurrence of "pattern". This one is surprisingly cool if you've not encountered it before, and really easy to incorporate into your repertoire. For example, to delete the rest of the current paragraph just spot the first few letters at the start of the next paragraph: say it begins "Accordingly, ...". Then

d/Acc

does the business. Of course that's a pretty tragic regexp, but I'll let you take it forward from there!

----------

:g/^Item:$/+d

Suppose, for example, someone's sent you a file in which they've added a dashed line after every line that contains only the heading "Item:", and you'd love to kill them all off. The above does exactly that: I'll leave the explanation out as this is already getting longer than I intended.

-----------

A couple of quickies along the line of the previous command:

:g/regexp/nu

:g!/regexp/nu

Show and number all lines that match (resp. don't match) regexp. For example, to see all the comments in your file, together with their line numbers (assuming you comment by putting a # at the start of a line, possibly after spaces)


:g/^ *#/nu

To copy all of those comments into a new file you could use something like

:g/^ *#/ .w >> newfilename

------------

I guess everyone knows how to get shell output into a vi window:

:r! ls

for example (to get the ls output included in your current window). Some books will show this as :!! ls, but tcsh (at least) seems to grab the first ! and interpret it as the previous shell event. Blrrk. Anyway, some experimentation led to the example shown above. Obviously you can "cat" files and so forth.

-------------

What about more exotic inclusions or even better, some sort of filtering on the contents of the file that you're editing? Here's a quick way to implement a perl filter in vi: just as a dumb example, suppose you wanted to add one to every number that occurs in the file. (To check out the action of the following script you might want to read in the output from cal first, just to get some numbers hanging around:

:r! cal

and then

:% ! perl -pe 's/(\d+)/$1+1/ge'

I guess a temperature converter is another option here: let's say a set of recipes has temperatures in Celsius --written as 230C, for example, just to make things easy, and you wish to convert them all to Fahrenheit. (Recall that x degrees Celsius corresponds to (9/5*x + 32) = (1.8*x+32) degrees Fahrenheit.)

:% ! perl -pe 's/(\d+)C/int(1.8*$1+32)."F"/ge'

But that's starting to get a little silly! Must-go-to-bed.

Cheers,
Paul (BBEdit user whenever he has the choice!)
     
mudmonkey
Dedicated MacNNer
Join Date: Jan 2000
Location: Other side of your screen
Status: Offline
Reply With Quote
Aug 16, 2002, 01:49 PM
 
Originally posted by Paul McCann:
Today's cool vi-ism. You're using less to look at a file, and notice a stupid error that needs changing. Do you (a) quit less, then open up the file in the editor of your choice, and then make the change, or (b) hit the v key on your keyboard and find yourself editing the file in vi, and placed at the same line that you were reading in "less".
That isn't actually a "vi-ism," but, rather a "unix-ism."

You can set two environment variables: EDITOR and VISUAL to be whichever you prefer:

so, (in csh):

setenv VISUAL /usr/bin/pico
setenv EDITOR /usr/bin/pico

When you hit 'v' in less it will load pico. When you do a 'crontab -e', it will load pico.

If these variables are undefined, vi is the default...
Meh
     
Paul McCann
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Aug 16, 2002, 10:43 PM
 
Originally posted by mudmonkey:


That isn't actually a "vi-ism," but, rather a "unix-ism."

You can set two environment variables: EDITOR and VISUAL to be whichever you prefer:

If these variables are undefined, vi is the default...
True indeed (and in depth): I guess a little more context would make it clearer that I was thinking about modifying system files, which I wouldn't let pico near. Yeah, yeah, works for emacs/whatever as well, and even manages the "go to the appropriate line number" trick correctly, which is rather nice. So what can I use to reinstate this increasingly tenuous connection with "vi"? Maybe only the fact that vi makes a natural connection with the "v" command! Unless you're sufficiently immersed in unix culture that you see "v" and think "VISUAL environment variable" etc etc (cf man less).

Cheers,
Paul
     
DekuDekuplex
Dedicated MacNNer
Join Date: May 2003
Location: Tokyo, Japan
Status: Offline
Reply With Quote
Aug 28, 2004, 05:53 PM
 
Originally posted by theory:
If you want to use emacs without the terminal and don't want to use X windows go to
http://wsidecar.apple.com/cgi-bin/np...cs-21.1.tar.gz

It is quit nice and the meta key is command.
Does anybody know how to set the Escape key as the Meta key in Enhanced Carbon Emacs 21.3.50.4 (stand-alone Emacs; not within the Terminal window) on Mac OS X 10.2.6 Jaguar?

For some reason, when I press the Escape key in Emacs, nothing happens; I need to press Shift+Escape, instead. I can still use the Command key as the Escape key by holding it down as I press the combination key, but I'm used to pressing the Escape key first, followed by the combination key.

Does anybody know how to set this option?

-- DekuDekuplex
PowerBook® 17-inch [Rev. A] @ 1 GHz
512 MB RAM, 60 GB HD, AEBS, APP/PB
"Furuike ya, kawazu tobikomu mizu no oto."
-- Matsuo Basho
     
khufuu
Registered User
Join Date: Aug 2002
Location: On my couch
Status: Offline
Reply With Quote
Aug 28, 2004, 08:19 PM
 
Originally posted by charleschuck:
The real flame war isn't emacs vs. vi, it's ed vs. everyone else.

But first you have to find someone who uses ed. :-)

-Charles
Holy crap!! I haven't used ed in so long I had forgotten that it had existed. Wow!
     
Juggle5
Junior Member
Join Date: Nov 2001
Location: Seattle
Status: Offline
Reply With Quote
Aug 30, 2004, 03:56 AM
 
Originally posted by gorgonzola:
That's freaking slick. Got any more?
Well, these are vim (not vi) tricks, but I find them handy:

Select some poorly formatted code you want and press =. This will re-indent it for you! Very handy when you are editing bad code, or when pasting code and the indentation is messed up by the auto-indenter.

Should you use tabs or spaces when editing code? How many spaces should tabs be? Avoid this holy war using :retab.

If the line breaks on a text file are all screwed up, use gq to reformat the text. Good for really long lines or lines that were wrapped several times. (Usage: (1) select text, type gq, or (2) gqj or gq$ for one line.)

For information on these, type ":help =", ":help retab", or ":help gq".
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:10 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,