qazwsx
qazwsx

Reputation: 26898

How to properly enable syntax highlighting for Mathematica in Vim?

How to properly enable syntax highlighting for Mathematica in Vim? I want it automatically on when opening .m files with Vim too.

Upvotes: 3

Views: 1403

Answers (3)

Conner
Conner

Reputation: 31060

Place this in your ~/.vim/syntax folder, then put

au BufRead,BufNewFile *.m setl ft=mma

in your ~/.vimrc.

Upvotes: 4

kev
kev

Reputation: 161674

You can install a custom syntax file in two steps:

Create ~/.vim/syntax/mma.vim:

# create directory(if not exist)
mkdir ~/.vim/syntax
cd ~/.vim/syntax

# download syntax file
wget https://github.com/vim-scripts/Mathematica-Syntax-File/raw/master/syntax/mma.vim

Create ~/.vim/filetype.vim:

" my filetype file
if exists("did_load_filetypes")
  finish
endif
augroup filetypedetect
  au! BufRead,BufNewFile *.m,*.nb       setfiletype mma
augroup END

Note: In Windows, change ~/.vim to C:\program files\vim\vimfiles

Upvotes: 1

John Riselvato
John Riselvato

Reputation: 12904

There is a syntax file for this, which you'll need to install.

http://vim.sourceforge.net/scripts/script.php?script_id=1273

install details

Install instructions are also in the file.

Basically:

  • Drop mma.vim into $HOME/.vim/syntax/ (%HOME%\vimfiles\syntax\ for Windows)

  • Open a Mathematica file**

Upvotes: 2

Related Questions