sponsor Vim development Vim logo Vim Book Ad

octave.vim : Syntax highlighting file for GNU Octave language

 script karma  Rating 290/128, Downloaded by 11859  Comments, bugs, improvements  Vim wiki

created by
Rik ***
script type
This file provides syntax highlighting for the GNU Octave programming language.

* Highlights entire Octave grammar (endwhile, endfor, etc.), not just Matlab keywords
* Updated to highlight all core Octave functions as of version 8.1.0
* Use-dependent highlighting of Octave system variables
   When querying system variables, keyword is highlighted as a constant.  For example, var = true, highlights 'true' as a constant.
   When setting variables or otherwise invoking keyword as a function, keyword is highlighted as a function.  For example, var = true (2,4), highlights 'true' as a function.
* Highlights user functions and anonymous functions [@(...)] from within the .m file being edited
* Support for multi-line strings with line continuation characters as well as escaped quotes (\" or '') within string.
* Support for multi-line block comments
* Support for highlighting numbers that use hex (0x) or binary (0b) syntax
* Error highlighting for bad structure variable names, bad block comments, bad line continuations.
* Optional runtime support for highlighting user variables, operators (+, -, *, etc.), and tabs  

* The syntax file has a list of every valid function in Octave which makes it very useful as an auto-completion dictionary for use with ViM's omnifunc function.  Once installed, type a few letters of the name of a function and then use Ctrl-X Ctrl-O to bring up a list of possible matches.

* Detection of incorrectly formed numbers is incomplete.


For automatic indenting of Octave code see the companion file at vimscript #6056.


This script has been thoroughly rewritten and expanded.

This original script owes some debt to the two existing Octave syntax scripts:
install details
Syntax file install on a UNIX-like system

1) mkdir -p ~/.vim/syntax
2) cp octave.vim ~/.vim/syntax/
3) Add the following lines to your ~/.vimrc to have ViM use the file

----- SNIP -----
" Octave filetype detection
augroup filetypedetect
  au! BufRead,BufNewFile *.m set filetype=octave
augroup END
----- SNIP -----

Optional highlighting is controlled by three configuration variables:

"octave_highlight_variables" : highlight user variables.  For example, "y" and "x" in the code "y = cos (x)"
"octave_highlight_operators" : highlight logical (&,|,!,~), arithmetic (+,-,*,/,\,^), and relational (<,<=,>,>=,!=,~=) operators
"octave_highlight_tabs" : highlight tabs (\t)

To enable one of the optional highlighting classes use the following command in a buffer or in your .vimrc file for permanent behavior

----- SNIP -----
let octave_highlight_XXXX=1
----- SNIP -----

and to disable optional highlighting use

----- SNIP -----
unlet octave_highlight_XXXX
----- SNIP -----

OMNIFUNC install on a UNIX-like system

1) Install the syntax file as described above
2) Add the following lines to your ~/.vimrc after the snippet from step 3 above
----- SNIP -----
" Use keywords from Octave syntax language file for autocomplete
if has("autocmd") && exists("+omnifunc")
   autocmd Filetype octave
   \ if &omnifunc == "" |
   \ setlocal omnifunc=syntaxcomplete#Complete |
   \ endif
----- SNIP -----

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
octave.vim 8.1.0 2023-03-28 7.0 Rik *** Syntax matched to Octave Release: 8.1.0
Underscores now supported in numbers for readability (e.g., 1_000).
Class signifiers (u8,u16,u32,u64,s8,s16,s32,s64) for binary and hex numbers.
Fortran exponeniation operator (\"**\") is now an error.
Backslash line continuations in single-quoted strings are now an error.
Backslash line continuations for ordinary code are now an error.
Trailing text on the first line of a block comment is now an error.
Support for Vim < 5.7 has been removed.
octave.vim 6.3.0 2021-09-22 5.7 Rik *** Syntax matched to Octave Release 6.3.0
Add runtime configuration variables octave_highlight_operators, octave_highlight_variables, octave_highlight_tabs.
Fix highlighting of classdef keywords which are also functions.
Fix highlighting of complex numbers with capital I,J.
Fix highlighting of user variables, particularly structs.
Fix highlighting of run-away strings and strings with line continuations
Avoid changing vim variable "iskeyword" and regexp matching for local buffer.
Completely overhauled strategy for highlighting
Performance improvements in regular expressions
octave.vim.4.2.0 4.2.0 2016-11-14 5.7 Rik *** Updated to include syntax highlighting for all functions in 4.2.0.
Highlights numbers that use new syntax for hex (0x) and binary (0b).
Classdef keywords now automatically indent/exdent when used in code.
octave.vim 3.8.3 2014-09-18 5.7 Rik *** Correctly highlight cell arrays that use a transpose operator
octave.vim 3.8.0 2014-01-10 6.0 Rik *** Updated function list to match 3.8.0 release of Octave
Correct coloring problem with escaped double quotes within double-quoted string
octave.vim 3.6.0b 2012-01-30 5.7 Rik *** Correctly highlight functions like strcmp which use '=' within quotes rather than assignment
octave.vim 3.6.0 2012-01-23 5.7 Rik *** Update with list of 3.6.0 functions.  Now highlights keywords varargin, varargout, parfor.
octave.vim 3.4.3 2011-10-12 5.7 Rik *** Updated for 3.4.3
Spellchecking in Vim, if used, is now restricted to string literals and comments which reduces screen clutter.
octave.vim 3.4.2 2011-08-03 5.7 Rik *** Updated with 3.4.2 function list
octave.vim 3.4.0c 2011-06-08 5.7 Rik *** Now highlights anonymous functions.
Commands integrated into use-dependent highlighting.
Better recognition of keyword on LHS of '=' to stop highlighting user variables
octave.vim 3.4.0b 2011-05-31 5.7 Rik *** Correct occasional non-highlighting of nested () within function calls
octave.vim 3.4.0 2011-05-24 5.7 Rik *** 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.
Vim at Github