Skip to content

Instantly share code, notes, and snippets.

@maio
Created June 3, 2012 09:58
Show Gist options
  • Save maio/2862867 to your computer and use it in GitHub Desktop.
Save maio/2862867 to your computer and use it in GitHub Desktop.
Smart semi-colon in Emacs (and Vim)
;; Port of Coderush's smart semi-colon feature to Emacs
;;
;; When I hit semi-colon anywhere, Emacs will move cursor to the end of current
;; line and insert semi-colon (if it's not already there).
;;
;; Idea from last @CoderetreatCZ - HK
(defun maio/electric-semicolon ()
(interactive)
(end-of-line)
(when (not (looking-back ";"))
(insert ";")))
(define-key cperl-mode-map ";" 'maio/electric-semicolon)
(define-key php-mode-map ";" 'maio/electric-semicolon)
;; or key-chord
(key-chord-define cperl-mode-map ";;" 'maio/electric-semicolon)
...
;; Vim version (that doesn't check if ; is already there) - ~/.vim/ftplugin/perl.vim
inoremap ; <ESC>A;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment