Vim: Difference between revisions

298 bytes added ,  2 April 2023
m
m (Add missing word to sentence.)
 
(6 intermediate revisions by the same user not shown)
Line 4: Line 4:


== Vim as the default editor ==
== Vim as the default editor ==
To set Vim as the default editor launched by the GNU Octave {{Codeline|edit}} command, add the following line to your {{Path|~/.octaverc}} file:
To set Vim as the default editor launched by the GNU Octave {{Codeline|edit}} command, add one of the following line to your {{Path|~/.octaverc}} file:


  edit mode async
  EDITOR ("gvim")
 
EDITOR ("<terminal> -e 'vim'");


and one of the following:
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.


  EDITOR ("<terminal> -e 'vim'");
The {{Codeline|edit}} command defaults to asynchronous communication which creates a new process for the launched editor and then runs it in the background. If, for some reason, you have modified this setting then you will also need to add


  EDITOR ("gvim")
  edit mode async


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 the {{Path|~/.octaverc}} file.


To use Vim as default editor without starting a separate window, add the following lines to your {{Path|~/.octaverc}} file:
To use Vim as the default editor without starting a separate window, add the following lines to your {{Path|~/.octaverc}} file:


  edit mode sync
  edit mode sync
Line 23: Line 25:


== A better GNU Octave syntax file ==
== A better GNU Octave syntax file ==
As for now, Vim hasn't a dedicated, officially distributed filetype for GNU Octave. The community agreed the best solution is to use [https://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.  A companion script for indenting Octave m-files is available at [https://www.vim.org/scripts/script.php?script_id=6056 octave.vim].
For now, Vim does not have a dedicated, officially distributed filetype for GNU Octave. The community agreed the best solution is to use [https://www.vim.org/scripts/script.php?script_id=3600 syntax.vim] by Rik. All the instructions for installing it can be found on the hyperlink.  A companion script for indenting Octave m-files from Rik is available at [https://www.vim.org/scripts/script.php?script_id=6056 indent.vim].


== Accessing GNU Octave info ==
== Accessing GNU Octave info ==
GNU Octave info package can be found in almost all Linux distributions. For installing it under Ubuntu, you can type:
GNU Octave info package can be found in almost all Linux distributions. To install the package under Ubuntu, you can type:


  $ sudo apt-get install octave<version>-info
  $ sudo apt-get install octave<version>-info


where {{Codeline|<version>}} must be substituted by the appropriate string. Add the following line to your {{Path|~/.vimrc}} file:
where {{Codeline|<version>}} must be substituted by the appropriate string.
 
Add the following line to your {{Path|~/.vimrc}} file:


  autocmd FileType matlab setlocal keywordprg=info\ octave\ --vi-keys\ --index-search
  autocmd FileType matlab setlocal keywordprg=info\ octave\ --vi-keys\ --index-search
Line 36: 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.
Unfortunately info does not work in dumb terminals. As gVim has only a dumb terminal, a workaround must be done to access info. Two methods are possible. First, one can to use a plugin, like [https://github.com/carlobaldassi/ConqueTerm ConqueTerm], which can turn a gVim buffer into a terminal emulator.
Second method is to select an external terminal emulator, preferably fast loading one, such as xterm, and install it. For installing it under Ubuntu, you can type:
Second, one can use an external terminal emulator, preferably a fast loading one such as xterm, and install it. To installing xterm under Ubuntu, you can type:


  $ sudo apt-get install xterm
  $ sudo apt-get install xterm
Line 45: Line 49:
  autocmd FileType octave setlocal keywordprg=xterm\ -e\ info\ octave\ --vi-keys\ --index-search
  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:
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 a larger font and a specific window geometry for xterm with the 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
  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}}.
'''NOTE:''' If using Rik's [http://www.vim.org/scripts/script.php?script_id=3600 syntax.vim] syntax, replace {{Codeline|matlab}} by {{Codeline|octave}}.


== Jumping between control statements ==
== Jumping between control statements ==
1,072

edits