Some useful features of Emacs that are around, but sometimes take years to discover.
I would prefer that this page not turn into an emacs vs X war, but merely as a useful page for people who already use and prefer to use emacs, but may be missing some useful functionality. Not everyone likes to read the 400-page manual. So drop in on GreatVimFeatures if you feel provoked!
See also GreatEmacsLispSnippets
How about:
- input completion -- when you are prompted for input that can match any of several possible candidates, just type a bit of the name, then hit 'TAB' to complete the name
- outline-mode and its cousin, selective-display (C-x $) -- view and manipulate text files (including source code) as tree structures
- saving frame properties in registers, e.g. register s has the properties: frame split in two, top part with the code you're working on, bottom part 10 lines high and containing a programming shell. (C-x r f to save, C-x r j to restore)
- the mark ring, including the amazing command C-u C-space which takes you back to wherever you were previously working -- and to the one before that, if you hit it again, etc. (Is there any other editor in the world besides emacs with a feature like this?)
- IncrementalSearch, optionally using regular expressions (I haven't seen any other editor with this feature)(*), with a history of previous search values
- M-/, or dabbrev-expand: expand the word before point, using every buffer in the editor as possible expansions. So addr M-/ becomes addressOfServer, addressOfClient, etc. Endlessly useful if you misspell received as much as I do.
- Deep integration with the work environment; this is most noticeable when coding in the built-in EmacsLisp, where you can ask the Lisp environment what the arguments to this function look like, or to compile this, or what the documentation is for this symbol, or to macroexpand that s-exp. The cool bit is that it works in other languages, too: JDE, for example, can interrogate your Java runtime about classes it contains, and methods in those classes. IlispMode is a similar package for external Lisps. Smalltalk and VAJ are similar, but for only one language at a time.
- Structural navigation keystrokes: M-C-a, M-C-e, M-(, and friends. These work across languages, to move forward and backward across language elements, not lines, and to enclose language elements in parentheses.
- The customization described in FixmeComment.
- ff-find-other-file to switch between C++ include files and implementation files.
- hideshow functions to hide levels of code (see progmodes/hideshow.el)
- grep and grep-find to search for regular expressions in sets of files. Use next-error (C-x `) to jump to the matches.
- calc is a very nice (and powerful) calculator.
- great automation and scripting!
- keyboard macros (start-kbd-macro ('C-x (') end-kbd-macro ('C-x )') name-last-kbd-macro call-last-kbd-macro (C-x e)) Record keyboard input. For example, this is useful for taking function declarations in a C++ header file and moving them to an implementation file (virtual void foo(); becomes void class_name::foo(){}; for all the functions in the header file).
- EmacsLisp (elisp) - one of the most powerful customization languages around.
- ispell to spell check comments in code.
- narrow-to-region (C-x n n). This restricts editing to the current region. Use widen (C-x n w) to remove the narrowing restriction.
- * It's amazing how useful narrow-to-region is in lisp code when combined with save-restriction. You don't have to worry about any code that munges the text in the region escaping the region, because it becomes your whole buffer while your function runs.
- Not one, but six different packages to emulate vi/vim (some people like vi's UI): vi-mode, vip, viper, vimpulse (vim-like addons for viper), vim-mode, and evil
- iswitchb (IswitchbBuffer)
- shell mode. Almost every Emacs user I know doesn't use shell mode. They always C-z to the command line, an incredible waste of capability.
- check out term mode (M-x term) and eshell mode (M-x eshell) too. Term mode is useful for running programs that use ncurses, e.g. nethack-console.
- sql mode. Run SQL*Plus within Emacs.
- recursive edits. Search/replace for function calls, and interactively decide whether to replace it, skip it, or edit it and continue.
- M-x balance-windows
- M-x compare-windows. Used with C-x-2 to split the screen. How can anyone live without this feature? (JavaSchrod)
- ediff. visual difference viewer and merger, working with RCS, CVS, etc. I especially like how it clearly indicates when there are only white-space differences between two regions.
- WikiMode wiki-mode.el, which lets you turn all the files in a directory into a miniature wiki. emacs-wiki.el seems to be more powerful.
- rectangle functions (C-x r ?) to cut, copy, and paste just columns x through y of a block of text (e.g. chop the "> " off the beginning of every line)
- set-fill-prefix (C-x .) Take an email quote, go just past the leading "> ", and hit C-x . - now when you fill the paragraph (M-q), it does the right thing with the "> " prefixes.
- efs. Edit files you can FTP to as if they were local. Just type something like: /ange@anorman:/tmp/notes as a filename, and recent Emacsen will go get it, let you edit it, warn you if it changes while you're working on it, auto-save it, make a ~-backup when you save... And you can use this extended syntax anywhere you can use a regular filename - I keep my emacs diary file on my web site, so I can easily use it from anywhere.
- Even better than efs is tramp, which lets you edit any file you can get to by ssh or telnet. Works with ssh and PuTTY, and I think it even has DAV support now by way of using cadaver.
- calendar and diary. Most common recurring dates can be specified; if you want something really weird, you can write it as a lisp expression. You can set diary up to remind you of appointments ahead of time. The calendar gives you Gregorian, Julian, ISO, Astronomical, French Revolutionary, Islamic, Hebrew, Persian, Chinese, Coptic, Ethiopic, and two kinds of Mayan dates for any day you wish. -- GeorgePaci, 12.19.10.0.8
- org-mode <http://orgmode.org/>, a mode for keeping notes, maintaining ToDoLists?, and doing project planning. Included in recent gnu-emacs releases.
- Ibuffer - like dired for buffers
- ELPA package manager (since Emacs 24) download and update elisp packages from a buffer interface. Search packages with IncrementalSearch.
- winner-undo - Accidentally hit C-x 1 and deleted your carefully arranged window layout? No problem, just hit C-c left arrow to undo. Put (winner-mode 1) in your .emacs to activate.
- proced - like dired for processes. Works on *nix and Windows
- configurable syntax-aware indenting. Tell Emacs how you want your code indented, rebind RET and never think about it again.
The feature that convinced me to learn Emacs was ^x^m, which runs make, and then the ability to look at all the errors one at a time with ^x^e. I used that feature heavily for years. However, I haven't used C or make for a long time, but I still sometimes use Emacs.
The main thing I like about it now is that I can run it on a dozen different kinds of machines, and I've been using it for nearly 20 years without having to retrain my fingers. I know other editors have advantages, but not worth the time to retrain my fingers.
-- RalphJohnson
What is outline-mode? It's like this:
image never seems to work.
You can specify a RegularExpression that matches outline headings (here I'm using " *>"), and then headings are highlighted, can be automatically folded up (shown as ...), etcetera. Importantly, this is just a plain text buffer displayed in an unusual way: you can ask emacs to display for example LaTeX source in the same way.
Still looking for a (C++) editor that can
- show all comments, hide all comments, hide everything but comments
- collapse functions (maybe outline mode with the regexp set to ^{ or something like that?) What I'd really like is a tree view with a little plus/minus box on the left so I can collapse the functions I don't want to see.
I thought I saw that in VS.NET for C# (but, thank God, I won't be doing C# any time soon.) Can Emacs do that? --
AndrewQueisser
VS.NET's C++ editor can.
Not to my knowledge, i.e. without programming. But if you use a sane indentation convention, the following is often close enough:
C-u 2 C-x $
This hides all lines which don't have anything in column zero or one, which normally has the desired effect of giving you a nice overview of the file. Of course, it's more useful in lisp modes and C++... but you get the idea. C-x $ again to turn it off. The name of the command is set-selective-display.
For python code, C-u 6 C-x $ is a good way to fold method bodies while still being able to read class names and method signatures.
There's something called outl-mouse that works with outl-minor-mode. It provides little arrows that you can click on to hide/expand some section of code.
Folding and narrowing will do this for you - check out this at the EmacsWiki: http://www.emacswiki.org/cgi-bin/wiki.pl?CategoryOutline -- ChanningWalton
Have you looked at speedbar (http://cedet.sourceforge.net/speedbar.shtml)? -- DimiterKurtev
From the above link:
-
- Speedbar is an EmacsLisp program which allows you to create a special skinny frame with a specialized directory listing in it. This listing will have both directories and filtered files in it. You can then load files into your emacs frame, or expand the files to display all the tags that are in them and jump to those tags.
How does a person load the new code for a mode and make the mode available for use?
Say you've grabbed WikiMode, and you've put the file in your home directory:
To load the code manually, just for this session, type:
M-x load-file RETURN ~/emacs-wiki.el
If you always want to do it, put the equivalent line in your .emacs file:
(load-file "~/emacs-wiki.el")
You can always see the
EmacsLisp equivalent of the last thing you did by hitting "C-x ESC ESC". Then you can cut it and paste it wherever you need it.
There are lots of refinements (like auto-load to load things only when you first use them), but that's the basic mechanism.
A useful project could be to outline many of the operations that can be performed in both Emacs and Vim and explain how to do each one in both editors.
Having used both, there are some things I know how to do in one but not the other. Yet, I always hear that anything you can do in one you can do in the other.
I doubt that the above is true. Unless I misunderstand the design of vim, there are many things you can do in emacs that you cannot do in vim (let alone vi). However, the issue is more about the things you want to do in your editor, and I expect that for many people this feature set is similar in both
For programmers working on MacOsx with the newest (December 2002) version of the developer tools, it's possible to use emacs as ProjectBuilder's text editor. BbEdit can also be used. This should please a lot of people who don't like PB's built-in editor... I find it just fine, myself, but I suppose different people need different things from an editor. -- JoeOsborn
Note that this page is a subset of http://purl.org/wiki/emacs/EmacsNiftyTricks. -- ShaeErisson et al
Ripped bleeding from GreatVimFeatures:
These days I use keyboard macros in Emacs, but the problem there is that you have to know before you do something the first time that you will want to do it again, and tell Emacs to start recording. In vi you don't need to know that in advance.
You have just realized, "Hey, that would make a pretty cool keyboard macro". Hit Control-X Control-K, and Emacs will prompt you for a "Keyboard macro to edit". Hit Control-H L. Emacs will present you with a macro editing window filled with your last 100 input keystrokes (the "lossage"). Edit to your heart's content, and hit Control-C Control-C to save.
The only drawback is that mouse actions are not supported, and Emacs will refuse to start the editor. Get around this by editing the "last keyboard macro" (Control-X Control-K Control-X E), viewing the lossage manually (Control-H L) and pasting the lossage into the editing buffer.
(Note: The command is kmacro-edit-lossage and it's on C-x C-k l here)
If there is a series of commands that you want to execute repeatedly and without bothering to remember C-x C-k commands, use <F3>/<F4>. Use <F3> commands... <F4> to push a new macro onto the macro ring, then <F4> to repeat the last created macro as many times as you wish. C-u # <F4> repeats the last macro that many times, and C-u <F4> repeats the second-to-last macro. (If you like, when you're done with a macro, you can delete it with C-x C-k C-d. See C-x C-k C-h for help.) For example, to replace the last 4 characters of the first word of the next 10 lines with "Foo", type <F3> M-m M-f C-u DEL F o o C-n <F4> C-u 9 <F4>.
Hey if you want to bring Emacs keybindings to all your Windows apps, check out the freeware XKeymacs (yes there's a "K" in there). Imagine having a kill ring in Notepad (yes it incredibly gives a kill ring to all your Windows apps). Or using Emacs keys in Mozilla. [Jon Aquino]
TextExtras? is a similar thing for OSX. It plugs into the Cocoa text system to give all kinds of neat features to any Cocoa edit area (completion, Emacs KeyBindings?, autoindent, piping to external commands) http://www.lorax.com/FreeStuff/TextExtras.html
CategoryEmacs