Syntax highlight a vimrc file in Emacs?

There is a great package for this: https://github.com/mcandre/vimrc-mode

Install by M-x package-install vimrc-mode.

It highlights vimrc files with amazing syntax highlighting automatically when they are opened, or you can invoke it manually via (vimrc-mode).


Googling does turn up wenbinye's vimrc-mode, a very lightweight generic mode. Here's what I have in my .emacs:

(define-generic-mode 'vimrc-generic-mode
    '()
    '()
    '(("^[\t ]*:?\\(!\\|ab\\|map\\|unmap\\)[^\r\n\"]*\"[^\r\n\"]*\\(\"[^\r\n\"]*\"[^\r\n\"]*\\)*$"
       (0 font-lock-warning-face))
      ("\\(^\\|[\t ]\\)\\(\".*\\)$"
      (2 font-lock-comment-face))
      ("\"\\([^\n\r\"\\]\\|\\.\\)*\""
       (0 font-lock-string-face)))
    '("/vimrc\\'" "\\.vim\\(rc\\)?\\'")
    '((lambda ()
        (modify-syntax-entry ?\" ".")))
    "Generic mode for Vim configuration files.")

Tags:

Emacs