Movatterモバイル変換


[0]ホーム

URL:


If_ruby

Nvim:help pages,generated fromsource using thetree-sitter-vimdoc parser.


The Ruby Interface to VimrubyRuby
E266E267E268E269E270E271E272E273
The home page for ruby ishttps://www.ruby-lang.org/. You can find links fordownloading Ruby there.

1. Commandsruby-commands

:ruby:rub:rub[y]{cmd}Execute Ruby command{cmd}. A command to try it out:
:ruby print "Hello"
:rub[y] << [trim] [{endmarker}]{script}{endmarker}Execute Ruby script{script}.
If [endmarker] is omitted, it defaults to a dot '.'like for the:append and:insert commands. Referto:let-heredoc for more information.
This form of the:ruby command is mainly useful forincluding ruby code in vim scripts.
Example Vim script:
function! RedGem()ruby << EOFclass Garnet        def initialize(s)                @buffer = VIM::Buffer.current                vimputs(s)        end        def vimputs(s)                @buffer.append(@buffer.count,s)        endendgem = Garnet.new("pretty")EOFendfunction
To see what version of Ruby you have:
:ruby print RUBY_VERSION
:rubydo:rubydE265:[range]rubyd[o]{cmd}Evaluate Ruby command{cmd} for each line in the[range], with $_ being set to the text of each line inturn, without a trailing<EOL>. Setting $_ willchange the text, but note that it is not possible toadd or delete lines using this command.The default for [range] is the whole file: "1,$".
:rubyfile:rubyf:rubyf[ile]{file}Execute the Ruby script in{file}. This is the sameas:ruby load 'file', but allows file name completion.
Executing Ruby commands is not possible in thesandbox.

2. The VIM moduleruby-vim

Ruby code gets all of its access to vim via the "VIM" module.
Overview
print "Hello"      # displays a messageVIM.command(cmd)      # execute an Ex commandnum = VIM::Window.count      # gets the number of windowsw = VIM::Window[n]      # gets window "n"cw = VIM::Window.current      # gets the current windownum = VIM::Buffer.count      # gets the number of buffersb = VIM::Buffer[n]      # gets buffer "n"cb = VIM::Buffer.current      # gets the current bufferw.height = lines      # sets the window heightw.cursor = [row, col]      # sets the window cursor positionpos = w.cursor      # gets an array [row, col]name = b.name      # gets the buffer file nameline = b[n]      # gets a line from the buffernum = b.count      # gets the number of linesb[n] = str      # sets a line in the bufferb.delete(n)      # deletes a lineb.append(n, str)      # appends a line after nline = VIM::Buffer.current.line       # gets the current linenum = VIM::Buffer.current.line_number # gets the current line numberVIM::Buffer.current.line = "test"     # sets the current line number
Module Functions:
ruby-message
VIM::message({msg})Displays the message{msg}.
ruby-set_option
VIM::set_option({arg})Sets a vim option.{arg} can be any argument that the ":set" commandaccepts. Note that this means that no spaces are allowed in theargument! See:set.
ruby-command
VIM::command({cmd})Executes Ex command{cmd}.
ruby-evaluate
VIM::evaluate({expr})Evaluates{expr} using the vim internal expression evaluator (seeexpression). Returns the expression result as a string.AList is turned into a string by joining the items and insertingline breaks.

3. VIM::Buffer objectsruby-buffer

VIM::Buffer objects represent vim buffers.
Class Methods:
currentReturns the current buffer object.countReturns the number of buffers.self[{n}]Returns the buffer object for the number{n}. The firstnumber is 0.
Methods:
nameReturns the full name of the buffer.numberReturns the number of the buffer.countReturns the number of lines.lengthReturns the number of lines.self[{n}]Returns a line from the buffer.{n} is the line number.self[{n}] ={str}Sets a line in the buffer.{n} is the line number.delete({n})Deletes a line from the buffer.{n} is the line number.append({n},{str})Appends a line after the line{n}.lineReturns the current line of the buffer if the buffer isactive.line ={str} Sets the current line of the buffer if the buffer is active.line_number Returns the number of the current line if the buffer isactive.

4. VIM::Window objectsruby-window

VIM::Window objects represent vim windows.
Class Methods:
currentReturns the current window object.countReturns the number of windows.self[{n}]Returns the window object for the number{n}. The firstnumber is 0.
Methods:
bufferReturns the buffer displayed in the window.heightReturns the height of the window.height ={n}Sets the window height to{n}.widthReturns the width of the window.width ={n}Sets the window width to{n}.cursorReturns a [row, col] array for the cursor position.First line number is 1 and first column number is 0.cursor = [{row},{col}]Sets the cursor position to{row} and{col}.

5. Global variablesruby-globals

There are two global variables.
$curwinThe current window object.$curbufThe current buffer object.

6. rubyeval() Vim functionruby-rubyeval

To facilitate bi-directional interface, you can userubyeval() function toevaluate Ruby expressions and pass their values to Vim script.
The Ruby value "true", "false" and "nil" are converted to v:true, v:false andv:null, respectively.
Main
Commands index
Quick reference

1. Commands
2. The VIM module
3. VIM::Buffer objects
4. VIM::Window objects
5. Global variables
6. rubyeval() Vim function

[8]ページ先頭

©2009-2025 Movatter.jp