Vim: Difference between revisions

1,465 bytes added ,  11 November 2012
no edit summary
m (moved VIM to Vim: cosmetic reasons)
No edit summary
Line 31: Line 31:


'''OBS:''' If using the Rik's [http://www.vim.org/scripts/script.php?script_id=3600 octave.vim] syntax, replace {{Codeline|matlab}} by {{Codeline|octave}}.
'''OBS:''' If using the Rik's [http://www.vim.org/scripts/script.php?script_id=3600 octave.vim] syntax, replace {{Codeline|matlab}} by {{Codeline|octave}}.
== Jumping between control statements ==
GNU Octave has a richer set of closing tags ({{Codeline|endif}},{{Codeline|endfor}},...) but for compatibility with MATLAB most users avoid them. This sometimes makes the code hard to follow and one possible workaround is to enable the [http://www.vim.org/scripts/script.php?script_id=39 matchit.vim] plugin for jump between matching control statements. Although the plugin is distributed with Vim, it's disabled by default (see {{Codeline|:help matchit-install}}). To enable it, add the following lines to your {{Path|~/.vimrc}} file:
set nocompatible
filetype plugin on
runtime macros/matchit.vim
Now that's enabled, one needs to specify the matching pairs for the GNU Octave language. The less broken solution i've found by [http://vim.1045645.n5.nabble.com/Matchit-and-identical-closing-tags-tt1145032.html#a1145034 Jake Wasserman]:
let s:conditionalEnd = '\(([^()]*\)\@!\<end\>\([^()]*)\)\@!'
autocmd FileType octave let b:match_words = '\<if\>\|\<while\>\|\<for\>\|\<switch\>:' .
        \ s:conditionalEnd . ',\<if\>:\<elseif\>:\<else\>:' . s:conditionalEnd
It allows to jump (quasi-)correctly even in the presence of array indexing with {{Codeline|end}}. Put the cursor on an {{Codeline|if}} keyword for example and press {{Key|%}}, it'll move to the corresponding {{Codeline|elseif}}, {{Codeline|else}}, {{Codeline|end}} keywords.
Any improvements on the {{Codeline|b:match_words}} variable are welcome.
27

edits