emacs tips

Useful Emacs bits 'n' bobs

I've hacked my emacs configuration quite a lot in order to support some major modes that I find particularly useful: (php-mode, html-helper-mode, css-mode and the rather more specialist lhcb-c++-mode in particular.

I've also gone to a fair bit of trouble to set some of the more ubiquitous emacs key combinations to a more "normal" behaviour: I've bound C-a to "select all", use S-[cursor keys] to select regions and have bound Home and End to go to the start and end (respectively) of lines rather than the BOF and EOF. I also use the rather wonderful cua-mode to bring the cut-copy-paste-undo shortcuts in line with the rest of computing, not least because I found myself getting some RSI- like hand pains after repeated use of C-y for pasting! The C-s search binding and C-k kill-line bindings remain intact since I find them really handy. I also recommend the AuCTeX package for advanced LaTeX editing in Emacs, as well as php- elisp, the equivalent functionality for PHP editing.

Here's a few handy key combinations I wish I'd been told about when I started using emacs:

* C-g or ESC ESC ESC: cancel minibrowser session      * C-s: search for text      * C-r: search for text backwards
  • C-%: replace text (press space to okay each suggested instance * C-M-%: replace regex (press space to okay each suggested instance * C-[space]: place mark (I don't use this...see above re. region selection) * C-w: cut region (std emacs) * M-w: copy region (std emacs) * C-k: cut line * C-y: paste (yank) * C-l: recentre buffer window vertically around active line * C-x C-f: open (find) file in buffer * C-x C-s: save buffer to file * C-x C-w: save buffer to new file * C-x C-z: stop (pause) emacs process (re-start with shell fg) * C-x k: kill buffer * C-x b: change active buffer * C-x 1: display only current buffer window * C-x 2: split buffer window * C-x 0: kill current buffer pane * C-x 4 f: open file in new window * C-x 4 b: open buffer in new window * C-x 5 2: open new frame * C-x 5 0: kill current frame * C-x 5 f: open file in new frame * C-x 5 b: open buffer in new frame * C-x o: switch between active sub-window * C-x D: enter the very nifty dired-mode * M-x global-font-lock-mode: toggle syntax highlighting * M-x perl-mode: a lot of code highlights fairly well in Perl mode * M-x goto-line: jump to line * F10: access menus in text mode (via the minibuffer) * M-x byte-compile-file .emacs: compile .emacs or another elisp file for faster operation