A Fast Open for init.el

Like me, Bozhidar Batsov is always fiddling with his init.el file. As a result, he's devised a way to open it quickly. He wrote a bit of Elisp to load it and bound the Elisp to the simple key sequence 【Ctrl+c I】. That's a pretty nice solution and one that Irreal readers might expect me to adopt.

I, however, have a different strategy. I have 4 or 5 files that I use all the time. I have them bookmarked so I can load them easily but I don't need to do that very often because I just keep them loaded. I use desktop-save-mode so they stay loaded even across Emacs invocations. Then when I want to examine, say, init.el it's just a matter of 【Ctrl+x bin or maybe just 【Ctrl+x bi depending on what ido has in its cache at the moment. That's not as fast as Batsov's 【Ctrl+c I】 but it's fast enough1.

One of the commenters to Batsov's post suggests using the bookmark facility with a label of, say, i for init.el. Then you can open init.el with 【Ctrl+x r b i】. That gives us at least 3 ways of solving the problem, which is really the point. With Emacs you can solve problems in a way that's comfortable for you. How do you solve the problem of opening frequently accessed files?


1 Basov's solution opens init.el in another window so his solution is faster still if you have that requirement. If I needed that, I'd use 【Ctrl+x 2】 first. If I always wanted a separate window, I'd probably adopt Batsov's solution.

This entry was posted in General and tagged . Bookmark the permalink.
  • CJ

    Regarding using separate windows, very early on in my Emacs days I set:

    (global-set-key (kbd "M-0") 'delete-window)
    (global-set-key (kbd "M-1") 'delete-other-windows)
    (global-set-key (kbd "M-2") 'split-window-vertically)
    (global-set-key (kbd "M-3") 'split-window-horizontally)

    • jcs

      For some reason I didn't get notified when you posted and I just now noticed your comment. Sorry for keeping you languishing in the moderation queue.

  • Phil

    For the longest time I've used a couple of custom functions for reloading and visiting my init file, with the following aliases defined, so that to visit my init file I type M-x lll RET

    (defalias 'll 'load-dot-emacs)
    (defalias 'lll 'find-dot-emacs)

    I don't think I've used the 'load' variant in years. It wouldn't do much in any case -- nowadays my init.el mostly just requires other files -- but in any case I would now tend to evaluate individual functions or regions rather than reload the whole file.

    I'm not even sure why I did it this way. Perhaps at the time I decided that it was something I wouldn't want to waste a key-binding on, but would still do regularly enough to not want to type the whole function name? It's pretty quick to type in any case, so I've never been inclined to change it.

    In a sense, short command names like this almost turn M-x into another prefix keybinding. It's probably safe to assume that very short names won't be clobbered. Probably. I also use aliases for a small number of other commands (dw for delete-trailing-whitespace, ws for whitespace-mode, nm for normal-mode).

  • I have similar approach but my keys are bound to F1 key map. e.g. I have ek to open key binding .el file and ow to open org mode wiki. See more at: https://github.com/exu/emacs.d/blob/master/autoload/keys.el#L43-L63