3

I'm still very new to vim but I've noticed that files with -*- mode: {lang} -*- as the first or second line turn on the syntax highlighting for that language. It's tough searching for -*- when Google ignores punctuation but after a couple hours, I was able to find out what it's called in emacs. (Major-modes)

So far it's worked great when using mode:python on python files without .py but I can't seem to get mode:javascript working for javascript files without a .js extension. I've searched the vim docs but was unable to find a way to embed the syntax mode in a file like the major-mode does for emacs.

I was able to find this post about setting an override in the .vimrc but I'd like the highlighting to stay with the file and not rely on my .vimrc.

Any help is appreciated. Thanks!

Community
  • 1
  • 1
Rob Tomson
  • 33
  • 2

3 Answers3

3

It's called modeline. See :help modeline for details.

mike3996
  • 17,047
  • 9
  • 64
  • 80
1

If the files you're working in already have emacs major-mode lines, then you could try the emacsmodeline vim plugin to parse those lines instead of adding your own modelines.

idbrii
  • 10,975
  • 5
  • 66
  • 107
0

What you are looking for is called in modeline in vim-land.

To e.g. set python-mode for a file, add a line

# vi:filetype=python

to your files. You can do much more, see

:help modeline

in vim.

Benjamin Bannier
  • 55,163
  • 11
  • 60
  • 80