Like you, I have a huge .emacs that I've acquired over the years. Here's what I use to comment out a C region with #if 0: (define-key c-mode-base-map "\C-ci" 'if0-region) ; function to comment a region using #if 0 (defun if0-region (p1 p2) (interactive "r") (let* () (goto-char p1) (beginning-of-line) (insert "#if 0\n") (goto-char (+ p2 +9)) (beginning-of-line) (insert "#endif\n"))) From: Harry Putnam To: help-gnu-emacs@gnu.org Date: 12/02/2010 05:06 PM Subject: Wrap predefined text around region Sent by: help-gnu-emacs-bounces+kgold=watson.ibm.com@gnu.org Can anyone show an example of how to do something like this: I want to wrap this: # [HP 101202_15:55:07 # ] Around the selected text... that is, select some text and press a key combo ... voila... its now surrounded by: # [HP 101202_15:55:07 # ] Over the yrs I've acquired a fairly lengthy .emacs mostly by theft from more skilled people. Coding something like that is clear out of my skill set. I use lots of `skeleton' things for inserting various predefined texts but don't know how to make that happen to selected region. Usually given an example, I've been able to hack it up to my needs.