Module: Neovim

Defined in:
lib/neovim.rb,
lib/neovim/api.rb,
lib/neovim/host.rb,
lib/neovim/buffer.rb,
lib/neovim/client.rb,
lib/neovim/plugin.rb,
lib/neovim/window.rb,
lib/neovim/current.rb,
lib/neovim/logging.rb,
lib/neovim/message.rb,
lib/neovim/session.rb,
lib/neovim/tabpage.rb,
lib/neovim/version.rb,
lib/neovim/connection.rb,
lib/neovim/event_loop.rb,
lib/neovim/executable.rb,
lib/neovim/line_range.rb,
lib/neovim/plugin/dsl.rb,
lib/neovim/host/loader.rb,
lib/neovim/remote_object.rb,
lib/neovim/ruby_provider.rb,
lib/neovim/plugin/handler.rb,
lib/neovim/ruby_provider/buffer_ext.rb,
lib/neovim/ruby_provider/window_ext.rb

Overview

The main entrypoint to the Neovim gem. It allows you to connect to a running nvim instance programmatically or define a remote plugin to be autoloaded by nvim.

You can connect to a running nvim instance by setting or inspecting the NVIM_LISTEN_ADDRESS environment variable and connecting via the appropriate attach_ method. This is currently supported for both UNIX domain sockets and TCP. You can also spawn and connect to an nvim subprocess via Neovim.attach_child(argv).

You can define a remote plugin using the Neovim.plugin DSL, which allows you to register commands, functions, and autocmds. Plugins are autoloaded by nvim from the rplugin/ruby directory in your nvim runtime path.

Examples:

Connect over a TCP socket

Neovim.attach_tcp("0.0.0.0", 3333) # => Neovim::Client

Connect over a UNIX domain socket

Neovim.attach_unix("/tmp/nvim.sock") # => Neovim::Client

Spawn and connect to a child nvim process

Neovim.attach_child(["nvim", "--embed"]) # => Neovim::Client

Define a Ruby plugin

# ~/.config/nvim/rplugin/ruby/plugin.rb

Neovim.plugin do |plug|
  # Define a command called "SetLine" which sets the contents of the
  # current line. This command is executed asynchronously, so the return
  # value is ignored.
  plug.command(:SetLine, nargs: 1) do |nvim, str|
    nvim.current.line = str
  end

  # Define a function called "Sum" which adds two numbers. This function is
  # executed synchronously, so the result of the block will be returned to
  # nvim.
  plug.function(:Sum, nargs: 2, sync: true) do |nvim, x, y|
    x + y
  end

  # Define an autocmd for the BufEnter event on Ruby files.
  plug.autocmd(:BufEnter, pattern: "*.rb") do |nvim|
    nvim.command("echom 'Ruby file, eh?'")
  end
end

See Also:

Defined Under Namespace

Modules: Logging, RubyProvider Classes: API, Buffer, Client, Connection, Current, EventLoop, Executable, Host, LineRange, Message, Plugin, RemoteObject, Session, Tabpage, Window

Constant Summary collapse

VERSION =
Gem::Version.new("0.7.1")

Class Method Summary collapse

Class Method Details

.attach_child(argv = [executable.path]) ⇒ Client

Spawn and connect to a child nvim process.

Parameters:

  • argv (Array) (defaults to: [executable.path])

    The arguments to pass to the spawned process

Returns:

See Also:


82
83
84
# File 'lib/neovim.rb', line 82

def self.attach_child(argv=[executable.path])
  Client.from_event_loop EventLoop.child(argv)
end

.attach_tcp(host, port) ⇒ Client

Connect to a running nvim instance over TCP.

Parameters:

  • host (String)

    The hostname or IP address

  • port (Integer)

    The port

Returns:

See Also:


64
65
66
# File 'lib/neovim.rb', line 64

def self.attach_tcp(host, port)
  Client.from_event_loop EventLoop.tcp(host, port)
end

.attach_unix(socket_path) ⇒ Client

Connect to a running nvim instance over a UNIX domain socket.

Parameters:

  • socket_path (String)

    The socket path

Returns:

See Also:


73
74
75
# File 'lib/neovim.rb', line 73

def self.attach_unix(socket_path)
  Client.from_event_loop EventLoop.unix(socket_path)
end

.executableExecutable

Return a Neovim::Executable representing the active nvim executable.

Returns:

See Also:


99
100
101
# File 'lib/neovim.rb', line 99

def self.executable
  @executable ||= Executable.from_env
end

.loggerLogger

The Neovim global logger.

Returns:

  • (Logger)

See Also:


116
117
118
# File 'lib/neovim.rb', line 116

def self.logger
  Logging.logger
end

.logger=(logger) ⇒ Logger

Set the Neovim global logger.

Parameters:

  • logger (Logger)

    The target logger

Returns:

  • (Logger)

See Also:


108
109
110
# File 'lib/neovim.rb', line 108

def self.logger=(logger)
  Logging.logger = logger
end

.pluginObject

Placeholder method for exposing the remote plugin DSL. This gets temporarily overwritten in Host::Loader#load.


91
92
93
# File 'lib/neovim.rb', line 91

def self.plugin
  raise "Can't call Neovim.plugin outside of a plugin host."
end