https://wiki.octave.org/wiki/api.php?action=feedcontributions&user=71.198.226.194&feedformat=atomOctave - User contributions [en]2024-03-28T20:11:12ZUser contributionsMediaWiki 1.39.2https://wiki.octave.org/wiki/index.php?title=Vim&diff=3909Vim2014-01-09T02:17:37Z<p>71.198.226.194: edit editor does not work in 3.8.0. EDITOR() function does.</p>
<hr />
<div>[http://www.vim.org/ Vim the editor] is one of the most famous text editors in the hacker programming universe. It has a plenty of extensible (script-based) capabilities and very comfortable shortcuts that makes the programmer the fastest gun of the old west. (I can imagine Vim in front of Emacs on a desert city, Vim's shot is much faster!). In this page you'll learn some tips to better adapt Vim for GNU Octave programming.<br />
<br />
If you aren't familiar with Vim script language, you can also use [http://brainacle.com/how-to-write-vim-plugins-with-python.html Python to write Vim plugins]. If you do some for GNU Octave, please let us know.<br />
<br />
== Vim as the default editor ==<br />
To set Vim as the default editor launched by the GNU Octave {{Codeline|edit}} command, add the following line to your {{Path|~/.octaverc}} file:<br />
<br />
edit mode async<br />
<br />
and one of the following:<br />
<br />
edit editor "<terminal> -e 'vim %s'"<br />
<br />
edit editor "gvim %s"<br />
<br />
where {{Codeline|<terminal>}} can be [http://directory.fsf.org/wiki/Gnome-terminal gnome-terminal], [http://directory.fsf.org/wiki/Xterm xterm], or any other terminal of your preference. Please note the {{Codeline|-e}} option is common to the mentioned terminals, change it if necessary.<br />
<br />
To use Vim as default editor without starting a separate window, add the following lines to your {{Path|~/.octaverc}} file:<br />
<br />
edit mode sync<br />
edit home .<br />
edit editor 'vim > /dev/tty 2>&1 < /dev/tty %s'<br />
<br />
In version 3.8.0, editor option for edit is gone. In stead use the following: <br />
edit mode sync<br />
edit home .<br />
EDITOR('vim > /dev/tty 2>&1 < /dev/tty %s')<br />
<br />
== A better GNU Octave syntax file ==<br />
As for now, Vim hasn't a dedicated, officially distributed filetype for GNU Octave. The community agreed the best solution is to use [http://www.vim.org/scripts/script.php?script_id=3600 octave.vim] by Rik. All the instructions for installing it can be found on the hyperlink.<br />
<br />
== Accessing GNU Octave info ==<br />
GNU Octave info package can be found in almost all Linux distributions. For installing it under Ubuntu, you can type:<br />
<br />
$ sudo apt-get install octave<version>-info<br />
<br />
where {{Codeline|<version>}} must be substituted by the appropriate string. Add the following line to your {{Path|~/.vimrc}} file:<br />
<br />
autocmd FileType matlab setlocal keywordprg=info\ octave\ --vi-keys\ --index-search<br />
<br />
Now, when editing a {{Path|*.m}} file, you can type {{Key|K}} in normal mode and the word under the cursor will be searched for in the GNU Octave documentation index. Pressing {{Key|,}} yields the next occurrence. However, this does not work when using gVim, because gVim has only dumb terminal implemented. When using vim in some not dumb terminal, all works fine.<br />
<br />
'''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}}.<br />
<br />
== Jumping between control statements ==<br />
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:<br />
<br />
set nocompatible<br />
filetype plugin on<br />
runtime macros/matchit.vim<br />
<br />
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]:<br />
<br />
let s:conditionalEnd = '\(([^()]*\)\@!\<end\>\([^()]*)\)\@!'<br />
autocmd FileType octave let b:match_words = '\<if\>\|\<while\>\|\<for\>\|\<switch\>:' .<br />
\ s:conditionalEnd . ',\<if\>:\<elseif\>:\<else\>:' . s:conditionalEnd<br />
<br />
It allows to jump (quasi-)correctly even in the presence of array indexing with {{Codeline|end}}. Place 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.<br />
<br />
Any improvements on the {{Codeline|b:match_words}} variable are welcome.<br />
<br />
[[Category:Editors]]</div>71.198.226.194