(Stupid) Useful Emacs Tricks? 412
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' ;-)"
editing over ssh (Score:5, Informative)
in one's .emacs file. Then open remote files with:
Re:What is next ? (Score:2, Informative)
AUCTeX with preview-latex (Score:5, Informative)
macros are cool (Score:3, Informative)
C-x ( -- start a macro definition
-- type some commands
C-x ) -- end the macro
C-x e -- execute the last macro
For certain repetitive tasks which didn't warrent a new script I though this macro capability was awesome.
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.
Modifying variables (Score:3, Informative)
If you've got a file that you always want to set some specific variable to a non-default value for when editing, use something like this (taken from the end of a C file...)
* Local Variables:
* fill-column: 78
* c-basic-offset: 4
* End:
*/
Re:grep and emacs integration (Score:5, Informative)
Like M-x rgrep? It's builtin now.
Open jars, wars, ears with archive-mode (Score:2, Informative)
Configure emacs auto-mode-alist to open Java archives with archive-mode, and then edit deployment descriptors contained in the archive without having to extract the archive. Bliss.
Re:Some favorites (Score:3, Informative)
(global-set-key (kbd "C-c c") 'comment-dwim)
Note: this is already bound to M-; by default.
Mistake made (Score:3, Informative)
I think this article has been incorrectly filed; please fix, editors. It's been put under "News".
there's a whole wiki to answer this question (Score:5, Informative)
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]
Meta-/ (Score:5, Informative)
auto completes based on words that have been seen in the buffer.
Obligatory link (Score:3, Informative)
EMACS and butterflies [xkcd.com]
Re:Not much of a trick... BUT... (Score:1, Informative)
you can actually do something similar with Konqueror:
Window -> Split View Left/Right or Split View Top/Bottom.
it also comes with keyboard shortcuts.
zippy the pinhead! (Score:3, Informative)
M-x yow
and of course, the ever relevant:
M-x psychoanalyze-pinhead
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.
Re:Editing recorded keystrokes (Score:3, Informative)
This is covered in Chapter 10 of that invaluable reference "Learning GNU Emacs" (now in its 3rd edition, I need to 'upgrade' my 1st edition so the chapter organization might have changed) (http://oreilly.com/catalog/9780596006488/index.html)
You can do M-x apropos macro to get info. There's an edit-kbd-macro command as well as a whole bunch of other useful things.
dave
Two tips for trailing whitespace (Score:2, Informative)
There are a lot of things that you can do with Emacs, but I find the two simplest to share would be related to trailing whitespace:
(when (>= emacs-major-version 21)
(setq-default show-trailing-whitespace t))
(add-hook 'write-file-hooks
'delete-trailing-whitespace)
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
Re:Favorite Acronym (Score:3, Informative)
The funny thing is, those jokes about Emacs being slow date back to the 80s. These days, I find that Emacs is about the fastest app to start on a modern Linux distribution.
The rest of userland has gotten fatter and fatter, but Emacs has stayed about the same.
Since the story asks for favorite things about Emacs, I will just add: Gnus. The best email app bar none.
Back in the early nineties, I had an Acorn R140 with 4Mb of core; it ran RISC iX, which was basically BSD 4.2. It could just about run X11; and it could happily run a full Emacs development session (but not under X11). Pretty soon after that I got an R280, which had 8Mb of core; and that ran Emacs under X11 really nicely...
It's a long time since Emacs has really been slow, but the jokes have long memories.
Browsing Code: ecb-mode and etags (Score:3, Informative)
Whenever you download a bunch of code and want to dip your feet in it, it helps getting a good overview.
To that end, ecb-mode can be greatly helpful. It displays navigable directory trees, a list of all symbols defined in your current file, a list of recently visited files, and a compile window. Double-click anything to jump to it, quite nice to use. The symbol list is really neat; I've thrown C, python and makefiles at it, much to my satisfaction. Haskell support is a bit rudimentary, but still very useful. It says it handles perl and TeX specially [they can't be parsed without being partially executed]. I don't know how well.
If you just want to follow symbols around, use etags [use it anyways]. Run etags in your source root (zsh% etags **/*.[ch]), cursor-over a symbol, press M-. to jump to it.
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)
Re:Questions for Emacs People (Score:3, Informative)
The problem was, there was some key combination I was hitting on accident (probably since I am used to nano keybindings) that was causing me to delete large chunks of my document (usually everything above my current view). I didn't realize it, then I would save and have to restore the file from backup. This happened several times. I think it was happening as I was saving, but could never trace back my error.
My guess would be that you were pressing ctrl-w, "kill-region", which removes everything between your cursor and the 'mark', and places it in the kill buffer. As with ctrl-k, pressing ctrl-y will 'yank' it out and insert it (insert juvenile jokes here :-)).
Re:calc and pictures (Score:3, Informative)
(does vi do calculus? I think not).
No, but it does edit files pretty well.
Re:Lots of them (Score:1, Informative)
M-x where-is, also known as C-h w :)
Re:vi is for building emacs (Score:3, Informative)
Solaris, it's been said, has a great kernel and an utterly shit userland (i.e. the tools you actually interact with). I can almost guarantee you that at some point the admins of your system have gotten pissed off at the Sun-shipped utils (from hell's heart, sun tar, I stab at thee) and have installed some variety of 3rd-party-freeware utilities on the system (either Sun's freeware, Sun Freeware [different], or Blastwave freeware come to mind). You might try looking, if you haven't yet, in /opt and /usr/local to see if bin dirs exist under there somewhere as these are common locations for these packages. If so, adding them into your shell's $PATH will make interactive use a lot more pleasant.
Re:Wanted: su for a buffer (Score:2, Informative)
Re:macros are cool (Score:3, Informative)
This feature is built into C-x e as well: `C-x e e e e e' is exactly the same as `C-x e C-x z z z z'. :)