Slashdot Log In
(Stupid) Useful Emacs Tricks?
Posted by
timothy
on Friday November 07, @08:58AM
from the bonus-if-it-uses-10-fingers-at-once dept.
from the bonus-if-it-uses-10-fingers-at-once dept.
Count Fenring writes "Since the Vi version of this question was both interesting and popular, let's hear from the other end of the spectrum. What are your favorite tricks, macros, extensions, and techniques for any of the various Emacs? Myself, I like 'M-x dunnet' ;-)"
Related Stories
[+]
Ask Slashdot: (Useful) Stupid Unix Tricks? 2356 comments
So the other day I messaged another admin from the console using the regular old 'write' command (as I've been doing for over 10 years). To my surprise he didn't know how to respond back to me (he had to call me on the phone) and had never even known you could do that. That got me thinking that there's probably lots of things like that, and likely things I've never heard of. What sorts of things do you take for granted as a natural part of Unix that other people are surprised at?
[+]
Ask Slashdot: (Useful) Stupid Vim Tricks? 702 comments
haroldag writes "I thoroughly enjoyed the recent post about Unix tricks, so I ask Slashdot vim users, what's out there? :Sex, :b#, marks, ctags. Any tricks worth sharing?"
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.

XKCD (Score:5, Funny)
C-X M-C M-butterfly
Reply to This
grep and emacs integration (Score:5, Interesting)
(defun my-grep ()
"grep the whole directory for something defaults to term at cursor position"
(interactive)
(setq default (thing-at-point 'symbol))
(setq needle (or (read-string (concat "grep for <" default "> ")) default))
(setq needle (if (equal needle "") default needle))
(grep (concat "egrep -s -i -n " needle " *
(global-set-key "\C-x." 'my-grep)
(global-set-key [f8] 'next-error)
Reply to This
Re:grep and emacs integration (Score:5, Informative)
Like M-x rgrep? It's builtin now.
Reply to This
Parent
Re:grep and emacs integration (Score:5, Informative)
Isn't that usually spelled
M-| wc
Meta-pipe is a great one -- it's "pipe region to external command" (M-x shell-command-on-region)
Reply to This
Parent
Some favorites (Score:5, Interesting)
(global-set-key (kbd "C-c c") 'comment-dwim)
C-c c to either comment out a region or uncomment it depending on context. Lovely feature.
(global-set-key "\M-g" 'goto-line)
M-g to go to specified line in buffer. Useful for emacs 21.x users where the keybinding is not yet standard.
(menu-bar-mode nil) (scroll-bar-mode nil) (tool-bar-mode nil)
Gets rid of the ugly TK widgets.
(iswitchb-mode t)
Superboosts C-x b.
(global-set-key "\C-z" 'undo)
The normal binding for C-z is suspend-emacs but having it bound as undo is much more useful imo.
Reply to This
editing over ssh (Score:5, Informative)
in one's .emacs file. Then open remote files with:
Reply to This
Outlines w/ org-mode (Score:5, Interesting)
I've recently discovered and almost instantly become a fan of org-mode, which is a great outlining tool (including folding, numbering, and other similar things you'd probably expect).
It's also good for lists of things to do, schedules, deadlines, and related stuff. It uses its own really simple markup langauge (similar to trac wiki), but you can include LaTeX and HTML inline.
It comes with exporters to HTML and LaTeX (and iCal for date stuff). You can also put tables inline, and the table editor is excellent for simple tables.
I use it every day for my list of things to do, and use it regularly for outlining text documents, pseudocode, and meeting notes.
Reply to This
AUCTeX with preview-latex (Score:5, Informative)
Reply to This
Edit files from anywhere w/ tramp (Score:5, Informative)
One of my favorite emacsisms a long time ago was ange-ftp, and the modern descendant, tramp, is one of my current faves. It lets you edit remote files over lots of protocols, including: ssh, scp, ftp, rsync, ftp, and smb.
Most emacs stuff works transparently, like dired and archive browsing. When you edit a file and save it, it's automatically put back on the remote machine. I have had trouble with psvn, but that's about the only thing that I kinda expected to work that didn't.
If you edit remote files and you use emacs, you want to start using this.
Reply to This
there's a whole wiki to answer this question (Score:5, Informative)
Reply to This
some of mine (Score:5, Informative)
1)First, ESS, Emacs speaks statistics, found at http://ess.r-project.org/ [r-project.org] . This lets you interface interactively with R, SAS, Stata, etc., all from the common Emacs interface. As a statistician, it's the one piece of software I could not do very well without!
2) The 'ido' package, with flex matching, in my .emacs,
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
This lets you open files and switch buffers with fuzzy matching, really nice when you have lots of things open.
See: http://www.emacsblog.org/2008/05/19/giving-ido-mode-a-second-chance/ [emacsblog.org]
3) Make the mouse jump away when you type over it.
(mouse-avoidance-mode 'cat-and-mouse)
4) Open two windows side-by-side (C-x 3) one with LaTeX code, one with a pdf, then use this in your .emacs, (add-hook 'doc-view-mode-hook 'auto-revert-mode), when you compile the .tex file into PDF, the PDF automatically updates in Emacs, I used that a lot while working on my CV.
5) The thunderbird extension that lets me compose replies in Emacs using emacsclient.
6) org-mode http://www.org-mode.org/ [org-mode.org]
7) preview-latex, now part of AUCTeX, this lets you see preview versions of formulae and graphics inline in your .text file, *while you edit*. Your formula is replaced by what it will look like when compiled.
8) EmacsWiki: http://www.emacswiki.org/ [emacswiki.org]
Reply to This
Meta-/ (Score:5, Informative)
auto completes based on words that have been seen in the buffer.
Reply to This
Check hard drive (Score:5, Funny)
It's often the case when you need to check the sectors on your disk for corruption, or just during hard drive testing. One of the coolest things that Emacs allows you to do is check your filesystem. For example on CentOS:
yum -y install emacs*
This will proceed to fill up your hard drive with tons of software until the filesystem is full.
(I kid, I kid)
Reply to This
Emacs Lisp (Score:5, Funny)
Lisp is a language that CompScis see for two months at University before leaving it behind. But if you really want to learn tricks with Emacs, you should learn Emacs Lisp - I have all sorts of specials, such as "move text to marker" and modes for handling internal IBM dump formats, that would be impossible in vi.
But if you want one quick piece of advice, here's one that should make someone smile
M-x hippie-expand RET
The ultimate, expand-this-thing-dammit-from-whatever-you-like completion trick.
Cheers,
Toby Haynes
Reply to This
Beginning of line (Score:5, Informative)
My two .emacs modifications I find essential follow.
First, turning off of obnoxious misfeatures:
And second, stealing the beginning-of-line behavior from Dev Studio: if you invoke the command at the beginning of the line, advance to the first non-whitespace-character instead.
Reply to This
trying to figure something out (Score:5, Funny)
I like emacs but I'm not ready to change over to it 100% yet.
Is there a way to dual boot between Vista and emacs?
Reply to This
The old Emacs vs Vi story (Score:5, Funny)
I asked my email-pal: "UNIX or Windoze?". He replied "UNIX". I said "Ah...me too!".
I asked my email-pal: "Linux or AIX?". He said "Linux, of course". I said "Me too".
I asked him: "Emacs or vi". He replied "Emacs". I said "Me too. Small world."
I asked him: "GNU Emacs or XEmacs?", and he said "GNU Emacs". I said "oh, me too."
I asked him "GNU Emacs 19 or GNU Emacs 20"? and he said "GNU Emacs 19". I said "oh, me too."
I asked him, "GNU Emacs 19.29 or GNU Emacs 19.34", and he replied "GNU Emacs 19.29". I said "DIE YOU OBSOLETE NOGOOD SOCIALLY MALADJUSTED CELIBATE COMMIE FASCIST DORK!", and never emailed him again.
From an old slashdot [slashdot.org] story
Reply to This
Rectangle Cut and Paste (Score:5, Informative)
Working with rectangular regions is a breeze in emacs (very useful for quickly swapping columns in csv-type files):
Set the mark at the upper left of the rectangle... move the cursor the lower right...
Kill rectangle: c-x r k
Move somewhere else...
Yank rectangle: c-x r y
There are some other rectangle commands, but these are probably the two most useful "unknown" emacs commands I've come across.
-Chris
Reply to This
Re:A favourite (works well on both Ubuntu and Debi (Score:5, Funny)
I've found this very useful whenever I'm put in front of emacs
C-x C-c
sudo apt-get -y purge emacs
vi
Reply to This
Parent
Re:A favourite (works well on both Ubuntu and Debi (Score:5, Funny)
Hmm.. that didn't work well for me. I tried it, but I ended up in an editor with functionality that was one step above punch cards.
Reply to This
Parent
Re:A big disappointment (Score:5, Funny)
it was posted from emacs, took a while to press all the keys.
Reply to This
Parent
Re:Please Stop (Score:5, Funny)
Hopefully this is the last story before we start with "Stupid pet tricks"
Seeing as this is about emacs tricks, everything else is a subset. Including pet tricks.
Don't get me wrong: Emacs is a great operating system -- it lacks a good editor, though.
Reply to This
Parent
Re:Please Don't Stop (Score:5, Insightful)
This is the first content I've seen in years that appeals to Slashdot's original demographics: hardcore geeks who are passionate about the tools they use. I've picked up a few tips in this series of articles and have enjoyed hearing other people learn about "old" stuff for the first time.
If "(Stupid) Useful $GEEK Tricks" isn't your cup of tea, then please feel free to look elsewhere [digg.com].
Reply to This
Parent
Re:Please Stop (Score:5, Funny)
A whole series...
Useful(Stupid) things to say to get modded Insightful
Useful(Stupid) things to say to get modded Interesting
Useful(Stupid) things to say to get modded Funny
Useful(Stupid) things to say to get modded Troll
Useful(Stupid) things to say to get modded Redundant
Useful(Stupid) things to say to get modded Flamebate
Useful(Stupid) things to say to get modded Overrated
Useful(Stupid) things to say to get modded Stupid
Useful(Stupid) things to say to get modded Useful
Reply to This
Parent
Re:What is next ? (Score:5, Funny)
(Stupid) Useful Chat-up Lines
hey, sexy mama. wanna kill all the humans?
Reply to This
Parent