Vim: Difference between revisions

Jump to navigation Jump to search
1,437 bytes added ,  30 August 2017
added info about terminal emulators for octave info
No edit summary
(added info about terminal emulators for octave info)
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[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.
[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.


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 now.
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.


== Vim as the default editor ==
== Vim as the default editor ==
Line 15: Line 15:


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.
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.
To use Vim as default editor without starting a separate window, add the following lines to your {{Path|~/.octaverc}} file:
edit mode sync
edit home .
edit editor 'vim > /dev/tty 2>&1 < /dev/tty %s'
In version 3.8.0, editor option for edit is gone. In stead use the following: 
edit mode sync
edit home .
EDITOR('vim > /dev/tty 2>&1 < /dev/tty %s')


== A better GNU Octave syntax file ==
== A better GNU Octave syntax file ==
Line 29: Line 40:


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.
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.
Unfortunately info does not work in dumb terminals. As gVim has only dumb terminal, a workaround must be done to access info. Two methods are possible. First one is to use some plugin, like [https://github.com/carlobaldassi/ConqueTerm ConqueTerm], which turn gVim buffer into terminal emulator.
Second method is to select an external terminal emulator, preferably fast loading one, as xterm, and install it. For installing it under Ubuntu, you can type:
$ sudo apt-get install xterm
Add the following line to your {{Path|~/.vimrc}} file:
autocmd FileType octave setlocal keywordprg=xterm\ -e\ info\ octave\ --vi-keys\ --index-search
Now you can type {{Key|K}} in normal mode and a new terminal window will opened and the word under the cursor will be searched for in the GNU Octave documentation index. You can set bigger font and specific window geometry of xterm by following line:
autocmd FileType octave setlocal keywordprg=xterm\ -fa\ 'DejaVu\ Sans\ Mono:style=Book'\ -fs\ 12\ -geometry\ 80x50\ -e\ info\ octave\ --vi-keys\ --index-search


'''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}}.
Line 45: Line 69:
         \ s:conditionalEnd . ',\<if\>:\<elseif\>:\<else\>:' . s:conditionalEnd
         \ 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.
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.


Any improvements on the {{Codeline|b:match_words}} variable are welcome.
Any improvements on the {{Codeline|b:match_words}} variable are welcome.
[[Category:Editors]]
5

edits

Navigation menu