Emacs has the ability to use abbreviations to save time typing. For example, if I type fn
and then press space or almost any punctuation character, it is automatically expanded to the word function
. This is also great for correcting common typos, like “teh” for “the”.
To make this work the most seamlessly, paste the following lines into your emacs config file, changing the location of your abbreviation file if you want:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; abbreviations ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq-default abbrev-mode t) ;; save abbreviations upon exiting xemacs (setq save-abbrevs t) ;; set the file storing the abbreviations (setq abbrev-file-name "~/docs/my-abbreviations.el") ;; reads the abbreviations file on startup (quietly-read-abbrev-file)
and then highlight the lines and run M-x eval-region
or restart emacs.
Now you can type the abbreviation you want, followed by C-x a -
and you will be prompted for the expanded text. e.g. to set up the abbrevation above, I used
fn C-x a - function
You can set as many of these as you want. You will be asked if you want to save your abbreviations when you exit emacs.
If you type something that you don’t want to be expanded, then follow the abbreviation with C-q
, so typing fn C-q SPACE
will give you the string fn
followed by a space.