Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Last active August 29, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkeepers/b252627ef2c3458f49a7 to your computer and use it in GitHub Desktop.
Save bkeepers/b252627ef2c3458f49a7 to your computer and use it in GitHub Desktop.
Regular expression for vim and emacs modelines.
/
(?:
(-\*- \s* (?:mode:)? \s*) | # $1: Emacs
(\/\* \s* vim: \s* set \s* (?:ft|filetype)=) # $2: Vim
)
(\w+) # $3: language
(?:
(?(1) # If $1 matched...
;?\s* -\*- | # then close Emacs syntax
: \s* \*\/ # otherwise close Vim syntax
)
)
/x
; -*-php-*-
# ; -*- mode: php;-*-
# /* vim: set filetype=perl: */
# /* vim: set ft=perl: */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment