if_ruby.txt (6190B)
1 *if_ruby.txt* Nvim 2 3 4 VIM REFERENCE MANUAL by Shugo Maeda 5 6 The Ruby Interface to Vim *if_ruby* *ruby* *Ruby* 7 8 See |provider-ruby| for more information. 9 10 *E266* *E267* *E268* *E269* *E270* *E271* *E272* *E273* 11 12 The home page for ruby is https://www.ruby-lang.org/. You can find links for 13 downloading Ruby there. 14 15 Type |gO| to see the table of contents. 16 17 ============================================================================== 18 1. Commands *ruby-commands* 19 20 *:ruby* *:rub* 21 :rub[y] {cmd} Execute Ruby command {cmd}. A command to try it out: > 22 :ruby print "Hello" 23 24 :rub[y] << [trim] [{endmarker}] 25 {script} 26 {endmarker} 27 Execute Ruby script {script}. 28 29 If [endmarker] is omitted, it defaults to a dot '.' 30 like for the |:append| and |:insert| commands. Refer 31 to |:let-heredoc| for more information. 32 33 34 This form of the |:ruby| command is mainly useful for 35 including ruby code in vim scripts. 36 37 Example Vim script: > 38 39 function! RedGem() 40 ruby << EOF 41 class Garnet 42 def initialize(s) 43 @buffer = VIM::Buffer.current 44 vimputs(s) 45 end 46 def vimputs(s) 47 @buffer.append(@buffer.count,s) 48 end 49 end 50 gem = Garnet.new("pretty") 51 EOF 52 endfunction 53 < 54 To see what version of Ruby you have: > 55 :ruby print RUBY_VERSION 56 < 57 58 *:rubydo* *:rubyd* *E265* 59 :[range]rubyd[o] {cmd} Evaluate Ruby command {cmd} for each line in the 60 [range], with $_ being set to the text of each line in 61 turn, without a trailing <EOL>. Setting $_ will 62 change the text, but note that it is not possible to 63 add or delete lines using this command. 64 The default for [range] is the whole file: "1,$". 65 66 *:rubyfile* *:rubyf* 67 :rubyf[ile] {file} Execute the Ruby script in {file}. This is the same 68 as `:ruby load 'file'`, but allows file name completion. 69 70 Executing Ruby commands is not possible in the |sandbox|. 71 72 ============================================================================== 73 2. The VIM module *ruby-vim* 74 75 Ruby code gets all of its access to vim via the "VIM" module. 76 77 Overview > 78 print "Hello" # displays a message 79 VIM.command(cmd) # execute an Ex command 80 num = VIM::Window.count # gets the number of windows 81 w = VIM::Window[n] # gets window "n" 82 cw = VIM::Window.current # gets the current window 83 num = VIM::Buffer.count # gets the number of buffers 84 b = VIM::Buffer[n] # gets buffer "n" 85 cb = VIM::Buffer.current # gets the current buffer 86 w.height = lines # sets the window height 87 w.cursor = [row, col] # sets the window cursor position 88 pos = w.cursor # gets an array [row, col] 89 name = b.name # gets the buffer file name 90 line = b[n] # gets a line from the buffer 91 num = b.count # gets the number of lines 92 b[n] = str # sets a line in the buffer 93 b.delete(n) # deletes a line 94 b.append(n, str) # appends a line after n 95 line = VIM::Buffer.current.line # gets the current line 96 num = VIM::Buffer.current.line_number # gets the current line number 97 VIM::Buffer.current.line = "test" # sets the current line number 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 A |List| is turned into a string by joining the items and inserting 121 line breaks. 122 123 ============================================================================== 124 3. VIM::Buffer objects *ruby-buffer* 125 126 VIM::Buffer objects represent vim buffers. 127 128 Class Methods: 129 130 current Returns the current buffer object. 131 count Returns the number of buffers. 132 self[{n}] Returns the buffer object for the number {n}. The first 133 number is 0. 134 135 Methods: 136 137 name Returns the full name of the buffer. 138 number Returns the number of the buffer. 139 count Returns the number of lines. 140 length Returns the number of lines. 141 self[{n}] Returns a line from the buffer. {n} is the line number. 142 self[{n}] = {str} 143 Sets a line in the buffer. {n} is the line number. 144 delete({n}) Deletes a line from the buffer. {n} is the line number. 145 append({n}, {str}) 146 Appends a line after the line {n}. 147 line Returns the current line of the buffer if the buffer is 148 active. 149 line = {str} Sets the current line of the buffer if the buffer is active. 150 line_number Returns the number of the current line if the buffer is 151 active. 152 153 ============================================================================== 154 4. VIM::Window objects *ruby-window* 155 156 VIM::Window objects represent vim windows. 157 158 Class Methods: 159 160 current Returns the current window object. 161 count Returns the number of windows. 162 self[{n}] Returns the window object for the number {n}. The first 163 number is 0. 164 165 Methods: 166 167 buffer Returns the buffer displayed in the window. 168 height Returns the height of the window. 169 height = {n} Sets the window height to {n}. 170 width Returns the width of the window. 171 width = {n} Sets the window width to {n}. 172 cursor Returns a [row, col] array for the cursor position. 173 First line number is 1 and first column number is 0. 174 cursor = [{row}, {col}] 175 Sets the cursor position to {row} and {col}. 176 177 ============================================================================== 178 5. Global variables *ruby-globals* 179 180 There are two global variables. 181 182 $curwin The current window object. 183 $curbuf The current buffer object. 184 185 ============================================================================== 186 6. rubyeval() Vim function *ruby-rubyeval* 187 188 To facilitate bi-directional interface, you can use |rubyeval()| function to 189 evaluate Ruby expressions and pass their values to Vim script. 190 191 The Ruby value "true", "false" and "nil" are converted to v:true, v:false and 192 v:null, respectively. 193 194 vim:tw=78:ts=8:noet:ft=help:norl: