home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / doc / if_ruby.txt < prev    next >
Encoding:
Text File  |  2003-06-01  |  5.2 KB  |  177 lines

  1. *if_ruby.txt*   For Vim version 6.2.  Last change: 2001 Oct 25
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Shugo Maeda
  5.  
  6. The Ruby Interface to Vim                *ruby* *Ruby*
  7.  
  8.  
  9. 1. Commands            |ruby-commands|
  10. 2. The VIM module        |ruby-vim|
  11. 3. VIM::Buffer objects        |ruby-buffer|
  12. 4. VIM::Window objects        |ruby-window|
  13. 5. Global variables        |ruby-globals|
  14.  
  15. {Vi does not have any of these commands}
  16.             *E266* *E267* *E268* *E269* *E270* *E271* *E272* *E273*
  17.  
  18. The Ruby interface only works when Vim was compiled with the |+ruby| feature.
  19.  
  20. For MS-Windows you might find a Ruby library here:
  21.  
  22.     http://www.dm4lab.to/~usa/ruby_en.html
  23.  
  24. ==============================================================================
  25. 1. Commands                        *ruby-commands*
  26.  
  27.                             *:ruby* *:rub*
  28. :rub[y] {cmd}        Execute Ruby command {cmd}.
  29.  
  30. :rub[y] << {endpattern}
  31. {script}
  32. {endpattern}
  33.             Execute Ruby script {script}.
  34.             {endpattern} must NOT be preceded by any white space.
  35.             If {endpattern} is omitted, it defaults to a dot '.'
  36.             like for the |:append| and |:insert| commands. This
  37.             form of the |:ruby| command is mainly useful for
  38.             including ruby code in vim scripts.
  39.             Note: This command doesn't work when the Ruby feature
  40.             wasn't compiled in.  To avoid errors, see
  41.             |script-here|.
  42.  
  43. Example Vim script: >
  44.  
  45.     function! RedGem()
  46.     ruby << EOF
  47.     class Garnet
  48.         def initialize(s)
  49.             @buffer = VIM::Buffer.current
  50.             vimputs(s)
  51.         end
  52.         def vimputs(s)
  53.             @buffer.append(@buffer.count,s)
  54.         end
  55.     end
  56.     gem = Garnet.new("pretty")
  57.     EOF
  58.     endfunction
  59. <
  60.  
  61.                         *:rubydo* *:rubyd* *E265*
  62. :[range]rubyd[o] {cmd}    Evaluate Ruby command {cmd} for each line in the
  63.             [range], with $_ being set to the text of each line in
  64.             turn, without a trailing <EOL>. Setting $_ will change
  65.             the text, but note that it is not possible to add or
  66.             delete lines using this command.
  67.             The default for [range] is the whole file: "1,$".
  68.  
  69.                             *:rubyfile* *:rubyf*
  70. :rubyf[ile] {file}    Execute the Ruby script in {file}.  This is the same as
  71.             ":ruby load 'file'", but allows file name completion.
  72.  
  73. Executing Ruby commands is not possible in the |sandbox|.
  74.  
  75. ==============================================================================
  76. 2. The VIM module                    *ruby-vim*
  77.  
  78. Ruby code gets all of its access to vim via the "VIM" module.
  79.  
  80. Overview >
  81.     print "Hello"            # displays a message
  82.     VIM.command(cmd)        # execute an ex command
  83.     num = VIM::Window.count        # gets the number of windows
  84.     w = VIM::Window[n]        # gets window "n"
  85.     cw = VIM::Window.current    # gets the current window
  86.     num = VIM::Buffer.count        # gets the number of buffers
  87.     b = VIM::Buffer[n]        # gets buffer "n"
  88.     cb = VIM::Buffer.current    # gets the current buffer
  89.     w.height = lines        # sets the window height
  90.     w.cursor = [row, col]        # sets the window cursor position
  91.     pos = w.cursor            # gets an array [row, col]
  92.     name = b.name            # gets the buffer file name
  93.     line = b[n]            # gets a line from the buffer
  94.     num = b.count            # gets the number of lines
  95.     b[n] = str            # sets a line in the buffer
  96.     b.delete(n)            # deletes a line
  97.     b.append(n, str)        # appends a line after n
  98. <
  99.  
  100. Module Functions:
  101.  
  102.                             *ruby-message*
  103. VIM::message({msg})
  104.     Displays the message {msg}.
  105.  
  106.                             *ruby-set_option*
  107. VIM::set_option({arg})
  108.     Sets a vim option.  {arg} can be any argument that the ":set" command
  109.     accepts.  Note that this means that no spaces are allowed in the
  110.     argument!  See |:set|.
  111.  
  112.                             *ruby-command*
  113. VIM::command({cmd})
  114.     Executes Ex command {cmd}.
  115.  
  116.                             *ruby-evaluate*
  117. VIM::evaluate({expr})
  118.     Evaluates {expr} using the vim internal expression evaluator (see
  119.     |expression|). Returns the expression result as a string.
  120.  
  121. ==============================================================================
  122. 3. VIM::Buffer objects                    *ruby-buffer*
  123.  
  124. VIM::Buffer objects represent vim buffers.
  125.  
  126. Class Methods:
  127.  
  128. current        Returns the current buffer object.
  129. count        Returns the number of buffers.
  130. self[{n}]    Returns the buffer object for the number {n}. The first number
  131.         is 0.
  132.  
  133. Methods:
  134.  
  135. name        Returns the name of the buffer.
  136. number        Returns the number of the buffer.
  137. count        Returns the number of lines.
  138. length        Returns the number of lines.
  139. self[{n}]    Returns a line from the buffer. {n} is the line number.
  140. self[{n}] = {str}
  141.         Sets a line in the buffer. {n} is the line number.
  142. delete({n})    Deletes a line from the buffer. {n} is the line number.
  143. append({n}, {str})
  144.         Appends a line after the line {n}.
  145.  
  146. ==============================================================================
  147. 4. VIM::Window objects                    *ruby-window*
  148.  
  149. VIM::Window objects represent vim windows.
  150.  
  151. Class Methods:
  152.  
  153. current        Returns the current window object.
  154. count        Returns the number of windows.
  155. self[{n}]    Returns the window object for the number {n}. The first number
  156.         is 0.
  157.  
  158. Methods:
  159.  
  160. buffer        Returns the buffer displayed in the window.
  161. height        Returns the height of the window.
  162. height = {n}    Sets the window height to {n}.
  163. cursor        Returns a [row, col] array for the cursor position.
  164. cursor = [{row}, {col}]
  165.         Sets the cursor position to {row} and {col}.
  166.  
  167. ==============================================================================
  168. 4. Global variables                    *ruby-globals*
  169.  
  170. There are two global variables.
  171.  
  172. $curwin        The current window object.
  173. $curbuf        The current buffer object.
  174.  
  175. ==============================================================================
  176.  vim:tw=78:ts=8:ft=help:norl:
  177.