This release represents ~2700 commits since v0.3.4, the previous non-maintenance release. Besides the highlights listed below, this release features vast improvements to documentation, internal subsystems and test/CI infrastructure, and 700+ patches merged from Vim. FEATURES: New API functions: nvim_create_buf: create various kinds of buffers nvim_get_context, nvim_load_context8e6b0a73c9
#10619 API: Context: save/restore/inspect editor state nvim_input_mouse: perform mouse actions nvim_open_win: create floating windows (and external, for supporting UIs) nvim_paste: paste text at cursor nvim_put: put text at cursor nvim_select_popupmenu_item: perform popupmenu actions nvim_set_keymap: create/delete mappings nvim_set_vvar: set v: variables nvim_ui_pum_set_height nvim_ui_try_resize_grid nvim_win_close: close windows nvim_win_get_config: get window configuration nvim_win_set_config: reconfigure windows New UI events: redraw.grid_destroy redraw.hl_group_set8a3f8589a3
#10504 UI/highlight: expose builtin highlight groups using hl_group_set event redraw.msg_clear redraw.msg_history_show redraw.msg_ruler redraw.msg_set_pos redraw.msg_show redraw.msg_showcmd redraw.msg_showmode redraw.win_close redraw.win_external_pos redraw.win_float_pos redraw.win_hide redraw.win_pos APIf5c56f03bb
#9170 API/Lua: nvim_buf_attach: support Lua callback82d48c0dab
#9896 API: emit nvim_error_event on failed async requestb9ad12e6c2
#9992 UI/nvim_ui_attach(): add `override` option3d1ed7c959
#9993 UI/ext_messages: learn more message kinds8ed54bbec3
#9547 proper multiline error message for rpcrequest, API wrappers Lua This release introduces "Nvim-Lua standard library". See ":help lua-stdlib".89d7e24891
#9463 Lua stdlib: vim.inspect, string functions8e941c59ec
#9740 Lua: generate documentation from docstrings1cbe014569
#9301 lua/stdlib: Introduce vim.sharedc83926cd0a
#10123 Lua: introduce vim.loop (expose libuv event-loop)81e1dbca99
#10120 Lua: vim.schedule(cb)1f54f68732
#10688 Lua: minimal UTF-16 support needed for LSP6fb0020df4
#10513 Lua encoding supportc0993ed343
Lua: support getting UTF-32 and UTF-16 sizes of replaced textb0e26199ec
Lua: add {old_byte_size} to on_lines buffer change event UI: - The Nvim 0.3.4 UI protocol introduced line-based updates instead of legacy char-based updates. Nvim 0.4 continues to evolve the UI protocol. See ":help ui". Legacy UI clients are supported. See ":help api-contract".9a1675b065
#6619 Floating windows - Can be (re)positioned, anchored, external. - Are real windows showing real buffers. No shortcuts, hacks, or compromises. - Support all features and API of normal windows, plus more.6427894d89
#8455 Multigrid: "windows drawn on separate grids" - Windows are logically isolated internally. - Windows are sent to UIs as distinct objects, so that UIs can control layout instead of being stuck with the classic TUI layout. - Per-window font-size, dimenions, line-spacing. - Compositor: Internal subsystem for composing grids.3855204f58
#6917 UIEnter, UILeave788bcbba24
#9923 ui: ":syn blend=", 'winblend'7cf7c0a0b8
#9575 ui: 'redrawdebug' option for flexible debugging of redrawing5c836d2ef8
#9607 wildoptions=pum (enabled by default)37f8df8824
#9571 UI: 'pumblend' option for semi-transparent popupmenuc403a95a52
#9446 Visual: highlight char-at-cursor - Traditionally Vim's visual selection does "reverse mode", which perhaps conflicts with the non-blinking block cursor. But 'guicursor' defaults to a vertical bar for selection=exclusive, and this confuses users who expect to see the text highlighted. :terminalfc27dc98d7
#8550 autocmds: TermEnter, TermLeaved13803f64f
#9810 keymap, terminal: more keycodes3b56f59532
#9535 :terminal : Fix F1-F4 key codes2d4a37ebab
#10370 :ls : show "R", "F" for terminal-jobsfd0fd752c8
#9966 terminal: swap priority of terminal, editor highlights7bb858c39c
#9494 libvterm 0.1 TUI3afb397407
syntax, TUI: support "strikethrough"ccbcd390d4
#9408 TUI: "title stacking" unconditionally298608f88c
#9509 TUI: detect background color, set bg=dark/light42f492ac99
#9097 TUI: handle Smulx extension capability (extended underline)424ddd01f5
#10205 TUI: support rgba background detection9b4383261a
#9601 TUI: italics in tmux, Terminal.appf6fb370b1b
#9793 keymap: support more (keypad) keycodes3340e08bec
#9423 TUI: Konsole DECSCUSR fixup :checkhealthd0fd66ba82
health/provider.vim: check curl HTTPS supportc38862acea
#10490 checkhealth: try yarn if npm is missing43356a43d0
#9929 health: check if tmux enabled true colorsec5a4d862d
#9548 checkhealth: validate locale providers (clipboard, python, etc.):96be8a2c4d
#10161 Allow reloading providers (useful for UIs/clients)db3c797c6b
#9487 provider: improve error message if provider is missing Various:36762a00a8
#9295 signs: support multiple columns801fe799ff
#10382 eval: wait() (wait for any condition)9df3a676e7
#10400 MsgArea highlight; message grida9bea8c104
#10790 keymap: allow modifiers to multibyte chars, like <m-ä>25e0a449bb
#10878 #4448 paste: redesign (10x+ faster pasting; extensible vim.paste Lua hook)ef5037e7f6
#9706 autocmd: introduce "++once" feature175398f216
#9616 add CompleteChanged autocmd7fcf2f926f
#9717 TextYankPost: add v:event["inclusive"]3a699a790c
#8364 termdebug.vim pluginca1ce59025
#9709 performance: use os_copy to create backupsed0e96cd28
man.vim: set 'linebreak'70f6939fd4
#9564 events: add "Signal" eventf89d0d8230
#9568 inccommand: auto-disable if folding is slow FIXES:41bb68b8e8
#10584 process_stop: uv: do not close stdin first/explicitlye50aa2a6c6
#10117 normal: Don't exit CTRL-O mode after processing K_EVENT95fa71c6d2
#9504 :recover : Fix crash on non-existent *.swp5a836d4767
#9507 screen: don't unconditionally clear messages on window scroll149dcbf2c7
#10021 channel: refactor events, prevent recursive invocation of eventsd19ff73b39
#10107 Fix multiple c_CTRL-D showing statuslineb65a7b7f66
#10103 Fix wildmode=list,full and display+=msgsep interaction0be6d3c86f
#9634 fsync: Ignore ENOTSUP. Fix writing to SMB.b247c6fd22
#10025 kbtree: pointer UB and unitialized value fixes018e0d5a19
#9643 API/buffer-updates: always detach on buf-reload400ee59247
#9961 API: fix cursor position when lines are added769f44e918
#9911 win/defaults: Use "…/nvim-data/site" in 'runtimepath'83d571653b
#9911 spellfile.vim: store files in stdpath('data')8dbf23181a
#9887 RPC: conform message-id type to msgpack-RPC spec5f996e36d1
#9894 options: properly reset directories on 'autochdir'4c4a570156
#9807 various CursorMoved fixes943bedfc86
#9853 event-loop: do not set CA_COMMAND_BUSY9d207fd876
#9693 dictwatcheradd(): support b:changedtick2d50bf3498
#9789 mac: fix locale detectionc5631338b1
#9754 :mksession : restore tab-local working directories092e7e6c60
#9703 #9703 executable(): return false if user is not owner11a481f711
#9686 env var fixes/improvements8e54847fdf
#9666 #7920 os/env: Fix completion of multibyte env var names519382646b
#10468 Fix is_executable_in_path() on Windows8eaa452073
#9516 win: exepath(), executable() fixesf55c1e4233
#10544 reltimefloat(): allow negative resultb08dc3ec19
#10561 win: jobstart(), system(): $PATHEXT-resolve exe7cc2b723d4
#10392 TextYankPost: spurious/too-early dispatch during delete6e01ed6a4c
OpenBSD: stop jobs/processes properly58dd5fcc01
#10522 jobstop(): close channel before process_stop()83632022f8
#10959 improved resize behavior (all UIs)c6eb1f42be
#10830 API: fix nvim_command_output buffer overflowcbfd18c85a
#10763 startup: handle 'guicursor' after user configb8f2436feb
#10915 jobwait(): fix race if job exits quickly2fafed6bb8
#10765 clipboard: handle/avoid SIGTERM with previous owner8aca932aa0
#9954 clipboard: setreg("*") with clipboard=unnamed3f10c5b533
#9480 performance: clipboard/macOS: assume that pbcopy works48efafc81c
#10398 screen: disable redrawing inside VimResized5e4b93a38f
#10389 API/Lua: make nvim_execute_lua use native lua floats, not special tables8c6f5b7f92
#9934 Spurious quote mark in command line when typing <C-R>a8a38f3465
Lua 5.2/5.3 compat :terminal47b7b471fa
#10700 :terminal : update buffer when switching tabpage5225c1ec30
#9605 terminal: Fix potential invalid local 'scrollback'894f6bee54
#8325 :terminal : set topline based on window height8171e96b96
#9551 Improve :terminal resized928b036dc
#9856 :stopinsert should leave terminal-mode3f71218505
#9926 :terminal : fix: Using `:stopinsert` while in normal mode5020daa6e5
#9883 ui/terminal: make terminal state redraw like any other state TUI:9f19e8d29d
#9443 TUI: Do not disable BCE for builtin terminfosa4076e5dcf
#9474 win/TUI: fix text overrides line numbers533d4a36ec
#9645 TUI: do not resize host-terminal on startupb51e5d8b8d
#9688 tui_tk_ti_getstr: handle weird value1f5eac1115
#10785 TUI: fix data-race during resize CHANGES:9697c7f56a
#8194 fix menu_get()7f2e43c637
#9520 improve Lua error messagesc2343180d7
#9526 Remove jemallocbaf93d9606
#9581 UI: always use concrete colors for default_colors_set91688b4883
#9563 defaults: set 'scrollback' to -1 by defaultbb24fec333
#10136 defaults: exclude "S" from 'shortmess'ddd0eb6f51
#8540 startup: -es/-Es (silent/batch mode): skip swapfile35362495c9
#9805 jumplist: avoid extra tail entry939d9053bd
#10573 channels: reflect exit due to signals in exit status code45c34bd84a
#10689 :doautocmd : Never show "No matching autocommands"fb19aeeb33
#9110 API: make nvim_win_set_option() set window-global, not buffer-localabfc8b3257
#10778 emsg_multiline: log Vim errors06d9cc734b
#10657 exists("$FOO"): return false for empty env var6616d1d3e5
#10743 win/env: Vim-compat: Empty string deletes env var7d664837e1
#10662 win: expand nested env var in $HOME2816bc8620
#8349 edit.c: Disable indent during completion58f505dc74
#9829 startup: remove TUI init special-case Historically Vim/Nvim does backflips to handle input and show messages before a UI is available. This logical contradiction was already fixed for remote UIs (#9024c236e80cf3
). Fixing it also for the TUI avoids problems on Windows, simplifies the logic, and avoids races like #9959.
Tests
Tests are broadly divided into unit tests (test/unit), functional tests (test/functional), and old tests (src/nvim/testdir/).
- Unit testing is achieved by compiling the tests as a shared library which is loaded and called by LuaJit FFI.
- Functional tests are driven by RPC, so they do not require LuaJit (as opposed to Lua).
You can learn the key concepts of Lua in 15 minutes. Use any existing test as a template to start writing new tests.
Tests are run by /cmake/RunTests.cmake
file, using busted
(a Lua test-runner).
For some failures, .nvimlog
(or $NVIM_LOG_FILE
) may provide insight.
Depending on the presence of binaries (e.g., xclip
) some tests will be
ignored. You must compile with libintl to prevent E319: The command is not available in this version
errors.
Layout
/test/benchmark
: benchmarks/test/functional
: functional tests/test/unit
: unit tests/test/config
: contains*.in
files which are transformed into*.lua
files usingconfigure_file
CMake command: this is for acessing CMake variables in lua tests./test/includes
: include-files for use by luajitffi.cdef
C definitions parser: normally used to make macros not accessible via this mechanism accessible the other way./test/*/preload.lua
: modules preloaded by busted--helper
option/test/**/helpers.lua
: common utility functions for test code/test/*/**/*_spec.lua
: actual tests. Files that do not end with_spec.lua
are libraries like/test/**/helpers.lua
, except that they have some common topic./src/nvim/testdir
: old tests (from Vim)
Running tests
Executing Tests
To run all tests (except "old" tests):
make test
To run only unit tests:
make unittest
To run only functional tests:
make functionaltest
Legacy tests
To run all legacy Vim tests:
make oldtest
To run a single legacy test set TEST_FILE
, for example:
TEST_FILE=test_syntax.res make oldtest
- The
.res
extension (instead of.vim
) is required. - Specify only the test file name, not the full path.
Debugging tests
-
You can set
$GDB
to run tests under gdbserver. And if$VALGRIND
is set it will pass--vgdb=yes
to valgrind instead of starting gdbserver directly. -
Hanging tests often happen due to unexpected
:h press-enter
prompts. The default screen width is 50 columns. Commands that try to print lines longer than 50 columns in the command-line, e.g.:edit very...long...path
, will trigger the prompt. In this case, a shorter path or:silent edit
should be used. -
If you can't figure out what is going on, try to visualize the screen. Put this at the beginning of your test:
local Screen = require('test.functional.ui.screen') local screen = Screen.new() screen:attach()
Afterwards, put
screen:snapshot_util()
at any position in your test. See the comment at the top oftest/functional/ui/screen.lua
for more.
Filtering Tests
Filter by name
Another filter method is by setting a pattern of test name to TEST_FILTER
.
it('foo api',function()
...
end)
it('bar api',function()
...
end)
To run only test with filter name:
TEST_TAG='foo.*api' make functionaltest
Filter by file
To run a specific unit test:
TEST_FILE=test/unit/foo.lua make unittest
To run a specific functional test:
TEST_FILE=test/functional/foo.lua make functionaltest
To repeat a test:
BUSTED_ARGS="--repeat=100 --no-keep-going" TEST_FILE=test/functional/foo_spec.lua make functionaltest
Filter by tag
Tests can be "tagged" by adding #
before a token in the test description.
it('#foo bar baz', function()
...
end)
it('#foo another test', function()
...
end)
To run only the tagged tests:
TEST_TAG=foo make functionaltest
NOTE:
TEST_FILE
is not a pattern string likeTEST_TAG
orTEST_FILTER
. The given value toTEST_FILE
must be a path to an existing file.- Both
TEST_TAG
andTEST_FILTER
filter tests by the string descriptions found init()
anddescribe()
.
Writing tests
Guidelines
- Luajit needs to know about type and constant declarations used in function
prototypes. The
helpers.lua
file automatically parses
types.h
, so types used in the tested functions could be moved to it to avoid having to rewrite the declarations in the test files.#define
constants must be rewrittenconst
orenum
so they can be "visible" to the tests.
- Use pending() to skip tests
(example).
Do not silently skip the test with
if-else
. If a functional test depends on some external factor (e.g. the existence ofmd5sum
on$PATH
), and you can't mock or fake the dependency, then skip the test viapending()
if the external factor is missing. This ensures that the total test-count (success + fail + error + pending) is the same in all environments.- Note:
pending()
is ignored if it is missing an argument, unless it is contained in anit()
block. Provide empty function argument if thepending()
call is outside ofit()
(example).
- Note:
- Really long
source([=[...]=])
blocks may break Vim's Lua syntax highlighting. Try:syntax sync fromstart
to fix it.
Where tests go
Tests in /test/unit
and /test/functional
are divided into groups
by the semantic component they are testing.
- Unit tests
(test/unit) should
match 1-to-1 with the structure of
src/nvim/
, because they are testing functions directly. E.g. unit-tests forsrc/nvim/undo.c
should live intest/unit/undo_spec.lua
. - Functional tests
(test/functional)
are higher-level (plugins and user input) than unit tests; they are organized
by concept.
- Try to find an existing
test/functional/*/*_spec.lua
group that makes sense, before creating a new one.
- Try to find an existing
Lint
make lint
(and make lualint
) runs luacheck
on the test code.
If a luacheck warning must be ignored, specify the warning code. Example:
-- luacheck: ignore 621
http://luacheck.readthedocs.io/en/stable/warnings.html
Ignore the smallest applicable scope (e.g. inside a function, not at the top of the file).
Configuration
Test behaviour is affected by environment variables. Currently supported (Functional, Unit, Benchmarks) (when Defined; when set to 1; when defined, treated as Integer; when defined, treated as String; when defined, treated as Number; !must be defined to function properly):
-
BUSTED_ARGS
(F) (U): arguments forwarded tobusted
. -
GDB
(F) (D): makes nvim instances to be run undergdbserver
. It will be accessible onlocalhost:7777
: usegdb build/bin/nvim
, typetarget remote :7777
inside. -
GDBSERVER_PORT
(F) (I): overrides port used forGDB
. -
VALGRIND
(F) (D): makes nvim instances to be run undervalgrind
. Log files are namedvalgrind-%p.log
in this case. Note that non-empty valgrind log may fail tests. Valgrind arguments may be seen in/test/functional/helpers.lua
. May be used in conjunction withGDB
. -
VALGRIND_LOG
(F) (S): overrides valgrind log file name used forVALGRIND
. -
TEST_SKIP_FRAGILE
(F) (D): makes test suite skip some fragile tests. -
NVIM_PROG
,NVIM_PRG
(F) (S): override path to Neovim executable (default tobuild/bin/nvim
). -
CC
(U) (S): specifies which C compiler to use to preprocess files. Currently only compilers with gcc-compatible arguments are supported. -
NVIM_TEST_MAIN_CDEFS
(U) (1): makesffi.cdef
run in main process. This raises a possibility of bugs due to conflicts in header definitions, despite the counters, but greatly speeds up unit tests by not requiringffi.cdef
to do parsing of big strings with C definitions. -
NVIM_TEST_PRINT_I
(U) (1): makescimport
print preprocessed, but not yet filtered throughformatc
headers. Used to debugformatc
. Printing is done with the line numbers. -
NVIM_TEST_PRINT_CDEF
(U) (1): makescimport
print final lines which will be then passed toffi.cdef
. Used to debug errorsffi.cdef
happens to throw sometimes. -
NVIM_TEST_PRINT_SYSCALLS
(U) (1): makes it print to stderr when syscall wrappers are called and what they returned. Used to debug code which makes unit tests be executed in separate processes. -
NVIM_TEST_RUN_FAILING_TESTS
(U) (1): makesitp
run tests which are known to fail (marked by setting third argument totrue
). -
LOG_DIR
(FU) (S!): specifies where to seek for valgrind and ASAN log files. -
NVIM_TEST_CORE_*
(FU) (S): a set of environment variables which specify where to search for core files. Are supposed to be defined all at once. -
NVIM_TEST_CORE_GLOB_DIRECTORY
(FU) (S): directory where core files are located. May be.
. This directory is then recursively searched for core files. Note: this variable must be defined for any of the following to have any effect. -
NVIM_TEST_CORE_GLOB_RE
(FU) (S): regular expression which must be matched by core files. E.g./core[^/]*$
. May be absent, in which case any file is considered to be matched. -
NVIM_TEST_CORE_EXC_RE
(FU) (S): regular expression which excludes certain directories from searching for core files inside. E.g. use^/%.deps$
to not search inside/.deps
. If absent, nothing is excluded. -
NVIM_TEST_CORE_DB_CMD
(FU) (S): command to get backtrace out of the debugger. E.g.gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"
. Defaults to the example command. This debug command may use environment variables_NVIM_TEST_APP
(path to application which is being debugged: normally either nvim or luajit) and_NVIM_TEST_CORE
(core file to get backtrace from). -
NVIM_TEST_CORE_RANDOM_SKIP
(FU) (D): makescheck_cores
not check cores after approximately 90% of the tests. Should be used when finding cores is too hard for some reason. Normally (on OS X or whenNVIM_TEST_CORE_GLOB_DIRECTORY
is defined and this variable is not) cores are checked for after each test. -
NVIM_TEST_RUN_TESTTEST
(U) (1): allows runningtest/unit/testtest_spec.lua
used to check how testing infrastructure works. -
NVIM_TEST_TRACE_LEVEL
(U) (N): specifies unit tests tracing level:0
disables tracing (the fastest, but you get no data if tests crash and there was no core dump generated),1
or empty/undefined leaves only C function cals and returns in the trace (faster then recording everything),2
records all function calls, returns and lua source lines exuecuted. -
NVIM_TEST_TRACE_ON_ERROR
(U) (1): makes unit tests yield trace on error in addition to regular error message. -
NVIM_TEST_MAXTRACE
(U) (N): specifies maximum number of trace lines to keep. Default is 1024.