VimLab replicates MATLAB's support for code sections in Vim. It uses tmux to maintain a MATLAB session from within vim.
VimLab relies on tmux and screen.vim which are used to set up and communicate
with a MATLAB session. It expects the matlab command to be on your $PATH.
Code analysis, similar to that offered by MATLAB's editor, is provided by the
excellent Syntastic plugin. If mlint is on your path as well, Syntastic will
automatically analyze your MATLAB code when it's saved.
VimLab requires vim to run inside a tmux session. Linux users may find a tmux package is provided by their favorite distribution. For OS X users, I recommend installing tmux using homebrew.
For a well written introduction to tmux, please take a look at the book "tmux: Productive Mouse-Free Development" by Brian P. Hogan.
VimLab uses Screen.vim to manage a MATLAB session within tmux.
Install Syntastic if you wish to have your MATLAB code automatically analyzed when it is saved.
I recommend installing VimLab using Vundle. Add the following lines to your .vimrc file:
Bundle "ervandew/screen"
Bundle "dajero/VimLab"
"Optional, if you desire automatic code analysis
Bundle "scrooloose/syntastic"Next, either quit and relaunch vim or source .vimrc from within your current
vim session. Finally, issue the :BundleInstall command to vim to install
VimLab and its dependencies.
VimLab automatically creates a few key mappings when you enter a MATLAB buffer.
These mappings are prefixed by your leader, which defauls to \. If you set
your mapleader to a different character, please mentally substitute the
backslash by the mapleader of your choice.
\mmstarts matlab\mssends the current section to MATLAB\mdopen the documentation for the current word\mhshow help for the current word\mvshow the variable the cursor is ongngo to the next sectiongNgo to the previous section
\mesend selection to Matlab\mlsend current line to Matlab\mfrun current file\mcclear Matlab screen\mxclose all figures\mqload errors (only if you choose g:matlab_quickfix_list='error'\mbadd break point\mBdelete all break points
VimLab also provides two commands to quickly open the documentation or help for a function:
:MATDoc my-functionopens the documentation for my-function:MATHelp my-functionshows help for my-function
By default, VimLab splits your tmux window horizontally to create a pane for
MATLAB. If instead, you prefer the panes to be arranged vertically, set the
varible g:matlab_vimlab_vertical to 1, e.g. add the following line to your
.vimrc:
let g:matlab_vimlab_vertical=1By default, if you installed Fabrice's Matlab plugin, :make call mlint to generate warns and messages. But if you want to use quickfix list to handle real errors, set g:matlab_quickfix_list to error. Everytime you see errors, press \mq to load them to quickfix list, then you can use cn cp clist etc.
The basic idea is to copy all the lines you want to run in a MatVimTmp.m file in the same folder which uses try..catch to handle errors and saves them in the /tmp/MatlabErrorForVim.err. Then they can be loaded by calling the cfile() vim buildin function. You can set g:delete_tmp_file_after=1, and the MatVimTmp.m will be deleted after you run it.
If you don't want quickfix list to handle errors and don't set 'g:matlab_quickfix_list', the approach will be the original approach. No temporary file will be created. All the lines are just copied to the Matlab command window.