if_ruby.txt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. *if_ruby.txt* Nvim
  2. VIM REFERENCE MANUAL by Shugo Maeda
  3. The Ruby Interface to Vim *if_ruby* *ruby* *Ruby*
  4. *E266* *E267* *E268* *E269* *E270* *E271* *E272* *E273*
  5. The home page for ruby is https://www.ruby-lang.org/. You can find links for
  6. downloading Ruby there.
  7. Type |gO| to see the table of contents.
  8. ==============================================================================
  9. 1. Commands *ruby-commands*
  10. *:ruby* *:rub*
  11. :rub[y] {cmd} Execute Ruby command {cmd}. A command to try it out: >
  12. :ruby print "Hello"
  13. :rub[y] << [endmarker]
  14. {script}
  15. {endmarker}
  16. Execute Ruby script {script}.
  17. The {endmarker} after {script} must NOT be preceded by
  18. any white space.
  19. If [endmarker] is omitted, it defaults to a dot '.'
  20. like for the |:append| and |:insert| commands.
  21. This form of the |:ruby| command is mainly useful for
  22. including ruby code in vim scripts.
  23. Example Vim script: >
  24. function! RedGem()
  25. ruby << EOF
  26. class Garnet
  27. def initialize(s)
  28. @buffer = VIM::Buffer.current
  29. vimputs(s)
  30. end
  31. def vimputs(s)
  32. @buffer.append(@buffer.count,s)
  33. end
  34. end
  35. gem = Garnet.new("pretty")
  36. EOF
  37. endfunction
  38. <
  39. To see what version of Ruby you have: >
  40. :ruby print RUBY_VERSION
  41. <
  42. *:rubydo* *:rubyd* *E265*
  43. :[range]rubyd[o] {cmd} Evaluate Ruby command {cmd} for each line in the
  44. [range], with $_ being set to the text of each line in
  45. turn, without a trailing <EOL>. Setting $_ will change
  46. the text, but note that it is not possible to add or
  47. delete lines using this command.
  48. The default for [range] is the whole file: "1,$".
  49. *:rubyfile* *:rubyf*
  50. :rubyf[ile] {file} Execute the Ruby script in {file}. This is the same as
  51. `:ruby load 'file'`, but allows file name completion.
  52. Executing Ruby commands is not possible in the |sandbox|.
  53. ==============================================================================
  54. 2. The VIM module *ruby-vim*
  55. Ruby code gets all of its access to vim via the "VIM" module.
  56. Overview >
  57. print "Hello" # displays a message
  58. VIM.command(cmd) # execute an Ex command
  59. num = VIM::Window.count # gets the number of windows
  60. w = VIM::Window[n] # gets window "n"
  61. cw = VIM::Window.current # gets the current window
  62. num = VIM::Buffer.count # gets the number of buffers
  63. b = VIM::Buffer[n] # gets buffer "n"
  64. cb = VIM::Buffer.current # gets the current buffer
  65. w.height = lines # sets the window height
  66. w.cursor = [row, col] # sets the window cursor position
  67. pos = w.cursor # gets an array [row, col]
  68. name = b.name # gets the buffer file name
  69. line = b[n] # gets a line from the buffer
  70. num = b.count # gets the number of lines
  71. b[n] = str # sets a line in the buffer
  72. b.delete(n) # deletes a line
  73. b.append(n, str) # appends a line after n
  74. line = VIM::Buffer.current.line # gets the current line
  75. num = VIM::Buffer.current.line_number # gets the current line number
  76. VIM::Buffer.current.line = "test" # sets the current line number
  77. <
  78. Module Functions:
  79. *ruby-message*
  80. VIM::message({msg})
  81. Displays the message {msg}.
  82. *ruby-set_option*
  83. VIM::set_option({arg})
  84. Sets a vim option. {arg} can be any argument that the ":set" command
  85. accepts. Note that this means that no spaces are allowed in the
  86. argument! See |:set|.
  87. *ruby-command*
  88. VIM::command({cmd})
  89. Executes Ex command {cmd}.
  90. *ruby-evaluate*
  91. VIM::evaluate({expr})
  92. Evaluates {expr} using the vim internal expression evaluator (see
  93. |expression|). Returns the expression result as a string.
  94. A |List| is turned into a string by joining the items and inserting
  95. line breaks.
  96. ==============================================================================
  97. 3. VIM::Buffer objects *ruby-buffer*
  98. VIM::Buffer objects represent vim buffers.
  99. Class Methods:
  100. current Returns the current buffer object.
  101. count Returns the number of buffers.
  102. self[{n}] Returns the buffer object for the number {n}. The first number
  103. is 0.
  104. Methods:
  105. name Returns the full name of the buffer.
  106. number Returns the number of the buffer.
  107. count Returns the number of lines.
  108. length Returns the number of lines.
  109. self[{n}] Returns a line from the buffer. {n} is the line number.
  110. self[{n}] = {str}
  111. Sets a line in the buffer. {n} is the line number.
  112. delete({n}) Deletes a line from the buffer. {n} is the line number.
  113. append({n}, {str})
  114. Appends a line after the line {n}.
  115. line Returns the current line of the buffer if the buffer is
  116. active.
  117. line = {str} Sets the current line of the buffer if the buffer is active.
  118. line_number Returns the number of the current line if the buffer is
  119. active.
  120. ==============================================================================
  121. 4. VIM::Window objects *ruby-window*
  122. VIM::Window objects represent vim windows.
  123. Class Methods:
  124. current Returns the current window object.
  125. count Returns the number of windows.
  126. self[{n}] Returns the window object for the number {n}. The first number
  127. is 0.
  128. Methods:
  129. buffer Returns the buffer displayed in the window.
  130. height Returns the height of the window.
  131. height = {n} Sets the window height to {n}.
  132. width Returns the width of the window.
  133. width = {n} Sets the window width to {n}.
  134. cursor Returns a [row, col] array for the cursor position.
  135. First line number is 1 and first column number is 0.
  136. cursor = [{row}, {col}]
  137. Sets the cursor position to {row} and {col}.
  138. ==============================================================================
  139. 5. Global variables *ruby-globals*
  140. There are two global variables.
  141. $curwin The current window object.
  142. $curbuf The current buffer object.
  143. ==============================================================================
  144. 6. rubyeval() Vim function *ruby-rubyeval*
  145. To facilitate bi-directional interface, you can use |rubyeval()| function to
  146. evaluate Ruby expressions and pass their values to Vim script.
  147. The Ruby value "true", "false" and "nil" are converted to v:true, v:false and
  148. v:null, respectively.
  149. ==============================================================================
  150. vim:tw=78:ts=8:noet:ft=help:norl: