class Neovim::Buffer

Class representing an nvim buffer.

The methods documented here were generated using NVIM v0.5.0

@api private

Attributes

lines[R]

Private Class Methods

[](index) click to toggle source
# File lib/neovim/ruby_provider/buffer_ext.rb, line 14
def self.[](index)
  ::Vim.list_bufs[index]
end
count() click to toggle source
# File lib/neovim/ruby_provider/buffer_ext.rb, line 10
def self.count
  ::Vim.list_bufs.size
end
current() click to toggle source
# File lib/neovim/ruby_provider/buffer_ext.rb, line 6
def self.current
  ::Vim.get_current_buf
end
new(*args) click to toggle source
Calls superclass method
# File lib/neovim/buffer.rb, line 11
def initialize(*args)
  super
  @lines = LineRange.new(self)
end

Private Instance Methods

[](index) click to toggle source

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
[]=(index, str) click to toggle source

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
active?() click to toggle source

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(index, str) click to toggle source

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
check_index(index) click to toggle source
# File lib/neovim/buffer.rb, line 130
def check_index(index)
  raise ArgumentError, "Index out of bounds" if index < 0
end
count() click to toggle source

Get the number of lines.

@return [Integer]

# File lib/neovim/buffer.rb, line 41
def count
  line_count
end
delete(index) click to toggle source

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
length() click to toggle source

Get the number of lines.

@return [Integer]

# File lib/neovim/buffer.rb, line 48
def length
  count
end
line() click to toggle source

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
line=(str) click to toggle source

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
line_number() click to toggle source

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
lines=(strs) click to toggle source

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
name() click to toggle source

Get the buffer name.

@return [String]

# File lib/neovim/buffer.rb, line 27
def name
  get_name
end
number() click to toggle source

Get the buffer index.

@return [Integer]

# File lib/neovim/buffer.rb, line 34
def number
  get_number
end