sponsor Vim development Vim logo Vim Book Ad

MatlabFilesEdition : A set of files useful to edit Matlab files (indent, syntax,tags , mlint use...)

 script karma  Rating 73/37, Downloaded by 4061  Comments, bugs, improvements  Vim wiki

created by
Fabrice Guy
script type
Contains a set of files useful to edit Matlab files.

Included is :
1) Syntax highlighting
2) Correct setting to use the matchit.vim script (extension of the % command to match if/end, for/end,... blocks)
3) Correct indentation
4) Integration of mlint (Matlab code checker) with the :make command
5)Tag support
6) Help file

1) Syntax highlighting

syntax/matlab.vim : Updates the matlab.vim syntax file provided in the vim distribution :
- highlights keywords dealing with exceptions : try / catch / rethrow
- highlights keywords dealing with class definitions : classdef / properties / methods / events
- highlights most Matlab functions

2) Correct settings in order to use the matchit.vim script

The matchit.vim extends the % matching and enables to jump through matching groups such as "if/end" or "swicth/end" blocks (see :help matchit in vim)

ftplugin/matlab.m provides the suitable definition for b:match_words in order to jump between if/end, classdef/end, methods/end, events/end, properties/end, while/end, for/end, switch/end, try/end, function/end blocks

3) Correct indentation
indent/matlab.vim : Updates the matlab.vim indention file provided in the vim distribution.
This script provides a correct indentation for :
- switch / end, try / catch blocks
- classdef / methods / properties / events
- mutli-line (lines with line continuation operator (...))

This script has been tested with the Matlab R2008a release on many files and the result of indentation compared to the one provided by the Matlab Editor (with 'indent all functions' option set)

NOTE : to work correctly, this script need the matchit.vim (vimscript#39) to be installed.

4) Integration of mlint (Matlab code checker) with the :make command

compiler/mlint.m provides the settings to use mlint (Matlab code ckecker) and puts the messages reported in the quickfix buffer.

Whenever you want to check your code, just type :make and then :copen and vim opens a quickfix buffer which enables to jump to errors (using :cn, :cp or Enter to jump to the error under the cursor : see :help quickfix in vim)

5)Tag support
The .ctags file (in the matlab.tar.gz) defines the Matlab language so that the exuberant ctags (http://ctags.sourceforge.net ) can construct the tag file : you can now jump to tags (using CTRL-] (or CTRL-$ if using Windows) and go back again (CTRL-T)
See also :help tags in vim.

These scipts have been tested using gvim 7.2 and Matlab R2008a on Windows.

install details
The package is matlab.zip : just unzip it to extract the files.

1) Syntax highlighting
Copy syntax/matlab.vim to your $HOME/vimfiles/syntax directory

2) Correct settings in order to use the matchit.vim script
In your vimrc file, add the following line :
source $VIMRUNTIME/macros/matchit.vim

And copy ftplugin/matlab.vim to your $HOME/vimfiles/ftplugin directory

3) Correct indentation
In your vimrc file, add the following line :
source $VIMRUNTIME/macros/matchit.vim

And copy indent/matlab.vim to your $HOME/vimfiles/indent directory

4) Integration of the mlint Matlab code checker with the :make command

Add the following line to your vimrc file :
autocmd BufEnter *.m    compiler mlint

And copy compiler/mlint.vim to your $HOME/vimfiles/compiler directory

5)Tag support
Copy the .ctags to your $HOME directory.
And then run the command to create tour tags file : for example :
ctags -R *

6) help file
Copy doc/matlab.txt to your $HOME/vimfiles/doc directory
And then run the command to create help for matlab :
:helptags $HOME/vimfiles/doc

And then the command
:help matlab
is available.


rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
matlab.zip 1.1 2009-11-23 7.0 Fabrice Guy - Added support for indentation of if/end blocks on the same line (and while/end, for/end,... blocks)
- Changes in functions indentation : the behavior of the indentation is now the same as the 'indent all function' option in the Matlab Editor,
- Insertion of comment line now inserts a comment header (%) at the beginning of a new comment
matlab.zip 1.1 2008-10-28 7.0 Fabrice Guy Enhanced syntax highligting for Matlab m-files : most Matlab builtin functions are now highlighted
matlab.zip 1.0.2 2008-10-24 7.0 Fabrice Guy Wrong indentation of subfunctions without matching 'end' has been fixed
matlab.zip 1.0.1 2008-10-21 7.0 Fabrice Guy As pointed out by Tobias Wolf :
- renamed the package to .zip
- replaced the DOS endings by CR line endings

Added a help file (matlab.txt)
matlab.tar.gz 1.0 2008-10-17 7.0 Fabrice Guy Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.