Skip to content
A vim plugin for easy interaction between matlab and vim
Vim script MATLAB Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ftplugin backup May 4, 2019
indent IsMatlabLineContinuation no longer s:function; used for continuing li… Dec 16, 2018
syntax
.gitignore big organisation Oct 27, 2018
LICENSE
README.md update readme to remove slime and add a couple more bindings Dec 16, 2018
op.m op: don't open when no word under cursor. Keybinds: run script will f… Feb 28, 2019

README.md

vimlab

This is a collection of code sourced from a few places, modified, expanded and put in one place for my own use.

It is my attempt at making vim and matlab work together as painlessly as possible. Some things are still a work in progress.

Features

  • Fabrice Guy's syntax highlighting, matchit pairing of for/end, if/end etc, and indentation rules.
  • Hitting enter in vim on a word to open it in the variable editor or in vim, if it is a variable or m file.
  • Matlab's own keybindings for running code lines, sections, selection, script etc, using tide
  • Debugging keybindings, including setting and clearing markers and navigating the function stack
  • Automatic session saving like in matlab
  • Automatic/on demand code checking and error highlighting with Thomas Ibbotson's mlint.vim
  • A shell script to find .m files in specified local directories and add them to the list of functions for syntax highlighting

Usage

vim

Most of the cool stuff requires vim be run in server mode. To run a vim server that can use all the functions here, including automatic session restoration, open it with:

vim --servername vimlab

Session restoration

To enable session saving and restoration, add this to your .vimrc:

let g:vimlab_session = "~/.cache/vim/sessions/matlab-session.vim"

changing the path to where you keep vim sessions, and open vim with:

vim --servername vimlab -S $HOME/.cache/vim/sessions/matlab-session.vim

You can change the default binding to save and exit (which is XA in normal mode):

nnoremap XA <Plug>VimlabEndSession

Opening variables, functions or scripts from vim*

Hitting enter when the cursor is on a word will either:

  1. open it in the variable editor if it is a variable, or
  2. open it in the vim server if it is a script or function and on matlabs path.

This requires the included op.m function be on matlab's path.

The default bindings are to open the word in the vim server and to open it in a new window, if the word points to an .m file. The vim server name and terminal can be changed from the default "vimlab" and urxvtc with:

let g:vimlab_server = "vimserver"
let G:vimlab_terminal = "xterm"

Debugging*

Key Function
\a add a debug marker at the current line (this saves the buffer)
\r remove the marker at the current line
\t toggle the marker at the current line
\s or F10 step to the next line in debug mode
\c or F5 continue running the code
\e toggle stopping to debug at errors
\x exit debug mode
\f flush all markers
\ds list the debug stack
\du go up the stack
\dd go down the stack

These keybindings assume the leader key is the default backslash.

Code checking

This plugin contains Thomas Ibbotson's mlint.vim. If mlint isn't on your system's $PATH, you can set the path by putting this in your .vimrc:

let g:mlint_path_to_mlint = "$HOME/applications/MATLAB/R2018b/bin/glnxa64/mlint"

This will automatically run mlint when the cursor is idle, but this can be disabled by setting this variable to anything:

let g:mlint_hover = 1

Auto linting can be toggled with the ToggleLine command, which is bound by default to

Key Function
\ll run mlint manually
| toggle automatic mlint aucommands
\lm see the message from the current line
\lo view an outline of all messages
\ln jump to the next message
\lp jump to the previous message

Auto close of for, if, switch statements

For, if, and switch statements will automatically get an end placed below them on the next empty line. So if there is a code block on the next line, the statement will surround it. To disable this altogether, set the variable g:vimlab_no_autoend

Misc

For matchit word pairing of things such as if/end, allowing the use of % to navigate these pairs, add the following to your .vimrc:

packadd! matchit

Other plugins that go well with this

  • vim-bbye works well to quickly close buffers opened by op.m (bind to backspace!)
  • The matlab editor autohighlights variables under the cursor. This can be replicated with this vimscript.
You can’t perform that action at this time.