If_ruby

Nvim :help 頁面,從 來源 使用 tree-sitter-vimdoc 解析器 產生


Ruby 到 Vim 的介面 ruby Ruby
Ruby 的首頁是 https://www.ruby-lang.org/。您可以在那裡找到下載 Ruby 的連結。

1. 命令 ruby-commands

:ruby :rub :rub[y] {cmd} 執行 Ruby 命令 {cmd}。一個可以試試看的命令
:ruby print "Hello"
:rub[y] << [trim] [{endmarker}] {script} {endmarker} 執行 Ruby 腳本 {script}
如果省略 [endmarker],它會像 :append:insert 命令一樣,預設為一個點 '.'。有關詳細資訊,請參閱 :let-heredoc
這種形式的 :ruby 命令主要用於在 vim 腳本中包含 Ruby 程式碼。
Vim 腳本範例
function! RedGem()
ruby << EOF
class Garnet
        def initialize(s)
                @buffer = VIM::Buffer.current
                vimputs(s)
        end
        def vimputs(s)
                @buffer.append(@buffer.count,s)
        end
end
gem = Garnet.new("pretty")
EOF
endfunction
查看您擁有的 Ruby 版本
:ruby print RUBY_VERSION
:rubydo :rubyd E265 :[range]rubyd[o] {cmd} 對於 [range] 中的每一行,評估 Ruby 命令 {cmd},其中 $_ 設定為每一行的文字,不帶尾隨的 <EOL>。設定 $_ 將會變更文字,但請注意,使用此命令無法新增或刪除行。[range] 的預設值為整個檔案:"1,$"。
:rubyfile :rubyf :rubyf[ile] {file} 執行 {file} 中的 Ruby 腳本。這與 :ruby load 'file' 相同,但允許檔案名稱補全。
沙箱中無法執行 Ruby 命令。

2. VIM 模組 ruby-vim

Ruby 程式碼透過 "VIM" 模組取得對 vim 的所有存取權。
概述
print "Hello"                              # displays a message
VIM.command(cmd)                      # execute an Ex command
num = VIM::Window.count                      # gets the number of windows
w = VIM::Window[n]                      # gets window "n"
cw = VIM::Window.current              # gets the current window
num = VIM::Buffer.count                      # gets the number of buffers
b = VIM::Buffer[n]                      # gets buffer "n"
cb = VIM::Buffer.current              # gets the current buffer
w.height = lines                      # sets the window height
w.cursor = [row, col]                      # sets the window cursor position
pos = w.cursor                              # gets an array [row, col]
name = b.name                              # gets the buffer file name
line = b[n]                              # gets a line from the buffer
num = b.count                              # gets the number of lines
b[n] = str                              # sets a line in the buffer
b.delete(n)                              # deletes a line
b.append(n, str)                      # appends a line after n
line = VIM::Buffer.current.line       # gets the current line
num = VIM::Buffer.current.line_number # gets the current line number
VIM::Buffer.current.line = "test"     # sets the current line number
模組函數
ruby-message
VIM::message({msg}) 顯示訊息 {msg}
ruby-set_option
VIM::set_option({arg}) 設定 vim 選項。{arg} 可以是 ":set" 命令接受的任何引數。請注意,這表示引數中不允許有空格!請參閱 :set
ruby-command
VIM::command({cmd}) 執行 Ex 命令 {cmd}
ruby-evaluate
VIM::evaluate({expr}) 使用 vim 內部運算式評估器評估 {expr} (請參閱 expression)。將運算式結果以字串形式傳回。List 會藉由連接項目並插入換行符號轉換為字串。

3. VIM::Buffer 物件 ruby-buffer

VIM::Buffer 物件代表 vim 緩衝區。
類別方法
current 傳回目前緩衝區物件。count 傳回緩衝區的數量。self[{n}] 傳回編號為 {n} 的緩衝區物件。第一個數字為 0。
方法
name 傳回緩衝區的完整名稱。number 傳回緩衝區的編號。count 傳回行數。length 傳回行數。self[{n}] 傳回緩衝區中的一行。{n} 為行號。self[{n}] = {str} 設定緩衝區中的一行。{n} 為行號。delete({n}) 從緩衝區刪除一行。{n} 為行號。append({n}, {str}) 在行 {n} 後面附加一行。line 如果緩衝區處於活動狀態,則傳回緩衝區的目前行。line = {str} 如果緩衝區處於活動狀態,則設定緩衝區的目前行。line_number 如果緩衝區處於活動狀態,則傳回目前行的編號。

4. VIM::Window 物件 ruby-window

VIM::Window 物件代表 vim 視窗。
類別方法
current 傳回目前視窗物件。count 傳回視窗的數量。self[{n}] 傳回編號為 {n} 的視窗物件。第一個數字為 0。
方法
buffer 傳回視窗中顯示的緩衝區。height 傳回視窗的高度。height = {n} 將視窗高度設定為 {n}。width 傳回視窗的寬度。width = {n} 將視窗寬度設定為 {n}。cursor 傳回游標位置的 [row, col] 陣列。第一行編號為 1,第一列編號為 0。cursor = [{row}, {col}] 將游標位置設定為 {row}{col}

5. 全域變數 ruby-globals

有兩個全域變數。
$curwin 目前的視窗物件。$curbuf 目前的緩衝區物件。

6. rubyeval() Vim 函數 ruby-rubyeval

為了方便雙向介面,您可以使用 rubyeval() 函數來評估 Ruby 運算式,並將其值傳遞給 Vim 腳本。
Ruby 值 "true"、"false" 和 "nil" 會分別轉換為 v:true、v:false 和 v:null。
主頁
命令索引
快速參考