views:

551

answers:

6

Possible Duplicate:
The single most useful Emacs feature

So, there is this question for Vim users that keeps popping up in my feed reader, but I'm an Emacs person.

So, what are some of the cool little hacks and tricks you've come up with using Emacs?

And like the Vim thread, I'm talking about the things that only a very few know about.

+3  A: 

This may not be a deep dark secret, but it is one of the most powerful capabilities of emacs: keyboard macros. "C-x (" will start a keyboard macro, and "C-x )" will finish it. Given you can do about anything in emacs, this becomes very powerful. You can redo a macro using "C-x e". I am commonly dealing with a list of items so I often use "M-x apply-macro-to-region-lines".

Ivan
Wow, I often use keyboard macros, but never knew about 'apply-macro-to-region-lines', thank you! I usually end up using C-u '#' to get about the right number, then repeating it a few more times manually.
Ckhrysze
+5  A: 
  • To save the current file using superuser privilege:

    C-x C-w /su::/path/file

  • To kill the current word, s-exp (text enclosed in parentheses), string (text enclosed in quotes), you just need a single command: move the cursor to the start of such entity and press C-M-k

  • To edit file as hex code:

    M-x hexl-mode

  • To execute an extenal shell command:

    M-!

    When negatively prefixed will insert result of command into current buffer:

    M-- M-!

  • To display all lines matching a regexp,

    M-x occur [enter] regexp

  • To set coding system of current buffer:

    C-x C-m f

etc, etc.

huaiyuan
+2  A: 

I started typing out some tips and then realized that I've already read what I just wrote -- I give you, Steve Yegge's Emacs Tips

To that I would also like to add -- use iswitchb for awesome buffer switching.

Also use bookmarks -- C-x r m to set a bookmark in any buffer, give it a name, and C-x r b to jump to a named bookmark. Handy for navigating in a large codebase.

SquareCog
+2  A: 

The extended search and replace function. For example, if you have

bob
sue
ralph
alice
jimmy
preston
billy joe jim bob

and want to capitalize all the words you can do:

M-x replace-regexp Replace regexp: (\w+) Replace regexp with: \,(capitalize \1)

It's all explained nicely in the great Steves Yegge's blog.

Chmouel Boudjnah
Or use capitalize-region.
Eisen
A: 

C-x C-x exchanges point and mark. I don't need it very often but when I do it's brilliant.

Eisen
+1  A: 

The Keyboard Macro Ring.

Being able to record one macro, and then record yet another, while referring to the previous one is mana from heaven. kmacro-call-ring-2nd is the command.

I don't know if it is a dark corner necessarily, but I just found it.

You can also use the Emacs TOTD. Some days it comes up with some duds.. but other days the commands it describes are pure gold.

Jonathan Arkell