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