Emacs-fu Emacs Tips
Emacs-fu started a great post requesting little tricks. I gave my own response, covering cut-and-paste, ido mode, uniquify and tidy backups. Da Zhang has a nice summary of some of the other tips.
Using/Extending Core Libraries
There are a few emacs libraries that store current state in global variables. For example, ido stores the list of current matches in ido-matches. Accessing this variable while filtering using ido can be a little convoluted. I gave an example of how to do this in Shell Command on Multiple Buffers.
Dabbrev also uses global variables although it provides [internal] functions for completing an abbreviation. I have a complete example at Autocomplete with a Dabbrev Twist but the core is very simple:
(let ((dabbrev-check-all-buffers t))
(dabbrev--reset-global-variables)
(dabbrev--find-all-expansions <abbreviation> t))
Multi-file Search/Replace
I really liked this post from Ian Eure demonstrating how to do multi-file search and replace in emacs. I frequently see emacs proponents saying its awesome and you’ll know when you reach emacs nirvana so it is nice to see a practical demonstration of emacs power. And of course I know it is possible in shell but the simplicity and the interactive nature of emacs makes this a much more pleasant experience. A quick summary:
M-x find-grep-dired RET <pattern>(put matching files in dired buffer)m .php$ RET(mark all php files)Q <pattern> RET <replace string>(run query-replace on marked files)C-x s(save all modified files)
Emacs Popularity
So first of all I found this post referring to a thread where a guy says he recommends nano as he has used Unix-like systems that don’t have vi. Hmmm… okay, and then that post has this one from 2007 in the auto-generated links list about Emacs losing in popularity.
And from there I get to this one which has a poll where 56% of the almost 750 respondants chose vim1 as their favourite Linux text editor compared to 9% choosing emacs. Of course it is a highly unscientific result, but do you think more than 6 times as many people use vim as emacs?
1. Fair enough – it is a fine editor
This isn’t scientific either, but libre.fm groups for Emacs and ViM both count 12 members.
http://alpha.libre.fm/group/emacs
http://alpha.libre.fm/group/vim
Six to one sounds a little high, but I wouldn’t be surprised. The rough breakdown where I work is vi over Emacs 2.5:1. This is for developers only, and is probably incomplete and inaccurate. It could easily be as low as 2:1 or as high as 3:1.
The non-Emacs to Emacs ratio is 9:1. This is made up of jEdit, TextMate, Eclipse, Coda, and probably a few other oddballs.
There are a couple non developers (operations guys) who use Emacs as well, but I stuck to coders since I have a better idea of who uses what.
Of course, being and advocate for Emacs, I’ve tried to get people to consider it, but few have. They’re either unwilling to take the productivity hit while they adapt, or are put off by the complexity.
Hi P4bl0 – I was unable to access the alpha.libre.fm website. Isn’t it something to do with radio stations in which case how are there emacs or vim groups?
Within my team of 10 the ratio is 2 to 1 in favour of Vim but one of the Emacs users is a convert
Emacs vs. Vim is so… boring.
A majority of people whom I have talked to about their editor preference say they choose vi/vim because it is likely installed on any given *nix system. This is especially good for sysadmins, who typically would need to edit config files, on a variety of machines. Great, it works for them.
Get stuff done with emacs, don’t bother trying to convert people. If you want emacs to become the most popular linux editor, why not see about integrating it with linux better? Maybe the modes for editing config files could be made better? Maybe it could be hooked into a typical sysadmins workflow better? Maybe there needs to be a better tutorial on how to use TRAMP? Food for thought.
I once tried to persuade my colleague to use emacs with latex, but when I installed emacs and my set of configuration on her laptop, she seemed to be scared and urged me to delete them off…… I thought I acted so much like a weird geek.
I’m surprised that that many programmers would use vi(m) in this day and age. I would have thought that for the generation that has come to expect IDEs, vi(m) looks at least as frightening as Emacs.
I don’t think Nano is ‘a fine editor’. It’s one of those that do an evil half-arsed imitation of Emacs keybindings. Some of the very elementary ones work, but e.g. C-k works in a different way, which causes endless problems for Emacs users, word wrapping is all wrong, search is unfathomable for an Emacs user etc. If you want a minimal editor with an Emacs-like interface, use zile. Nano is for people who were conditioned on Pine/Pico.
Emacs could probably improve its chances quite a bit by improving the most offensive parts of the UI. I’m not talking about keybindings, but e.g. better integration with the toolkit (Gtk on Linux/Unix), revamp Customize. Fortunately font rendering is finally there with Emacs 23.
I just discovered multi-file search/replace after having it in mind that it must be possible for ages. I updated EmacsWiki to reflect a couple of other options for marking files: http://www.emacswiki.org/emacs/DiredSearchAndReplace
@Jonathan
> Emacs vs. Vim is so… boring.
Well, maybe, but I wasn’t actually comparing them in an emacs is better than vim sense. I was comparing their popularity which I find interesting. I guess others find it interesting too.
> (paraphrasing) – people use vim because it is installed everywhere
Okay, that is interesting information, but there is nothing I can do about it at my firm – emacs is already available on all servers.
> Get stuff done with emacs, don’t bother trying to convert people.
Why not? If people in my team are solving problems using the emacs framework that otherwise I would have to solve, that is good for me.
> Maybe it could be hooked into a typical sysadmins workflow better?
> Maybe there needs to be a better tutorial on how to use TRAMP?
Er, possibly. But I’m not a sysadmin and I don’t know any. So it is difficult for me to empathise with them and think about the problems they need to solve. I suspect it is a better use of my time to try and make it better for programmers.
@zhangda – it is a good start at least
I got my mother to use emacs + org-mode with cua-mode but I don’t think she still uses it. Maybe it is worth going through a few other standard bindings and fixing them up as per my previous post
@Mike – I’m not surprised that many people use vim – it is always available as Jonathan points out above and it’s not that bad really. Vim wizards are almost as quick at basic editing tasks as emacs wizards
I haven’t any experience of nano but I’m surprised there are Unix-like systems with nano and without some sort of vi-a-like.
And I completely agree about the new font engine. Emacs 23 is finally an absolute pleasure to use. Previously my experience was slightly marred by the ugly fonts.
@James – nice summary, thanks for adding it to the wiki.
> I haven’t any experience of nano but I’m surprised there are Unix-like systems with nano and without some sort of vi-a-like.
Nano is a Free reimplementation of Pico, the editor for the Pine email program. Nano is installed in the default package set of Fedora and Ubuntu, and notably it’s in their live cd systems, and probably other live cds as well. Emacs is apparently deemed too large for these. Vi is there and Nano is the consolation prize for people who prefer Emacs keybindings (which Nano does not support very well). I often end up doing rescue and systems administration work using live cds and, as an Emacs user, always curse Nano.
Yes, I do recognise Nano from my brief look at Pine (I was more of an Elm man). But it doesn’t even support C-u correctly. Or M-f or M-b. I think I’ll stick to vi for when emacs is not available.