views:

16805

answers:

80

My primary editor is Emacs, but my usage habits and knowledge of features has barely changed over the last few years.

What are the Emacs features that you use on a daily basis? Are there any little-known Emacs features that you find very useful?

Edit: Made this into the recommended poll format...please put one feature per answer from now on.

+15  A: 

I'm not sure if iswitchb is little known but it's something I use countless times everyday. It makes switching buffer that little bit easier. When you enter C-x b to switch buffers iswitchb allows you just to enter a unique substring of the buffer name to select it which can often just be a single character. It's hard to explain but easy to try and once you've tried it you'll never switch it off.

partial-completion-mode does something similar in that it can autocomplete any minibuffer commands. It works best if it give it a hint by typing any dashes in the commands. For example, for M-x yank-rectangle I can use M-x y-r [tab] and have it autocomplete.

And there's TRAMP for opening files on remote machines, usually via SSH. It works a treat on Windows using plink.exe from the Putty package.

Dave Webb
s/ I useless countless/ I use countless/
J.F. Sebastian
Thamks. Made the edit.
Dave Webb
Ray Vega
ido-mode is built in now I think.(ido-mode 1)(ido-everywhere 1)(setf ido-confirm-unique-completion t)(setf ido-enable-flex-matching t)(ido-mode 'buffer)(ffap-bindings)
Richard Riley
thanks! using it from now on
Peter
+24  A: 

self-insert, by far, imo.

John
+1. Wow, using Emacs for typing text?! That's the last thing one would imagine.
ShreevatsaR
+84  A: 

Auto-complete words in your code based on what already exists in the buffers:

M-/

Keep hitting M-/ until you find the word you are looking for.

Cuts down tremendously on how much you type.

Ray Vega
As mentioned below, hippie-expand is a good feature. (global-set-key (kbd "M-/") 'hippie-expand)It's just like the default binding for M-/ - except more powerful.
Trey Jackson
+42  A: 

Anything

Anything! It's a kind of Quicksilver / Launchy / slickedit / Ubiquity tool inside Emacs.

Out of the box it allows you to type a word or regex and presents you lists of matching:

  • buffers (defaulting to the previous buffer, allowing you to switch back & forth between two buffers)
  • files from the current directory
  • recent files
  • emacs functions / commands
  • info pages
  • man pages

And it's easily extensible, you can easily add Google suggestions, or grep / find / mdfind tools (most of them being allready there).

With Anything, I don't need iswitchb anymore, and I rarely use (ido-)find-file, since most of the time the files I want to open are already in the recent files list or the current directory list.

It changed the way I use Emacs!

Org Mode

Org Mode for project planning. From the home page:

Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing project planning with a fast and effective plain-text system.

It comes with Emacs, and it has a great integrated, plain text, programmer friendly, builtin table & spreadsheet engine! (Includig auto re-aligning and formulas.)

Smart Tab

Smart Tab makes your tab key smart. If you're at the end of a symbol it tries to complete it, otherwise it indents the current line / region.

It works great for me: it makes line indenting, region indenting and completion available near the home line.

Sébastien RoccaSerra
Tried anything, and its an awesome tool! I was just unable to actually use it, since it "destroys" my regular find-files by making me unable to complete dirs/files and/or edit the suggestions from anything! Not sure if this could be win32-related or not, but I went back to ido.
sandos
+29  A: 

Keyboard macros are very powerful when dealing with list of stuff...I use them as often as possible.

epatel
+16  A: 

Flyspell-mode! "Flyspell enables on-the-fly spell checking in Emacs by the means of a minor mode."

Can be configured to check LaTeX documents and comments in some other languages (flyspell-prog-mode).

cic
Insanely useful. I have a line in my .emacs file to automatically enable it for latex-mode: (add-hook 'latex-mode-hook 'flyspell-mode)
Kimmo Puputti
Yes, and once you get used to using the C-; to correct the last mistake it becomes very efficient.
Borbus
+1  A: 

@Ray Vega I think it is even better if you use hippie-expand. You can configure which functions, and in which order will be called to complete. Here is my list:

try-complete-file-name-partially, try-complete-file-name, try-expand-all-abbrevs, try-expand-dabbrev, try-expand-dabbrev-all-buffers, try-expand-dabbrev-from-kill

query-replace-regexp. The syntax sucks, but once you get used ...

Mario
+9  A: 

Most-used and most-useful features (for me):

  • navigational keyboard bindings (M-b, M-f, C-a, C-e, etc) work well for fancy keyboard layouts. You do not use Home, End, PgUp, PgDn, arrows, therefore there is no need to relearn touch-typing when, for example, on notebook these keys are placed in unusual places.

  • It works in console (emacs -nw) as well as with GUI. And it works under Windows, Linux, Mac. You can use the same editor both in command-line and GUI environment on any OS.

  • It has server-mode which allows an instant opening of new documents in the same editor environment.

  • It allows to view several documents (and/or different parts of the same document) simultaneously. It is especially useful for wide-screen monitors.

  • Embedded command-line (M-!).

  • version-control (C-x v v - do the next logical version control operation on the current file.)

  • find, open, switch, create file, buffer (C-x C-f, C-x b) via ido.el

J.F. Sebastian
+79  A: 

A not so well known feature that I find very useful is M-x align-regexp. If you mark a region and execute it, you will be asked for a regular expression, and emacs will then line up the first match of that expression on every line, by padding with spaces (or tabs, if you like). For example, say that you have a list of variables in your code:

int a = 2;
int a_longer_variable_name = 73;
int i = 0;

Then you can mark those lines and to M-x align-regexp and specify = as the expression, and it will align it like:

int a                      = 2;
int a_longer_variable_name = 73;
int i                      = 0;

Maybe not the most important feature in the world, but I use it regularly, and it sometimes impresses non-emacs people. :)

ehdr
Wow, this is amazingly useful in combination with kill-rectangle!
rcreswick
I love this! Doing this by hand is a real pain. I'd never even thought about automating it!
allyourcode
The only problem with this is that if later you add a longer variable name than your maximum, you need to re-align the other lines - which introduces meaningless DIFFs into your source control. The general rule is that a line shouldn't change in source control unless its meaning or functionality changes.
Erik Forbes
Erik: If you add a new variable, "it" (the block of variable definitions) has changed it's meaning or functionality. Code should be presented in a way to best convey it's meaning to the reader and, until we have editors that can do it all automatically the way each person likes it done, this type of formatting will continue to happen.
RHSeeger
I also don't find this a very good programming practice, but the command is extremely useful when formatting other types of text, like ad-hoc tables in documentation and all sorts of non-programming uses.
obvio171
Don't do this in Python, if you care about PEP8.
Vince
@Erik Forbes: That's because source version control systems are broken. They should be agnostic: parsing the AST for a C source file and noticing that they're actually identical files, same for Java, C#, etc. Anyway, the issue you raise and 15 people upvote can be solved by formatting to a common accepted codestyle before committing. Now comes a line about *"people seeing the world as it is and wondering: why?"* versus *"people imagining the world as it could be and wondering: why not?"*. Something like that ;)
Webinator
@RHSeeger - That's true, but I was talking about all the other lines - if, taking his example, I add a variable named 'a_really_really_long_variable_name', then I need to change all the other variable declarations which have no business changing since the functionality isn't changing. Hence - meaningless diffs.
Erik Forbes
@Webinator - I wish, man, I wish. AST-based source control would be awesome - although there'd have to be some sort of hooks for the type of information that gets lost during the translation, like comments, metadata, file names, etc. At least for C#, once the whole 'Compiler as a Service' bit comes out, maybe we'll start seeing some movement in this area. I'm keeping an open mind.
Erik Forbes
@Erik, that's what diff -bB is for
jdizzle
+14  A: 

dired (M-x dired) let me navigate folders by touch-typing, much faster than browsing in a GUI.

Bart
Or faster: C-x d
Jeremy Powell
This is what I mainly use emacs for :)
sandos
I use `M-x find-dired` a lot. Useful for a getting a dired buffer containing a list of all the files (filtered by the Unix find command) in a directory, and its subdirectories, recursively.
ataylor
+8  A: 

Though it's not an emacs feature, it's always worthwhile to point out to any newbies to remap their caps lock keys to control. Save those pinkies!

Devrin
despite popularity, this is a very bad advice--it puts undue stress on the left hand and the left pink! the original emacs keyboard had controls on both sides of spacebar (followed by meta, super and hyper). splittist elaborates here, http://splittist.livejournal.com/3114.html
æon
Traditional UNIX keyboards typically had the control key where the caps lock key is now, hence the remapping tradition. You use your pinky for hitting shift and tab, and caps is even easier - give the finger some credit! It's a LOT better than the default layout, so I wouldn't call it bad advice.
Alasdair
I don't have any problems with control in either location. Meta, however - I bring my left thumb under for meta, but I have oddly-formed thumbs, so maybe that only works for me.
JasonFruit
The whole, rebinding capslock/pinky pain problem is the entire reason I bought this keyboard http://www.kinesis-ergo.com/advantage_pro.htm and rebound the left thumb pad so Ctrl and Meta are more easily accessible.
docgnome
I second the idea to put control on either side of the space bar and metas next to control. In this way, I am able to press both ctrl and meta with the opposite thumb.
Joseph Gay
+1  A: 

re-builder

ionut bizau
Already suggested a few hours earlier :)
jlf
+9  A: 

Compiling from within emacs, and then for each error, being able to visit the line of code causing the error with a keystroke.

Graeme Perrow
+37  A: 

Don't forget about a little known command C-x M-c M-butterfly

J.F. Sebastian
Please don't upvote jokes in questions not tagged as 'fun'
Jakub Narębski
Quite right: no fun unless the `fun` label is present; also, never on Sundays.
Telemachus
Hey, it exists in emacs 23 now...
Kendall Helmstetter Gelner
Please don't upvote douches in questions not tagged as 'douche'
Justin
Somebody set us up the vote!
Konamiman
+1 I saw the question title and instantly knew this would be an answer.
dotjoe
You know M-x butterfly actually exists, right?
Adam
@Adam: I know http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1695a1a754766c9978687767e7f27c800bed028d
J.F. Sebastian
+13  A: 

hippie-expand, best text expansion in emacs, binding it to TAB and it will always do the right thing (and also very customizable).

Łukasz
+14  A: 

I like interactive SQL mode to give me command line editing and history while using sqlplus.

M-x sql-oracle

And I add the following to my .emacs file:

(defun my-sql-interactive-mode-hook ()
  (setq tab-width 8))
(add-hook 'sql-interactive-mode-hook 'my-sql-interactive-mode-hook)
(require 'sql)

Now I can start a sqlplus session and I get C-up and C-down to navigate through prior sql commands (similar to shell mode). This requires sqlplus to be available.

Alex B
This is awesome, fantastic :)
robertpostill
Also, `M-x sql-mysql`, `M-x sql-postgres`, etc, for just about any SQL database you're likely to be using.
ataylor
In addition, I find it useful to `(setq truncate-lines t)` in my `sql-interactive-mode-hook`, so emacs won't try to wrap wide table selects.
ataylor
An oft overlooked aspect of interactive SQL is that it works through TRAMP. Just execute the command while viewing a remote shell buffer or dired buffer. The most important thing to note is that your SQL session runs through localhost on the remote machine, which is so cool, it almost merits a separate answer. What this means of course, is that you can take advantage of the interactive SQL interface in your existing Emacs to a machine that doesn't allow remote SQL server connections.
Joseph Gay
+6  A: 

I find the Emacs Code Browser to be very useful for browsing the large code base we have at work. I also Have to say the most useful feature is really elisp itself. While I think it sucks, it only sucks compared to scheme or another lisp variant. It is by far the most powerful, imho, scripting language built into any editor.

docgnome
+6  A: 

The ediff- commands, there's a bunch of variations, up to and beyond merging a full directory tree.

M-x ediff [then tab to the variant you need.] While editing I use ediff-buffers frequently.

The | switches between vertical and horizontal layout, it's color coded to help see just which word/letter changed.

sammyo
+29  A: 

Here's the rundown of my F-keys:

F1: Gnus. Takes some learning, but cut my daily email time down to 20 minutes.

F2: ansi-term. Fairly full featured terminal emulator with a mode where you can switch back into behaving like an emacs buffer for kill/yank/macro goodness.

F3: slime. Crazy good tool for hacking the good hack with Common Lisp.

F4: switch-to-buffer "scratch". The scratch buffer is a good place to do fancy Emacs stuff when you don't want to type in the mini-buffer (try C-j).

F5: compile. You don't realize how great this is until you also grok next-error and previous-error.

F6: visits the buffer I have usually associated with an SQL session, either in an ansi-term or using psql.

F7: w3m. Very slick, fast web browser. Perfect for searching documentation.

F9: Visit my todo file in org-mode. org-mode, like gnus, takes a while to learn, but you can go so damn fast with it, it's worth it.

F10: calendar. Not as nice as org-mode but I haven't switched over all the way yet.

F11: open the EMMS playlist. EMMS doesn't come with the usual upstream Emacs distribution, but it's a pretty reasonable OGG/MP3/etc player.

F12: I run ERC and bitlbee. F12 brings me to the chat buffer with all my contacts from Google Talk and AIM in it.

Insanely cool thing not on one of my F-keys: TRAMP. TRAMP integrates into the way emacs finds, reads, and writes files. You can use file names like /sudo::/etc/passwd to edit things as root without starting another emacs, or /ssh:[email protected]:foo/bar.html to edit files remotely without staring a remote emacs.

Generalized ompletion modes and facilities are useful too. I like completion.el, but there are several to choose from.

Definitely check out www.emacswiki.org. Tons of good ideas there. Good luck!

jfm3
+1  A: 

Little known but useful:

M-x isearch-forward-regexp

Incremental regex search that you can edit while it runs to get the regex matches correct.

dajobe
C-u C-s does the same thing with fewer keystrokes.
hillu
+10  A: 

Someone else mentioned keyboard macros, but provided a broken link.

That feature may seem inane if you've used it with other platforms. But keyboard macros in Emacs are far more powerful, or at least easy to access the power of, than any other system I have used.

You can start simply by typing "C-x (", then anything you do is recorded to be played back... which means searches, replacement, opening new files, and so on. Then when you are done you can type "C-x )" to end the macro, and C-x e to replay the last keyboard macro. If you want to execute a macro multiple times, you can do so by pressing "e" repeatedly after the first execution via "C-x e". You can also run name-last-kbd-macro to name it, then use insert-kbd-macro to save off the macro you just defined somewhere (like .emacs).

The real power of macros comes into play when you use multiple cut buffers (registers), to save away various fragments of text in the middle of a macro and re-use the parts elsewhere. You can for example have a macro that expects some key text to be in register A for insertion, perhaps a search term in register B, and some other text to append elsewhere in register C grabbed on the fly within the macro. Or of course use multiple registers like multiple clipboards, all within emacs - the key bindings are different than they once were, but the commands you want are copy-to-register and insert-register.

All that, and it's basically as simple as typing something once (carefully) and then having Emacs repeat what you were doing with very complex changes possible.

I have used the combination of keyboard macros and registers to do things as diverse as turn lines of words into multiple lines of code appropriate for the word on the line, repair damaged LDIF files from an LDAP system, or do various refactoring tasks.

Kendall Helmstetter Gelner
The keybindings are C-x (, C-x ), and C-x e. And it is terribly annoying that macro recording stops right away once you make a mistake and cause C-g to be pressed.
Jouni K. Seppänen
I took the liberty to correct the bindings.
Svante
I have to agree with this one - even though most of my programming time these days is spent inside Visual Studio, I still find myself copying block of text into emacs, running a few macros, then pasting the results back into VS.
chris
Oooo. Clever use of registers. I'll have to remember that.
Paul Nathan
You can also repeat a macro by using C-u and a number. If the number is 0, the macro will go on until it rings a bell, runs out of input or something like this--this can go on indefinitely.Another fun thing to do is to use the scratch buffer to execute arbitrary elisp lines with C-j. This way you can subtract numbers, or something.
Tikhon Jelvis
and if you mess up a macro, fear not. C-x C-k C-e and you can edit your macro
Martin Neal
I love keyboard macros with `apply-macro-to-region-lines` Which is bound to `C-x C-k r` on my system. Emacs will go to the beginning of each line in the current region run the macro.
Shannon Severance
+6  A: 

Another one of my favorites is the transpose-* family of functions. They allow you to instantly switch two units of text around the current position of the cursor. For example, tranpose-words on key M-t switches the word in front of your cursor with the one behind it, tranpose-chars on C-t does the same with characters.

Perhaps the most useful variants are tranpose-lines (and especially the tranpose-line-up and -down variants of XEmacs) for moving lines around, and transpose-paragraph which switches entire blocks of code instantly.

If you really master these commands and make them part of the "active set" of emacs features that you actually use all the time, you will find that they add a whole new flow to editing code.

And, important as always, it sure does impress people who don't (yet) know the power of emacs. :)

ehdr
Also for s-expressions very useful.
Svante
+9  A: 

M-x gdb to test in the debugger while automatically moving through the source tree in other windows. Set break points by opening the source file and doing C-x on the appropriate source lines.

CJP
Try M-x gdba in emacs 23+ for even grand magic.
Vardhan Varma
Followed my M-x gdb-many-windows!
small_duck
+17  A: 

Elisp. While the language itself can be a little bit clunky (for a lisp) it is so nice to be able to extend or fix your editor on the fly when you need to do so.

Jonathan Arkell
That's like wishing for more wishes! You can't do that. =)
technomancy
+10  A: 

Using ido for finding symbols in the current buffer: http://www.emacswiki.org/cgi-bin/wiki/ImenuMode

Speeding up navigation by adding shortcuts to jump 5 lines per keystroke:

;; Faster point movement
(global-set-key "\M-\C-p" 
  '(lambda () (interactive) (previous-line 5)))

(global-set-key "\M-\C-n" 
  '(lambda () (interactive) (next-line 5)))

But the single biggest productivity booster for me has been swapping numbers and punctuation when programming in C++: http://infolab.stanford.edu/~manku/dotemacs.html

Chopmo
If you're moving more than a few lines, you probably should be moving either by page, or by using search. It's much faster to `C-s sometext` in most cases. Just pick something near the line you need. When it gets automatic, it's lightning fast.
Paul McMillan
If you want to invoke commands that accepts numeric arguments you can use prefix C-u to send an argument of 4 to the command. So C-u C-p moves 4 lines up by default.
antonj
+51  A: 

M-x occur

This feature is very useful when re-factoring/analyzing code. It's one of the things that keeps me from becoming a Vim user.

TMealy
:g/regex in vim will do the same thing ;)
camflan
Just hitting C-s (for search) already highlights all occurrences in a default Emacs
ShreevatsaR
This is one of the reasons I simply *love* Emacs: after about 7 years of use I can still discover useful new things coming with the default installation. Sometimes the shiny "new" feature I just discovered or learned about is 10-15 years old ... :-)
paprika
Don't forget about M-x multi-occur and M-x multi-occur-in-matching-buffers, which allow you to occur across multiple buffers.
ataylor
+8  A: 

EmacsWiki

+6  A: 

Something that can be very useful at times, especially when renaming a bunch of files: In a Dired buffer, type "e" for wdired-change-to-wdired-mode, which allows you to edit the directory using any of your normal editing commads: regex-replace, rectangle commands, etc on file names!

On a related note, the rectangle commands are also quite useful when you get used to them.

jamesnvc
It should be noted that 'e' is not a default binding. In fact, I don't think it's bound to any key by default.
paprika
'e' is bound to `(dired-find-file)` (GNU Emacs 23)
J.F. Sebastian
At least in GNU Emacs 23, `(dired-toggle-read-only)` (which is the same thing) is bound to `C-x C-q`.
monotux
A: 

Ubiquity. Not exactly a "feature" per se, but important nonetheless. You can log into pretty much any *nix machine in the world, and expect emacs to be there.

Sherm Pendley
This is more true for vi/vim than emacs.
docgnome
Even more true for ed: "The Standard Text Editor"! ;-) (I much prefer emacs to ed though!)
A. Levy
+4  A: 

For those coding in C in large projects cscope is etags killer. Mapping the shortcut

(define-key global-map "\M-."  'cscope-find-this-symbol)

in dot-emacs will make you forget about tags.

Of course you have to index your project but here is another helper:

(setq  cscope-database-regexps 
   '(
     ("^path_to_your_most/used/project/directory/tree/regexp.*" 
      ( t )
      ("path_to_first_indexed_tree")
      ("path_to_second_indexed_tree")
      ("path_to_third_indexed_tree")
      ("etc")))

Put it in your dot-emacs (there can be several entries for different projects) and (x)emacs will know where to look for symbols for current buffer, so you don't have to index whole project - just the modules you work on.

cscope greatly improves understanding and refactoring of C source in big projects. Every hit of M-. presents you an active list of symbol use with one line context.

Rajish
+4  A: 

hexl-mode is priceless for examining/editing non-text files.

Ferruccio
+20  A: 

yasnippets

Textmate-like snippet expansion functionality for Emacs.

I wouldn't call it refactoring; maybe snippet expansion or code-assistance are better terms.
Cheeso
the project is hosted on google code - http://code.google.com/p/yasnippet/
mozillalives
+1  A: 

Not really an editor feature proper, but having a foot pedal to avoid "Emacs pinky" is nice. My pedal has three buttons bound to Control, Meta, and Shift.

Greg Mattes
+8  A: 

Numbering in macros.

In the new(er) Emacsen, 'F3' is bound to start recording a keyboard-macro and 'F4' is bound to end recording a keyboard macro (and to replaying the last recorded keyboard-macro).

Press 'F3' to start recording a macro.

Now: when pressing 'F3' again while recording the macro, a counter is inserted which is incremented each time you play the macro back.

I found this incredibly useful in a surprising number of situations.

Press 'F4' to stop recording the macro, and press 'F4' again as many times as you need to repeat the macro.

Tim van der Leeuw
+6  A: 

How about Digit-Arguments for the next command. Before, I have always used Universal-Arguments via C-u but you can go much faster since Digit args are bound to both, Control and Meta.

Examples:

  • move point 3 words forward: hold down Meta and type 3f
  • kill those lines below: hold down Control and type 33k
binOr
A: 

A feature that I have found very useful is that whenever you're using Tramp to access a remote server and then into dired mode on a folder on that server, you can upload files from your computer with a simple drag and drop.

wallyqs
+2  A: 

I listed some of the packages I rely on most here:

Regularly used Emacs packages

Richard Riley
your link is broken
Joakim Elofsson
I editing to what I believe is the correct link that I found on his site.
mwilliams
+11  A: 

M-x rgrep

I've bound it to F4, I'm using it all the time to interactively greping for file in a recursive manner. Combine that with easy bindings for next-error (F9), previous-error (shift-F9) and you have struck gold!

It always makes my co-workers impressed how quickly I can find things. No tags needed and it's /very/ fast.

Johan Dahlin
+1  A: 

Minibuffer completion with Icicles.

Alexey Romanov
ido-mode provides it too. Icicles is way too complicated for most people IMO. Powerful yes, but you really need to invest a lot of time and effort to come to terms with its usage.
Richard Riley
+5  A: 

tramp-mode (and/or Ange-FTP): it lets you view and edit files over SSH, FTP and other protocols as if they were local.

You may want to know that you can specify the port for FTP with "#" after the host name. At least it took me a while to find out...

(Especially useful with Zope, when you can remotely edit objects in the running instance over FTP and in the products over SSH)

robcast
+2  A: 

I switched from using nedit and vi to emacs (now Xemacs) for column editing and the AUTOs in verilog-mode. cua-mode enables the familiar key bindings - specifically clipboard (undo-Z, cut-X, copy-C, paste-V) key bindings - it really helps to ease the transition to emacs because you can use the normal emacs key bindings at the same time.

Since then I have found many modes to make (x)emacs like the IDE Eclipse only better because I don't have the performance hit (memory and speed) and I don't have to work inside of an Eclipse project. Check-out CEDET.

Nathan
+4  A: 

selective-display aka code folding aka code summarizing

Code Summarizing in emacs plain beautiful(not really code folding since you're not closing up just one or two functions). It allows you to display only code that has a certain level of indentation in front of it. So you can hit a button and only classes show up or pass an argument with M- then hit the button and only the classes and the function definitions show up. Makes moving around code just plain easy. This works incredibly well with python's enforcement of indentation.

Silfheed
Thanks, set-selective-display is new for me, and quite useful.
Joseph Gay
A: 

One very useful package is the BrowseAproposUrl stuff:

http://www.emacswiki.org/emacs/BrowseAproposURL

I added some functions to translate using google dictionary and google translate a bit easier.

http://www.emacswiki.org/emacs/BrowseAproposURL#toc5

Richard Riley
+2  A: 

M-i

This insert spaces or tabs to next defined tab-stop column. It alows me to align everything with a few key presses which if very useful when you want a nice code.

Example:


int i = 1;
GtkWidget *window, *label;
double *a, *b;

can become something like this:


int          i = 1;
GtkWidget    *window,  *label;
double       *a,       *b;

Additionaly you can customize places where you want tab stop with:


M-x edit-tab-stops
kliketa
+2  A: 

dired! and in there: dired-mark-files-regexp, dired-do-rename-regexp and dired-do-shell-command

when editing (blog) texts: transpose-chars (CTRL-t). :-) a command i miss in most text editors.

when programming: python-mode, its py-comment-region and py-execute-buffer (with setting py-which-shell as local varuable).

halloleo
Also, `dired-mark-files-containing-regexp` (`%-g`)
ataylor
+7  A: 
C-x C-o runs the command delete-blank-lines

I know it is quite basic, but extremely useful; delete several blank lines at once, or (when cursor on nonblank line) delete any immediately following blank lines.

libjack
And vice versa, you can use `C-o` (open-line) to insert a blank line
Patrick
+11  A: 

M-x re-builder

Interactive regular expression builder that shows you live in the current buffer just what the regular expression is matching. Great for working out what things might need to be escaped (e.g. () pairs) and whether there's hidden tabs in the whitespace.

When you're done you just cut-n-paste into M-x query-replace-regexp or similar.

Dave Jennings
+8  A: 

M-x shell to directly access the shell from emacs. When used with a split screen (C-x 3), it becomes very quick and easy to do things. No need to continually switch between programs.

Nikwin
I prefer `M-x eshell` when running emacs on a Windows. It gives a more *nix-like experience over the native `cmd.exe` shell. (Plus, you can execute elisp at the command-line.)
Ray Vega
Cool, thank you for that.
Nikwin
+23  A: 

string-rectangle (C-x r t) and kill-rectangle (C-x r k). They allow to add stuff in front of every line in a block of text or---vice-versa---remove such stuff.

Heinzi
What would be the potential use cases for this (other than commenting/uncommenting blocks of code)?
Sridhar Ratnakumar
@Sridhar: Indenting blocks of code, editing text tables (in combination with yank-rectangle (C-x r y)). But yes, I also use it mainly for commenting/uncommenting and similar stuff (like adding a double quotation mark in front of every line).
Heinzi
+3  A: 

Many of these have been mentioned already, but here's my list:

auto-indent: I love that when I hit tab it automatically indents "correctly", regardless of the type of the file. Also, the fact that you have many options of indenting style!

elisp: I've written so many stupid little elisp functions... I love that I can just create a function that does exactly what I need... (Favorite: M-x bp-folgers-crystalyze: secretly replaces the meta-syntactic variable "foo" with folgers crystals)

indent-region: auto-indents any region. Tells you where your missing ; is immediately!

C-n C-f C-b C-p: I never use the arrow keys anymore. (To the point where I'm always annoyed that C-b gives "block quote" on SO...)

bookmarks: constantly editing .emacs? no problem.

Multiple frames, keyboard switching between frames and windows: I don't need to use the mouse!

Paren matching

comment-region: Uses mode-dependent comment syntax to comment out every line in a region.

Brian Postow
Please share the code for bp-folgers-crystalyze :)
Readonly
It's not much: (defun bp-folgers-crystalize () "secretly replaces the meta-sytactic variable foo with folgers_crystals" (interactive) (let ( (i (point))) (beginning-of-buffer) (while (search-forward "foo" nil t) (replace-match "folgers_crystals" nil t)) (goto-char i))) [sorry for bad formatting, can't format comments evidently]
Brian Postow
+4  A: 
killdash10
+6  A: 

My vote goes to org mode plus remember templates,

;;Remember
(org-remember-insinuate)
(setq org-directory "~/org/")
(setq org-default-notes-file (concat org-directory "/notes.org"))
(define-key global-map "\C-cr" 'org-remember)

;;Remember templates
(setq org-remember-templates
      '(("Todo" ?t "* TODO %?\n  %i\n  %a" "~/org/todo/TODO.org" "Tasks")
        ("Journal" ?j "* %U %?\n\n  %i\n  %a" "~/org/JOURNAL.org")
        ("Idea" ?i "* %^{Title}\n  %i\n  %a %:date" "~/org/JOURNAL.org" "New Ideas")))
A: 

webjump

Let's you quickly launch webpages with search terms. For example a google, wikipedia or flickr image search can be quickly launched in your favourite browser from emacs.

justinhj
+3  A: 

The grep-find command

M-x grep-find

search a pattern in current directory files and subfolders

My grep-find command is customized like that :

(custom-set-variables

....

'(grep-find-command "find . -type f -not -name \".svn-base\" -and -not -name \"~\" -and \( -name \".html\" -or -name \".php\" -or -name \".py\" -or -name \".sql\" -or -name \".js\" -or -name \".css\" -or -name \".sh\" -or -name \".tex\" -or -name \"Makefile\" \) -print0 | xargs -0 -e grep -n -s -F ")

....

)

fredz
A: 

Quiting (it was a while before I learned that), as being unable to quit Emacs kept me from wanting to use it. Was the same with Vim. Why does a simple command like 'exit' need to be so complicated?

CTRL-X-C

Andrioid
as opposed to :wq! in vi?Eat Flaming Death!
Brian Postow
(BTW, that was an obscure reference, for those who don't get it...)
Brian Postow
quitting is, I would say, worst "single most useful feature" of emacs, because you can only use it once per session and, the more you enjoy emacs, the less you should really use it.
Justin Lilly
There is no "exit".Did you mean C-x C-c?
Richard Riley
A: 

M-x is the most useful feature

+7  A: 

Most of us are familiar with M-! for running a quick shell command from inside Emacs. A somewhat lesser known facet of this function involves using a prefix command of 1:

M-1 M-!

This runs the shell command and inserts the output at point in my buffer.

But what good is that? It lets me insert text into buffers, but not interact with it in any significant way. What I really need is a way to get the shell to take input from my buffer. Enter the cousins M-| and M-1 M-|. From the docs:

M-| runs the command shell-command-on-region, which is an interactive compiled Lisp function in `simple.el'

M-1 M-| runs a shell command on the region and replaces the region with the output of the command.

In general, I prefer to use features built into Emacs, but when there's no Elisp equivalent available, I can carry out text transformations I need simply and easily:

M-1 M-| perl -p -e 'y/a-zA-Z/n-za-mN-ZA-M/'

To rot-13 encrypt a region quickly, for instance.

(Incidentally, The keystrokes C-1 through C-0 and M-1 through M-0 are the same (by default) as C-u 1 through C-u 0, which makes it very easy to type in repeat arguments. Just hold down M and type in 1 and |, or hold down C and type in 7 and n.)

+14  A: 

How about the newbie-friendly

C-h k

which shows the documentation for the command associated with any key.

Or

C-h f

which shows the documentation for any particular command, given its name (i.e. what you would type after M-x).

I find these to be very helpful while learning emacs.

Galghamon
C-h a is arguably more useful than C-h f on the assumption that you don't quite know the command name
jk
You can also use `C-h c` to describe a key command in the minibuffer. For instance `C-h c C-h c` prints "C-h c runs the command describe-key-briefly"
Patrick
A: 

Regular expression search backwards, just because it has a funny keystroke:

ctrl+alt+shift+5

fortran
+1  A: 

Bongo

Manage playlists and play music from within Emacs. Supports multiple different backends. It even supports streaming from internet radio. I use it to listen to internet radio feeds while working. Especially useful if working in a non-desktop environment.

Karl Voigtland
A: 

The fastest way to checkin/out: M-x svn-status

ayman
+3  A: 
multi-occur-in-matching-buffers

Allows you to regex search inside of all open buffers that match a regex

Carlos Rendon
A: 

TFS + emacs is one of the less well-known that I've been finding to be very useful. I can checkin/checkout files from codeplex, add or delete files, diff, rename, undo, etc.

Maybe not the single most useful feature, but very useful.

Cheeso
+1  A: 

Check out company-mode.

Excellent completion interface.

be sure to try C-s and the C-o to filter the completion candidates.

My completion set up is here:

http://richardriley.net/projects/emacs/dotprogramming

Richard Riley
+2  A: 

M-x toggle-truncate let's me switch of line-wrapping as a quick outline mode. Not so useful when programming, but definitely so when editing docs or html.

Zano
A: 

hi-lock-mode! I very recently found this, and in combination with auto-revert-tail-mode emacs can easily replace most cusom tail-applications if youre in windows.

sandos
+3  A: 

If you want to get all commands to a particular keyword just use the apropos command.

M-x apropos

This is very helpful if you want to learn new features within Emacs or if you just want to find a command by a given keyword.

Achim Tromm
+2  A: 

Some of these are really basic commands, but they do help me out a lot:

  • when hacking my .emacs config or other eLisp modding I place the cursor at the end of a line and press C-x C-e to evaluate the expression. This is a true friend for emacs tweakers.
  • C-l and C-u 0 C-l to jump cursor position to middle and top of screen. This is great for reading those long lonely log files. I also have key-binding for the latter since I use it so much.
  • C-x b and C-x C-b to navigate those buffers real fast. Combine this with window splitting ( C-x 2 and C-x 3 ) and you will do magic when showing off your log analysis to colleagues and managers... :)
  • The almighty incremental search: C-s and try pressing C-w a few times after. This is also one of the most productive, commonly used features of emacs. I myself was struggling with copy-pasting to the search field before I found this cool feature. C-g shall return to the point where you started out from so no worries about that either.
  • Try key-binding window movement it is a blast in productivity:
    • (global-set-key [S-left] 'windmove-left)
    • (global-set-key [S-right] 'windmove-right)
    • (global-set-key [S-up] 'windmove-up)
    • (global-set-key [S-down] 'windmove-down)
  • Last, but not least is the almighty UNDO feature C-/ which is my personal favorite in emacs, since it reflects how easy it is to use in emacs and how we do not need a separate command for REDO, since it actually is the undo of the undo.

These might sound too simple, but are really powerful features in everyday use.

Dlf
+1  A: 

For me, it's got to be ediff - it's saved my life on a number of occassions.

cristobalito
The mind boggles - what life threatening situation were you in that needed diff? See also http://xkcd.com/208/.
Dominic Rodger
+2  A: 

I like using rcirc client. You just do M-x irc.

Well, I used vim for years and recently I moved to emacs and I found it pretty amazing and useful that you can use an irc client from your text editor (not using irssi any more).

You can also add the following lines in your .emacs file to automatically connect to a specific IRC server or join specific channels.

(setq rcirc-authinfo '(("freenode" nicserv "your_nickname" "your_password")))
(setq rcirc-server-alist '(("irc.freenode.net" :channels ("#channel"))))

Here you cand find more infomations about rcirc Getting started with rcirc

And of course there is M-x tetris in case you are bored ;)

+5  A: 

I recently discovered C-u C-spacebar. Emacs keeps track of all the places you've navigated to, and this lets you pop off the stack (taking you to a place you were before you came to where you are). Extremely handy when chasing call trees in source code.

jdizzle
+1  A: 

For me, the single most useful feature is my .emacs file - there is a lot of power to be had in a scripted config.

dcm
+5  A: 

Org-mode. My whole life is in a massive, single .org file.

Kenneth
A: 

org-mode - Org-mode is for keeping notes, maintaining ToDo lists, doing project planning, and authoring with a fast and effective plain-text system. You can use it as a GTD (Getting Things Done, note taker and web/PDF authoring. http://orgmode.org/

duanedesign
"Put it an org-buffer and smoke it!" `:-)`
monotux
+1  A: 

For me it's rectangles. Create rectangles by placing marks (C-space)

  C-x r k (Kill Rectangle)
  C-x r y (Yank Rectangle)
  C-x r t (Append a prefix to rectangle)
zmf
Make sure you try out the CUA-rectangles - `C-enter` to start a rectangle, use the normal `M-w` to copy *etc*. [emacs-fu posted this as a tip, check it out!](http://emacs-fu.blogspot.com/2010/01/rectangles-and-cua.html)
monotux
+7  A: 

Pretty hard to limit myself to the single most useful feature, but I like this command that hasn't been mentioned yet: auto-revert-tail-mode.

Open up a log file you’d like to monitor in emacs and then do M-x auto-revert-tail-mode. Emacs will automatically watch the file, just like POSIX tail -f.

Pete
A: 

Flymake is the tool I cannot live without when programming. Correctly configured with Makefiles (I even use flymake on Windows), you instantly see, on-the-fly, all the errors and warnings that your compiler can find.

And this tool is part of GNU Emacs by default.

Jérôme Radix
+1  A: 
[ESC] [ESC] [ESC]

just try it on a frame with multiple windows.

Jérôme Radix
A: 

M-x gdb for debugger

M-x shell for runing code

f9 - compile

f10 - recompile

and CUE for C-c C-v C-x for copy/past/cut

shk
+2  A: 

Bookmarks. Emacs bookmarks are both named and persistent, two features that many editors fail to offer.

They are invaluable because not only can I save my place in a file, I can also bookmark a directory that will be opened with Dired. I use them to jump to my most visited locations on the file system, and my main Org Mode files. Having a bookmark which effortlessly takes me where I want to go prevents me from losing my focus while I click around in the Finder or Windows Explorer.

I manage large numbers of bookmarks by namespacing them - all of my Org file bookmarks start with 'org' for example. This makes it easier to find a bookmark with tab-completion.

How to use them:

  • C-x r m BOOKMARK <RET> Set the bookmark named BOOKMARK at point (`bookmark-set').

  • C-x r b BOOKMARK <RET> Jump to the bookmark named BOOKMARK (`bookmark-jump').

  • C-x r l List all bookmarks (`list-bookmarks').

I'm still waiting for Visual Studio to introduce named bookmarks - you need to install ReSharper just to get numbered ones!

Martin Owen
Thank you so much for that, I had no idea it existed. Tt will make my life so much easier!
Vivi