Emacs: Friend or Foe?

Frustrated with Emacs? Here's how to wrestle it into submission.
Miscellaneous Customizations

There are several small items that you might want to configure to depart from Emacs' default behavior. I'm going to list the code for these briefly below; none of them involve new concepts other than those discussed above. The comments should describe these customizations adequately.

;; Allow M-j, M-k, M-h, M-l to move cursor,
;; similar to vi.
(global-set-key "\M-j" 'next-line)
(global-set-key "\M-k" 'previous-line)
(global-set-key "\M-h" 'backward-char)
(global-set-key "\M-l" 'forward-char)
;; Commonly used buffer commands, requiring
;; less use of CTRL
;; (For the ergonomically-minded.)
(global-set-key "\C-xf" 'find-file)
(global-set-key "\C-xs" 'save-buffer)
;; Open a line below the current one; as in "o" in vi
(defun my-open-line ()
  (interactive "*")
  (end-of-line nil)
  (insert ?\n))
(global-set-key "\C-o" 'my-open-line)
;; Make the current buffer the only visible one,
;; and recenter it.
(defun my-recenter-frame ()
   (interactive "")
(global-set-key "\C-l 'my-recenter-frame)
;; Save all buffers and kill Emacs, without prompting
(defun my-save-buffers-kill-emacs (arg)
   (interactive "P")
   (save-buffers-kill-emacs t))
(global-set-key "\C-x\C-c" 'my-save-buffers-kill-emacs)
;; Preserve original save-buffers-kill-emacs,
;; in case we don't want
;; to save what we were doing
(global-set-key "\C-x\C-x" 'save-buffers-kill-emacs)
;; Real Programmers don't use backup files
(setq make-backup-files 'nil)
;; But Real Programmers do use RCS. Includes
;; rcsid[] definition in a C source file
(defun my-c-insert-rcsid ()
   (interactive "*")
   (insert "static char rcsid[] = \"@(#)$Header$\";"))
(define-key c-mode-map "\C-c\C-x" 'my-c-insert-rcsid)
;; Finally, prevent next-line command from adding
;; newlines at the
;; end of the document. Instead, ring the bell when
;; at the end of
;; the buffer.
(setq next-line-add-newlines 'nil)

I hope that this whirlwind tour through the world of Emacs customization has been useful, or, at least entertaining. I've found many of the above modifications to be invaluable. Remember the old saying: Have Elisp, will travel.

That being said, it's back to vi for a while.

Getting the Emacs LISP Manual

Matt Welsh (mdw@sunsite.unc.edu) is a programmer at the Cornell University Robotics and Vision Laboratory. He spends his free time homebrewing virtual beer and playing the blues.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks - nice article for an

eyolf's picture

Thanks - nice article for an new emacs convert (from vi...)
A couple of typos in the code for multiple key sequences:

; Various keys for nuking text (global-unset-key "\C-d")
(global-set-key "\C-d g" 'my-nuke-to-end)
(global-set-key "\C-d\C-d" 'my-nuke-line)

which I believe should be:

; Various keys for nuking text
(global-unset-key "\C-d")
(global-set-key "\C-dg" 'my-nuke-to-end)
(global-set-key "\C-d\C-d" 'my-nuke-line)

At least that worked for me.

Compare with this..

ILoveEmacs's picture

Ever tried viper mode?

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState