2017-03-21 17:13:51 -07:00
|
|
|
*develop.txt* Nvim
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
2016-06-12 23:11:12 -07:00
|
|
|
NVIM REFERENCE MANUAL
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
2018-09-05 15:58:10 -07:00
|
|
|
Development of Nvim *development*
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2018-11-15 18:00:04 -07:00
|
|
|
This reference describes design constraints and guidelines, for developing
|
|
|
|
Nvim applications or Nvim itself.
|
|
|
|
Architecture and internal concepts are covered in src/nvim/README.md
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2018-11-15 18:00:04 -07:00
|
|
|
Nvim is free and open source. Everybody is encouraged to contribute.
|
|
|
|
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md
|
2016-06-14 20:12:43 -07:00
|
|
|
|
2017-10-20 17:33:58 -07:00
|
|
|
Type |gO| to see the table of contents.
|
2017-05-01 08:09:29 -07:00
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
==============================================================================
|
2017-04-17 14:52:38 -07:00
|
|
|
Design goals *design-goals*
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2018-11-15 18:00:04 -07:00
|
|
|
Most important things come first (roughly). Some items conflict; this is
|
|
|
|
intentional. A balance must be found.
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
2016-06-12 23:11:12 -07:00
|
|
|
NVIM IS... IMPROVED *design-improved*
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2018-09-05 15:58:10 -07:00
|
|
|
The Neo bits of Nvim should make it a better Vim, without becoming a
|
|
|
|
completely different editor.
|
|
|
|
- In matters of taste, prefer Vim/Unix tradition. If there is no relevant
|
|
|
|
Vim/Unix tradition, consider the "common case".
|
2014-07-10 21:05:51 -07:00
|
|
|
- A feature that people do not know about is a useless feature. Don't add
|
|
|
|
obscure features, or at least add hints in documentation that they exist.
|
|
|
|
- There is no limit to the features that can be added. Selecting new features
|
2017-04-17 14:52:38 -07:00
|
|
|
is based on (1) what users ask for, (2) how much effort it takes to
|
2014-07-10 21:05:51 -07:00
|
|
|
implement and (3) someone actually implementing it.
|
2018-09-05 15:58:10 -07:00
|
|
|
- Backwards compatibility is a feature. The RPC API in particular should
|
|
|
|
never break.
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
2016-06-12 23:11:12 -07:00
|
|
|
NVIM IS... WELL DOCUMENTED *design-documented*
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
- A feature that isn't documented is a useless feature. A patch for a new
|
|
|
|
feature must include the documentation.
|
2017-04-17 14:52:38 -07:00
|
|
|
- Documentation should be comprehensive and understandable. Use examples.
|
2014-07-10 21:05:51 -07:00
|
|
|
- Don't make the text unnecessarily long. Less documentation means that an
|
|
|
|
item is easier to find.
|
|
|
|
|
|
|
|
|
2016-06-12 23:11:12 -07:00
|
|
|
NVIM IS... HIGH SPEED AND SMALL IN SIZE *design-speed-size*
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2017-04-17 14:52:38 -07:00
|
|
|
Keep Nvim small and fast.
|
2014-07-10 21:05:51 -07:00
|
|
|
- Computers are becoming faster and bigger each year. Vim can grow too, but
|
|
|
|
no faster than computers are growing. Keep Vim usable on older systems.
|
|
|
|
- Many users start Vim from a shell very often. Startup time must be short.
|
|
|
|
- Commands must work efficiently. The time they consume must be as small as
|
|
|
|
possible. Useful commands may take longer.
|
|
|
|
- Don't forget that some people use Vim over a slow connection. Minimize the
|
|
|
|
communication overhead.
|
|
|
|
- Vim is a component among other components. Don't turn it into a massive
|
|
|
|
application, but have it work well together with other programs.
|
|
|
|
|
|
|
|
|
2016-06-12 23:11:12 -07:00
|
|
|
NVIM IS... MAINTAINABLE *design-maintain*
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
- The source code should not become a mess. It should be reliable code.
|
|
|
|
- Use comments in a useful way! Quoting the function name and argument names
|
|
|
|
is NOT useful. Do explain what they are for.
|
|
|
|
- Porting to another platform should be made easy, without having to change
|
|
|
|
too much platform-independent code.
|
|
|
|
- Use the object-oriented spirit: Put data and code together. Minimize the
|
|
|
|
knowledge spread to other parts of the code.
|
|
|
|
|
|
|
|
|
2015-01-14 00:02:39 -07:00
|
|
|
NVIM IS... NOT *design-not*
|
|
|
|
|
2016-06-14 20:12:43 -07:00
|
|
|
Nvim is not an operating system; instead it should be composed with other
|
|
|
|
tools or hosted as a component. Marvim once said: "Unlike Emacs, Nvim does not
|
2017-04-17 14:52:38 -07:00
|
|
|
include the kitchen sink... but it's good for plumbing."
|
2015-01-14 00:02:39 -07:00
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
==============================================================================
|
2017-03-14 16:12:21 -07:00
|
|
|
Developer guidelines *dev*
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2017-04-17 14:52:38 -07:00
|
|
|
|
|
|
|
PROVIDERS *dev-provider*
|
2016-06-14 22:20:08 -07:00
|
|
|
|
|
|
|
A goal of Nvim is to allow extension of the editor without special knowledge
|
|
|
|
in the core. But some Vim components are too tightly coupled; in those cases
|
|
|
|
a "provider" hook is exposed.
|
|
|
|
|
|
|
|
Consider two examples of integration with external systems that are
|
|
|
|
implemented in Vim and are now decoupled from Nvim core as providers:
|
|
|
|
|
|
|
|
1. In the Vim source code, clipboard logic accounts for more than 1k lines of
|
|
|
|
C source code (ui.c), to perform two tasks that are now accomplished with
|
|
|
|
shell commands such as xclip or pbcopy/pbpaste.
|
|
|
|
|
|
|
|
2. Python scripting support: Vim has three files dedicated to embedding the
|
|
|
|
Python interpreter: if_python.c, if_python3.c and if_py_both.h. Together
|
|
|
|
these files sum about 9.5k lines of C source code. In contrast, Nvim Python
|
|
|
|
scripting is performed by an external host process implemented in ~2k lines
|
|
|
|
of Python.
|
|
|
|
|
|
|
|
Ideally we could implement Python and clipboard integration in pure vimscript
|
|
|
|
and without touching the C code. But this is infeasible without compromising
|
|
|
|
backwards compatibility with Vim; that's where providers help.
|
|
|
|
|
|
|
|
The provider framework helps call vimscript from C. It is composed of two
|
|
|
|
functions in eval.c:
|
|
|
|
|
|
|
|
- eval_call_provider(name, method, arguments): calls provider#(name)#Call
|
|
|
|
with the method and arguments.
|
|
|
|
- eval_has_provider(name): Checks if a provider is implemented. Returns true
|
|
|
|
if the provider#(name)#Call function is implemented. Called by |has()|
|
|
|
|
(vimscript) to check if features are available.
|
|
|
|
|
|
|
|
The provider#(name)#Call function implements integration with an external
|
2016-06-14 22:59:28 -07:00
|
|
|
system, because shell commands and |RPC| clients are easier to work with in
|
|
|
|
vimscript.
|
2016-06-14 22:20:08 -07:00
|
|
|
|
|
|
|
For example, the Python provider is implemented by the
|
|
|
|
autoload/provider/python.vim script; the provider#python#Call function is only
|
|
|
|
defined if a valid external Python host is found. That works well with the
|
|
|
|
`has('python')` expression (normally used by Python plugins) because if the
|
|
|
|
Python host isn't installed then the plugin will "think" it is running in
|
|
|
|
a Vim compiled without the |+python| feature.
|
|
|
|
|
2017-03-14 16:12:21 -07:00
|
|
|
DOCUMENTATION *dev-doc*
|
|
|
|
|
|
|
|
- Do not prefix help tags with "nvim-". Use |vim_diff.txt| to document
|
|
|
|
differences from Vim; no other distinction is necessary.
|
|
|
|
- If a Vim feature is removed, delete its help section and move its tag to
|
|
|
|
|vim_diff.txt|.
|
|
|
|
- Move deprecated features to |deprecated.txt|.
|
|
|
|
- Use consistent language.
|
|
|
|
- "terminal" in a help tag always means "the embedded terminal emulator", not
|
|
|
|
"the user host terminal".
|
|
|
|
- Use "tui-" to prefix help tags related to the host terminal, and "TUI"
|
|
|
|
in prose if possible.
|
2016-06-14 22:20:08 -07:00
|
|
|
|
2017-04-17 14:52:38 -07:00
|
|
|
API *dev-api*
|
2016-09-16 21:30:36 -07:00
|
|
|
|
2017-12-27 11:30:23 -07:00
|
|
|
Use this template to name new API functions:
|
2016-09-16 21:30:36 -07:00
|
|
|
nvim_{thing}_{action}_{arbitrary-qualifiers}
|
|
|
|
|
|
|
|
If the function acts on an object then {thing} is the name of that object
|
|
|
|
(e.g. "buf" or "win"). If the function operates in a "global" context then
|
|
|
|
{thing} is usually omitted (but consider "namespacing" your global operations
|
|
|
|
with a {thing} that groups functions under a common concept).
|
|
|
|
|
|
|
|
Use existing common {action} names if possible:
|
2016-09-24 06:07:49 -07:00
|
|
|
add Append to, or insert into, a collection
|
|
|
|
get Get a thing (or subset of things by some query)
|
|
|
|
set Set a thing
|
|
|
|
del Delete a thing (or group of things)
|
|
|
|
list Get all things
|
2016-09-16 21:30:36 -07:00
|
|
|
|
2016-09-24 06:07:49 -07:00
|
|
|
Use consistent names for {thing} in all API functions. E.g. a buffer is called
|
2016-09-16 21:30:36 -07:00
|
|
|
"buf" everywhere, not "buffer" in some places and "buf" in others.
|
|
|
|
|
|
|
|
Example: `nvim_get_current_line` acts on the global editor state; the common
|
|
|
|
{action} "get" is used but {thing} is omitted.
|
|
|
|
|
|
|
|
Example: `nvim_buf_add_highlight` acts on a `Buffer` object (the first
|
|
|
|
parameter) and uses the common {action} "add".
|
|
|
|
|
|
|
|
Example: `nvim_list_bufs` operates in a global context (first parameter is
|
|
|
|
_not_ a Buffer). The common {action} "list" indicates that it lists all
|
|
|
|
bufs (plural) in the global context.
|
|
|
|
|
2017-12-27 11:30:23 -07:00
|
|
|
Use this template to name new API events:
|
|
|
|
nvim_{thing}_{event}_event
|
|
|
|
|
|
|
|
Example: `nvim_buf_changedtick_event`.
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2017-08-19 05:13:14 -07:00
|
|
|
API-CLIENT *dev-api-client*
|
|
|
|
|
2018-08-04 18:17:08 -07:00
|
|
|
Standard Features ~
|
|
|
|
|
|
|
|
- Clients should call |nvim_set_client_info()| after connecting, so users and
|
|
|
|
plugins can detect the client by handling the |ChanInfo| event. This
|
|
|
|
avoids the need for special variables or other client hints.
|
|
|
|
|
2017-08-19 05:13:14 -07:00
|
|
|
Package Naming ~
|
2018-08-04 18:17:08 -07:00
|
|
|
|
2017-08-19 05:13:14 -07:00
|
|
|
API client packages should NOT be named something ambiguous like "neovim" or
|
|
|
|
"python-client". Use "nvim" as a prefix/suffix to some other identifier
|
|
|
|
following ecosystem conventions.
|
|
|
|
|
|
|
|
For example, Python packages tend to have "py" in the name, so "pynvim" is
|
|
|
|
a good name: it's idiomatic and unambiguous. If the package is named "neovim",
|
|
|
|
it confuses users, and complicates documentation and discussions.
|
|
|
|
|
|
|
|
Examples of API-client package names:
|
|
|
|
GOOD: nvim-racket
|
|
|
|
GOOD: pynvim
|
|
|
|
BAD: python-client
|
|
|
|
BAD: neovim
|
|
|
|
|
|
|
|
Implementation ~
|
|
|
|
|
2018-08-04 18:17:08 -07:00
|
|
|
Consider using libmpack instead of the msgpack.org C/C++ library. libmpack is
|
|
|
|
small (can be inlined into your C/C++ project) and efficient (no allocations).
|
|
|
|
It also implements msgpack-RPC.
|
|
|
|
https://github.com/libmpack/libmpack/
|
2017-08-19 05:13:14 -07:00
|
|
|
|
2017-04-17 14:52:38 -07:00
|
|
|
EXTERNAL UI *dev-ui*
|
|
|
|
|
|
|
|
External UIs should be aware of the |api-contract|. In particular, future
|
2017-08-19 05:13:14 -07:00
|
|
|
versions of Nvim may add new items to existing events. The API is strongly
|
2018-06-27 15:48:17 -07:00
|
|
|
backwards-compatible, but clients must not break if new (optional) fields are
|
|
|
|
added to existing events.
|
2017-04-17 14:52:38 -07:00
|
|
|
|
2018-08-04 18:17:08 -07:00
|
|
|
Standard Features ~
|
|
|
|
|
2017-08-19 05:13:14 -07:00
|
|
|
External UIs are expected to implement these common features:
|
2018-08-04 18:17:08 -07:00
|
|
|
|
|
|
|
- Call |nvim_set_client_info()| after connecting, so users and plugins can
|
|
|
|
detect the UI by handling the |ChanInfo| event. This avoids the need for
|
|
|
|
special variables and UI-specific config files (gvimrc, macvimrc, …).
|
2018-06-27 15:48:17 -07:00
|
|
|
- Cursor style (shape, color) should conform to the 'guicursor' properties
|
2017-08-19 05:13:14 -07:00
|
|
|
delivered with the mode_info_set UI event.
|
2017-12-27 11:30:23 -07:00
|
|
|
- Send the ALT/META ("Option" on macOS) key as a |<M-| chord.
|
2017-08-19 05:13:14 -07:00
|
|
|
- Send the "super" key (Windows key, Apple key) as a |<D-| chord.
|
2018-06-27 15:48:17 -07:00
|
|
|
- Avoid mappings that conflict with the Nvim keymap-space; GUIs have many new
|
|
|
|
chords (<C-,> <C-Enter> <C-S-x> <D-x>) and patterns ("shift shift") that do
|
|
|
|
not potentially conflict with Nvim defaults, plugins, etc.
|
|
|
|
- Consider the "option_set" |ui-global| event as a hint for other GUI
|
|
|
|
behaviors. UI-related options ('guifont', 'ambiwidth', …) are published in
|
|
|
|
this event.
|
2017-04-17 14:52:38 -07:00
|
|
|
|
|
|
|
|
2018-10-29 01:50:39 -07:00
|
|
|
vim:tw=78:ts=8:noet:ft=help:norl:
|