class Neovim::Buffer
Class representing an nvim
buffer.
The methods documented here were generated using NVIM v0.5.0
@api private
Attributes
Private Class Methods
# File lib/neovim/ruby_provider/buffer_ext.rb, line 14 def self.[](index) ::Vim.list_bufs[index] end
# File lib/neovim/ruby_provider/buffer_ext.rb, line 10 def self.count ::Vim.list_bufs.size end
# File lib/neovim/ruby_provider/buffer_ext.rb, line 6 def self.current ::Vim.get_current_buf end
# File lib/neovim/buffer.rb, line 11 def initialize(*args) super @lines = LineRange.new(self) end
Private Instance Methods
Get the given line (1-indexed).
@param index [Integer] @return [String]
# File lib/neovim/buffer.rb, line 56 def [](index) check_index(index) @lines[index - 1] end
Set the given line (1-indexed).
@param index [Integer] @param str [String] @return [String]
# File lib/neovim/buffer.rb, line 66 def []=(index, str) check_index(index) @lines[index - 1] = str end
Determine if the buffer is active.
@return [Boolean]
# File lib/neovim/buffer.rb, line 124 def active? @session.request(:nvim_get_current_buf) == self end
Append a line after the given line (1-indexed).
To maintain backwards compatibility with vim
, the cursor is forced back to its previous position after inserting the line.
@param index [Integer] @param str [String] @return [String]
# File lib/neovim/buffer.rb, line 89 def append(index, str) check_index(index) window = @session.request(:nvim_get_current_win) cursor = window.cursor set_lines(index, index, true, [*str.split($/)]) window.set_cursor(cursor) str end
# File lib/neovim/buffer.rb, line 130 def check_index(index) raise ArgumentError, "Index out of bounds" if index < 0 end
Get the number of lines.
@return [Integer]
# File lib/neovim/buffer.rb, line 41 def count line_count end
Delete the given line (1-indexed).
@param index [Integer] @return [void]
# File lib/neovim/buffer.rb, line 75 def delete(index) check_index(index) @lines.delete(index - 1) nil end
Get the number of lines.
@return [Integer]
# File lib/neovim/buffer.rb, line 48 def length count end
Get the current line of an active buffer.
@return [String, nil]
# File lib/neovim/buffer.rb, line 102 def line @session.request(:nvim_get_current_line) if active? end
Set the current line of an active buffer.
@param str [String] @return [String, nil]
# File lib/neovim/buffer.rb, line 110 def line=(str) @session.request(:nvim_set_current_line, str) if active? end
Get the current line number of an active buffer.
@return [Integer, nil]
# File lib/neovim/buffer.rb, line 117 def line_number @session.request(:nvim_get_current_win).get_cursor[0] if active? end
Replace all the lines of the buffer.
@param strs [Array<String>] The replacement lines @return [Array<String>]
# File lib/neovim/buffer.rb, line 20 def lines=(strs) @lines[0..-1] = strs end
Get the buffer name.
@return [String]
# File lib/neovim/buffer.rb, line 27 def name get_name end
Get the buffer index.
@return [Integer]
# File lib/neovim/buffer.rb, line 34 def number get_number end