Mercurial > vim
annotate runtime/doc/if_ruby.txt @ 7273:73207eca53f5 v7.4.942
commit https://github.com/vim/vim/commit/60422e68a3a555144f8c76c666f050e8d104c16b
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Nov 25 23:53:01 2015 +0100
patch 7.4.942
Problem: test_tagcase breaks for small builds.
Solution: Bail out of the test early. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 26 Nov 2015 08:22:10 +0100 |
parents | 42717d048817 |
children | 444efa5f5015 |
rev | line source |
---|---|
7196
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
1 *if_ruby.txt* For Vim version 7.4. Last change: 2015 Oct 16 |
7 | 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| | |
557 | 14 6. Dynamic loading |ruby-dynamic| |
7 | 15 |
16 {Vi does not have any of these commands} | |
17 *E266* *E267* *E268* *E269* *E270* *E271* *E272* *E273* | |
18 | |
19 The Ruby interface only works when Vim was compiled with the |+ruby| feature. | |
20 | |
21 The home page for ruby is http://www.ruby-lang.org/. You can find links for | |
22 downloading Ruby there. | |
23 | |
24 ============================================================================== | |
25 1. Commands *ruby-commands* | |
26 | |
27 *:ruby* *:rub* | |
3750 | 28 :rub[y] {cmd} Execute Ruby command {cmd}. A command to try it out: > |
29 :ruby print "Hello" | |
7 | 30 |
31 :rub[y] << {endpattern} | |
32 {script} | |
33 {endpattern} | |
34 Execute Ruby script {script}. | |
35 {endpattern} must NOT be preceded by any white space. | |
36 If {endpattern} is omitted, it defaults to a dot '.' | |
236 | 37 like for the |:append| and |:insert| commands. This |
7 | 38 form of the |:ruby| command is mainly useful for |
39 including ruby code in vim scripts. | |
40 Note: This command doesn't work when the Ruby feature | |
41 wasn't compiled in. To avoid errors, see | |
42 |script-here|. | |
43 | |
44 Example Vim script: > | |
45 | |
46 function! RedGem() | |
47 ruby << EOF | |
48 class Garnet | |
49 def initialize(s) | |
50 @buffer = VIM::Buffer.current | |
51 vimputs(s) | |
52 end | |
53 def vimputs(s) | |
54 @buffer.append(@buffer.count,s) | |
55 end | |
56 end | |
57 gem = Garnet.new("pretty") | |
58 EOF | |
59 endfunction | |
60 < | |
61 | |
62 *:rubydo* *:rubyd* *E265* | |
63 :[range]rubyd[o] {cmd} Evaluate Ruby command {cmd} for each line in the | |
64 [range], with $_ being set to the text of each line in | |
236 | 65 turn, without a trailing <EOL>. Setting $_ will change |
7 | 66 the text, but note that it is not possible to add or |
67 delete lines using this command. | |
68 The default for [range] is the whole file: "1,$". | |
69 | |
70 *:rubyfile* *:rubyf* | |
71 :rubyf[ile] {file} Execute the Ruby script in {file}. This is the same as | |
72 ":ruby load 'file'", but allows file name completion. | |
73 | |
74 Executing Ruby commands is not possible in the |sandbox|. | |
75 | |
76 ============================================================================== | |
77 2. The VIM module *ruby-vim* | |
78 | |
79 Ruby code gets all of its access to vim via the "VIM" module. | |
80 | |
81 Overview > | |
809 | 82 print "Hello" # displays a message |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
83 VIM.command(cmd) # execute an Ex command |
809 | 84 num = VIM::Window.count # gets the number of windows |
85 w = VIM::Window[n] # gets window "n" | |
86 cw = VIM::Window.current # gets the current window | |
87 num = VIM::Buffer.count # gets the number of buffers | |
88 b = VIM::Buffer[n] # gets buffer "n" | |
89 cb = VIM::Buffer.current # gets the current buffer | |
90 w.height = lines # sets the window height | |
91 w.cursor = [row, col] # sets the window cursor position | |
92 pos = w.cursor # gets an array [row, col] | |
93 name = b.name # gets the buffer file name | |
94 line = b[n] # gets a line from the buffer | |
95 num = b.count # gets the number of lines | |
96 b[n] = str # sets a line in the buffer | |
97 b.delete(n) # deletes a line | |
98 b.append(n, str) # appends a line after n | |
99 line = VIM::Buffer.current.line # gets the current line | |
100 num = VIM::Buffer.current.line_number # gets the current line number | |
101 VIM::Buffer.current.line = "test" # sets the current line number | |
7 | 102 < |
103 | |
104 Module Functions: | |
105 | |
106 *ruby-message* | |
107 VIM::message({msg}) | |
108 Displays the message {msg}. | |
109 | |
110 *ruby-set_option* | |
111 VIM::set_option({arg}) | |
112 Sets a vim option. {arg} can be any argument that the ":set" command | |
113 accepts. Note that this means that no spaces are allowed in the | |
114 argument! See |:set|. | |
115 | |
116 *ruby-command* | |
117 VIM::command({cmd}) | |
118 Executes Ex command {cmd}. | |
119 | |
120 *ruby-evaluate* | |
121 VIM::evaluate({expr}) | |
122 Evaluates {expr} using the vim internal expression evaluator (see | |
6647 | 123 |expression|). Returns the expression result as: |
124 - a Integer if the Vim expression evaluates to a number | |
125 - a Float if the Vim expression evaluates to a float | |
126 - a String if the Vim expression evaluates to a string | |
127 - a Array if the Vim expression evaluates to a Vim list | |
128 - a Hash if the Vim expression evaluates to a Vim dictionary | |
129 Dictionaries and lists are recursively expanded. | |
7 | 130 |
131 ============================================================================== | |
132 3. VIM::Buffer objects *ruby-buffer* | |
133 | |
134 VIM::Buffer objects represent vim buffers. | |
135 | |
136 Class Methods: | |
137 | |
138 current Returns the current buffer object. | |
139 count Returns the number of buffers. | |
236 | 140 self[{n}] Returns the buffer object for the number {n}. The first number |
7 | 141 is 0. |
142 | |
143 Methods: | |
144 | |
145 name Returns the name of the buffer. | |
146 number Returns the number of the buffer. | |
147 count Returns the number of lines. | |
148 length Returns the number of lines. | |
149 self[{n}] Returns a line from the buffer. {n} is the line number. | |
150 self[{n}] = {str} | |
151 Sets a line in the buffer. {n} is the line number. | |
152 delete({n}) Deletes a line from the buffer. {n} is the line number. | |
153 append({n}, {str}) | |
154 Appends a line after the line {n}. | |
856 | 155 line Returns the current line of the buffer if the buffer is |
809 | 156 active. |
157 line = {str} Sets the current line of the buffer if the buffer is active. | |
158 line_number Returns the number of the current line if the buffer is | |
159 active. | |
7 | 160 |
161 ============================================================================== | |
162 4. VIM::Window objects *ruby-window* | |
163 | |
164 VIM::Window objects represent vim windows. | |
165 | |
166 Class Methods: | |
167 | |
168 current Returns the current window object. | |
169 count Returns the number of windows. | |
236 | 170 self[{n}] Returns the window object for the number {n}. The first number |
7 | 171 is 0. |
172 | |
173 Methods: | |
174 | |
175 buffer Returns the buffer displayed in the window. | |
176 height Returns the height of the window. | |
177 height = {n} Sets the window height to {n}. | |
502 | 178 width Returns the width of the window. |
179 width = {n} Sets the window width to {n}. | |
7 | 180 cursor Returns a [row, col] array for the cursor position. |
181 cursor = [{row}, {col}] | |
182 Sets the cursor position to {row} and {col}. | |
183 | |
184 ============================================================================== | |
557 | 185 5. Global variables *ruby-globals* |
7 | 186 |
187 There are two global variables. | |
188 | |
189 $curwin The current window object. | |
190 $curbuf The current buffer object. | |
191 | |
192 ============================================================================== | |
557 | 193 6. Dynamic loading *ruby-dynamic* |
194 | |
2625 | 195 On MS-Windows and Unix the Ruby library can be loaded dynamically. The |
196 |:version| output then includes |+ruby/dyn|. | |
557 | 197 |
2625 | 198 This means that Vim will search for the Ruby DLL file or shared library only |
199 when needed. When you don't use the Ruby interface you don't need it, thus | |
200 you can use Vim even though this library file is not on your system. | |
557 | 201 |
7196
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
202 MS-Windows ~ |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
203 |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
204 You need to install the right version of Ruby for this to work. You can find |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
205 the package to download from: |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
206 http://www.garbagecollect.jp/ruby/mswin32/en/download/release.html |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
207 Currently that is ruby-1.9.1-p429-i386-mswin32.zip |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
208 |
557 | 209 To use the Ruby interface the Ruby DLL must be in your search path. In a |
210 console window type "path" to see what directories are used. | |
211 | |
212 The name of the DLL must match the Ruby version Vim was compiled with. | |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
213 Currently the name is "msvcrt-ruby191.dll". That is for Ruby 1.9.1. To know |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
214 for sure edit "gvim.exe" and search for "ruby\d*.dll\c". |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
215 |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
216 If you want to build Vim with Ruby 1.9.1, you need to edit the config.h file |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
217 and comment-out the check for _MSC_VER. |
3750 | 218 You may also need to rename the include directory name to match the version, |
219 strangely for Ruby 1.9.3 the directory is called 1.9.1. | |
557 | 220 |
7196
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
221 Unix ~ |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
222 |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
223 The 'rubydll' option can be used to specify the Ruby shared library file |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
224 instead of DYNAMIC_RUBY_DLL file what was specified at compile time. The |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
225 version of the shared library must match the Ruby version Vim was compiled |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
226 with. |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
6647
diff
changeset
|
227 |
557 | 228 ============================================================================== |
7 | 229 vim:tw=78:ts=8:ft=help:norl: |