A vim plugin that emulates all of the powerful IDE features of MATLAB in vim so you don't need to run the full GUI.
git clone https://mcol.xyz/code/vimlab
Log | Files | Refs | README | LICENSE

commit 9a8147a0d5c353adcfffeabd1f90d5ab2cc52542
parent 6ec5f76d8bb95545ff3b3cfefe4c91fd66c54ea1
Author: mcol <mcol@posteo.net>
Date:   Sun, 28 Oct 2018 09:31:10 +0000

cleaned up ftplugin file

Diffstat:
Mftplugin/matlab.vim | 77+++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 41 insertions(+), 36 deletions(-)

diff --git a/ftplugin/matlab.vim b/ftplugin/matlab.vim @@ -1,7 +1,7 @@ -" Vim filetype plugin file -" Language: matlab -" Maintainer: Fabrice Guy <fabrice.guy at gmail dot com> -" Last Changed: 2010 May 19 +"------------------------------------------------------------------ +" m-file filetype settings +"------------------------------------------------------------------ +" Credit to this section goes to Fabrice Guy if exists("b:did_ftplugin") finish @@ -34,11 +34,8 @@ let b:undo_ftplugin = "setlocal suffixesadd< suffixes< " let &cpo = s:save_cpo - - - "------------------------------------------------------------------ -" mlint code checking +" mlint code checking keybindings "------------------------------------------------------------------ " mlint is symlinked into $PATH from <MATLABROOT>/bin/<ARCH> " mlint.vim from vim-matlab appears to not get sourced automatically @@ -56,30 +53,14 @@ nnoremap <Leader>cp :cp<CR> "------------------------------------------------------------------ -" Folding (vim-matlab-behave i think) +" Section folding "------------------------------------------------------------------ -" make section title bold -highlight MATCELL cterm=bold term=bold gui=bold -match MATCELL /^%%[^%]*$/ - -" enable matlab section folding -function! MatlabFolds() - let thisline = getline(v:lnum) - if match(thisline,'^[\ ]*%%') >=0 - return ">1" - else - return "=" - endif -endfunction -setlocal foldmethod=expr -setlocal foldexpr=MatlabFolds() - - -autocmd BufWinLeave *.m mkview " remember folding layout +" remember folding layout +autocmd BufWinLeave *.m mkview autocmd BufWinEnter *.m silent loadview - +" format folded section header text function! MyFoldText() " {{{ let line = getline(v:foldstart) @@ -98,6 +79,24 @@ endfunction " }}} set foldtext=MyFoldText() +" These next two pieces are from ebranlard/vim-matlab-behave +" make section title bold +highlight MATCELL cterm=bold term=bold gui=bold +match MATCELL /^%%[^%]*$/ + +" enable matlab section folding +function! MatlabFolds() + let thisline = getline(v:lnum) + if match(thisline,'^[\ ]*%%') >=0 + return ">1" + else + return "=" + endif +endfunction +setlocal foldmethod=expr +setlocal foldexpr=MatlabFolds() + + "------------------------------------------------------------------ " vim-slime configuration git://github.com/jpalardy/vim-slime.git "------------------------------------------------------------------ @@ -106,11 +105,17 @@ let g:slime_dont_ask_default = 1 let g:slime_default_config = {"socket_name": "default", "target_pane": "1"} let g:slime_paste_file = "/tmp/slime_paste" + " open word under cursor using op.m function -" this opens variables in the variable editor, or text files in vim. The second argument -" (i.e. 'vimlab') makes the file open in the vim server with that name -nnoremap <silent> <CR> yiw:SlimeSend1 op <C-r>" 'vimlab'<CR> -nnoremap <silent> <Leader><CR> yiw:SlimeSend1 op <C-r>"<CR> +" if g:op_cmd_terminal is set to something else (e.g. "xterm"), then this +" sends that as an additional arg to op.m +if !exists("g:op_cmd_terminal") + nnoremap <silent> <CR> yiw:SlimeSend1 op <C-r>" vimlab<CR> + nnoremap <silent> <Leader><CR> yiw:SlimeSend1 op <C-r>"<CR> +else + exec "nnoremap <silent> <CR> yiw:SlimeSend1 op <C-r>\" vimlab " . g:op_cmd_terminal . "<CR>" + exec "nnoremap <silent> <Leader><CR> yiw:SlimeSend1 op <C-r>\" '' " . g:op_cmd_terminal . "<CR>" +endif """ Running code @@ -134,7 +139,7 @@ map <silent> <F2> <Esc>:let @" = expand("%")<CR>:SlimeSend1 <C-r>"<CR> nnoremap <silent> <C-w> :SlimeSend1 who<CR> -""" Debugging todo: make set and clear a toggle (and add F12 to this for normal matlab behaviour) +""" Debugging " (a)dd nnoremap <silent> <Leader>a :let @" = "dbstop in " . expand("%") . " at " . line(".")<CR>:SlimeSend1 <C-r>"<CR>:call matchaddpos('WildMenu', [line('.')], 10, line('.'))<CR> @@ -172,9 +177,9 @@ nnoremap <silent> <Leader>dd :SlimeSend1 dbdown<CR> inoremap # % " add shortcuts to write chunks of code -inoremap for<space> for<space><Esc>ms/^$<CR>iend<Esc>`s<CR>=ipA -inoremap if<space> if<space><CR>end<Esc>kA -inoremap switch<space> switch<space><CR>case<CR>end<Esc>kkA +"inoremap for<space> for<space><Esc>ms/^$<CR>iend<Esc>`s<CR>=ipA +"inoremap if<space> if<space><CR>end<Esc>kA +"inoremap switch<space> switch<space><CR>case<CR>end<Esc>kkA " echo synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name") " the line above will tell you if the cursor is in a comment