neovim/src/nvim
2023-04-22 14:18:24 +02:00
..
api fix(api): avoid integer truncation 2023-04-21 12:14:44 +02:00
eval fix(userfunc): fix possible out of bound access 2023-04-21 12:14:48 +02:00
event refactor: remove use of reserved c++ keywords 2023-04-06 22:39:50 +02:00
generators refactor(build): move the last generator from scripts/ to src/nvim/generators 2023-04-21 16:46:35 +02:00
lib build: remove clint error suppression #21782 2023-01-13 15:48:10 -08:00
lua build: update uncrustify to 0.76 2023-04-19 17:04:00 +01:00
msgpack_rpc build: update uncrustify to 0.76 2023-04-19 17:04:00 +01:00
os refactor(env): remove unused mutex 2023-04-20 18:54:00 +02:00
po refactor: remove :CheckHealth 2023-04-12 00:01:34 +02:00
tui build: update uncrustify to 0.76 2023-04-19 17:04:00 +01:00
viml/parser vim-patch:9.0.1380: CTRL-X on 2**64 subtracts two (#22530) 2023-03-05 09:18:42 +08:00
arabic.c build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
arabic.h
arglist.c vim-patch:9.0.1472: ":drop fname" may change the last used tab page (#23230) 2023-04-21 09:02:30 +08:00
arglist.h
ascii.h refactor: clang-tidy fixes to silence clangd warning (#20683) 2022-10-21 20:47:44 +08:00
assert.h build: remove clint error suppression #21782 2023-01-13 15:48:10 -08:00
auevents.lua feat(lsp)!: add rule-based sem token highlighting (#22022) 2023-03-06 19:03:13 +01:00
autocmd.c vim-patch:9.0.1443: ending Insert mode when accessing a hidden prompt buffer (#22984) 2023-04-10 07:33:26 +08:00
autocmd.h vim-patch:9.0.1443: ending Insert mode when accessing a hidden prompt buffer (#22984) 2023-04-10 07:33:26 +08:00
buffer_defs.h fix(ui): recording change doesn't trigger statusline redraw 2023-04-01 04:23:25 +02:00
buffer_updates.c fix(buffer_updates): save and restore current window cursor (#16732) 2023-03-09 10:19:00 +08:00
buffer_updates.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
buffer.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
buffer.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
bufwrite.c vim-patch:8.1.2094: the fileio.c file is too big 2023-04-19 13:15:29 +01:00
bufwrite.h vim-patch:8.1.2094: the fileio.c file is too big 2023-04-19 13:15:29 +01:00
change.c refactor: remove redundant casts 2023-04-07 21:08:16 +02:00
change.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
channel.c refactor: remove redundant const char * casts 2023-04-07 19:40:57 +02:00
channel.h refactor: remove use of reserved c++ keywords 2023-04-06 22:39:50 +02:00
charset.c refactor: remove redundant const char * casts 2023-04-07 19:40:57 +02:00
charset.h refactor: remove char_u (#22829) 2023-04-02 16:11:42 +08:00
CMakeLists.txt fix(cmake): restore previously undocumented workround, now documented 2023-04-22 14:18:24 +02:00
cmdexpand.c feat(ex_cmds)!: remove :behave 2023-04-13 12:15:30 +02:00
cmdexpand.h vim-patch:8.2.4579: cannot use page-up and page-down in the cmdline popup menu 2023-01-15 07:36:58 +08:00
cmdhist.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
cmdhist.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
context.c feat(api): nvim_exec2(), deprecate nvim_exec() #19032 2023-03-25 09:58:48 -07:00
context.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
cursor_shape.c build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
cursor_shape.h
cursor.c refactor: replace char_u with char (#21901) 2023-02-11 11:05:57 +01:00
cursor.h
debugger.c vim-patch:8.2.1080: Vim9: no line break allowed in a for loop 2023-04-14 16:10:09 +08:00
debugger.h
decoration_provider.c build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
decoration_provider.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
decoration.c feat(api): evaluate 'statuscolumn' with nvim_eval_statusline() 2023-04-05 12:36:47 +02:00
decoration.h refactor(extmarks): some minor internal API changes 2023-03-16 13:56:05 +01:00
diff.c vim-patch:8.1.2094: the fileio.c file is too big 2023-04-19 13:15:29 +01:00
diff.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
digraph.c vim-patch:8.2.1049: Vim9: leaking memory when using continuation line 2023-04-14 09:42:59 +08:00
digraph.h
drawline.c fix(drawline): initialize variable 2023-04-21 12:14:48 +02:00
drawline.h refactor(screen): screen.c delenda est 2023-03-14 13:37:43 +01:00
drawscreen.c fix(column): rebuild status column when sign column is invalid 2023-04-19 03:22:27 +02:00
drawscreen.h refactor(screen): screen.c delenda est 2023-03-14 13:37:43 +01:00
edit.c refactor: remove redundant const char * casts 2023-04-07 19:40:57 +02:00
edit.h vim-patch:9.0.0761: cannot use 'indentexpr' for Lisp indenting 2022-10-16 08:34:55 +08:00
eval.c refactor(eval): use tv_list_append_allocated_string() 2023-04-19 11:29:35 +08:00
eval.h vim-patch:8.2.1161: Vim9: using freed memory 2023-04-14 16:10:09 +08:00
eval.lua vim-patch:9.0.1007: there is no way to get a list of swap file names 2023-04-19 11:29:35 +08:00
ex_cmds2.c vim-patch:8.1.2094: the fileio.c file is too big 2023-04-19 13:15:29 +01:00
ex_cmds2.h vim-patch:8.2.1269: language and locale code spread out (#19964) 2022-08-27 11:26:47 +08:00
ex_cmds_defs.h vim-patch:8.2.1049: Vim9: leaking memory when using continuation line 2023-04-14 09:42:59 +08:00
ex_cmds.c vim-patch:8.1.2094: the fileio.c file is too big 2023-04-19 13:15:29 +01:00
ex_cmds.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
ex_cmds.lua fix(excmd): make :def unknown rather than unimplemented (#23150) 2023-04-17 17:44:08 +08:00
ex_docmd.c fix(excmd): make :def unknown rather than unimplemented (#23150) 2023-04-17 17:44:08 +08:00
ex_docmd.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
ex_eval_defs.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
ex_eval.c vim-patch:9.0.0370: cleaning up afterwards can make a function messy 2023-04-16 15:04:40 +08:00
ex_eval.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
ex_getln.c fix(ex_getln): initialize pointer with NULL 2023-04-21 12:14:48 +02:00
ex_getln.h refactor: replace char_u with char 23 (#21798) 2023-01-18 18:52:19 +08:00
ex_session.c refactor: add const and remove unnecessary casts (#22841) 2023-04-01 08:49:51 +08:00
ex_session.h
extmark_defs.h feat(ui): add support to display a title in the border of a float (#20184) 2022-11-06 11:59:43 +01:00
extmark.c feat(extmarks): extend nvim_buf_get_extmarks() 2023-04-01 13:59:03 +02:00
extmark.h feat(extmarks): extend nvim_buf_get_extmarks() 2023-04-01 13:59:03 +02:00
file_search.c vim-patch:9.0.1400: find_file_in_path() is not reentrant (#23146) 2023-04-17 14:38:53 +08:00
file_search.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
fileio.c refactor: fix PVS warnings (#23200) 2023-04-19 22:49:14 +08:00
fileio.h vim-patch:8.1.2094: the fileio.c file is too big 2023-04-19 13:15:29 +01:00
fold_defs.h perf(column): only build fold/sign column when present in 'statuscolumn' 2023-02-04 11:04:43 +01:00
fold.c vim-patch:8.2.4179: 'foldtext' is evaluated in the current script context 2023-04-17 15:46:24 +08:00
fold.h perf(column): only build fold/sign column when present in 'statuscolumn' 2023-02-04 11:04:43 +01:00
func_attr.h build: sanitizers for gcc 2023-03-16 18:33:41 +01:00
garray.c refactor: use uint8_t for blobs and ga_append() (#21916) 2023-01-21 09:24:09 +08:00
garray.h docs: fix typos (#21961) 2023-02-20 15:12:59 +08:00
getchar.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
getchar.h
gettext.h refactor: make error message definitions const 2023-04-05 21:13:53 +02:00
globals.h vim-patch:9.0.0419: the :defer command does not check the function arguments 2023-04-17 09:38:09 +08:00
grid_defs.h refactor: replace char_u with char or uint8_t (#22400) 2023-03-04 20:10:00 +08:00
grid.c refactor: remove use of reserved c++ keywords 2023-04-06 22:39:50 +02:00
grid.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
hashtab.c fix(api): make nvim_get_hl return 'cterm' attrs properly 2023-03-23 13:42:00 +01:00
hashtab.h vim-patch:8.2.1208: build failure 2022-12-17 08:58:50 +08:00
help.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
help.h
highlight_defs.h feat(api): evaluate 'statuscolumn' with nvim_eval_statusline() 2023-04-05 12:36:47 +02:00
highlight_group.c fix(api): make nvim_get_hl not return non-existing groups 2023-04-13 14:17:12 +02:00
highlight_group.h refactor(api): make typed dicts appear as types in the source code 2023-04-07 21:30:21 +02:00
highlight.c refactor(api): make typed dicts appear as types in the source code 2023-04-07 21:30:21 +02:00
highlight.h refactor(api): make typed dicts appear as types in the source code 2023-04-07 21:30:21 +02:00
iconv.h feat!: make iconv a non-optional dep 2023-01-23 16:33:45 +00:00
indent_c.c vim-patch:9.0.1426: indent wrong after "export namespace" in C++ (#22777) 2023-03-25 09:27:42 +08:00
indent_c.h
indent.c vim-patch:8.2.4185: cannot use an import in 'indentexpr' 2023-04-17 15:46:24 +08:00
indent.h vim-patch:9.0.0761: cannot use 'indentexpr' for Lisp indenting 2022-10-16 08:34:55 +08:00
input.c refactor(getchar.c): change most char_u to uint8_t (#22444) 2023-02-28 08:49:02 +08:00
input.h
insexpand.c refactor: remove redundant casts 2023-04-07 21:08:16 +02:00
insexpand.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
keycodes.c refactor(mappings)!: remove #n as a notation for a function key (#17318) 2023-04-08 20:29:23 +08:00
keycodes.h refactor: replace char_u with char (#21901) 2023-02-11 11:05:57 +01:00
linematch.c fix(linematch): initialize array 2023-04-21 12:14:48 +02:00
linematch.h Enable new diff option linematch (#14537) 2022-11-04 09:07:22 +00:00
log.c build: update uncrustify to 0.76 2023-04-19 17:04:00 +01:00
log.h refactor(log): reduce compile time LOG_LEVEL granularity 2023-03-04 15:26:17 +01:00
macros.h build: update uncrustify to 0.76 2023-04-19 17:04:00 +01:00
main.c refactor(env): remove unused mutex 2023-04-20 18:54:00 +02:00
main.h fix(ui): re-organize tty fd handling and fix issues 2023-01-16 11:26:49 +01:00
map_defs.h refactor: move klib out of src/nvim/ #20341 2022-09-25 06:26:37 -07:00
map.c build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
map.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
mapping.c vim-patch:8.2.1049: Vim9: leaking memory when using continuation line 2023-04-14 09:42:59 +08:00
mapping.h refactor(api): make typed dicts appear as types in the source code 2023-04-07 21:30:21 +02:00
mark_defs.h refactor: migrate comment style 2 #20080 2022-09-06 07:23:00 -07:00
mark.c fix(mark): properly init mark views (#22996) 2023-04-10 22:49:32 +08:00
mark.h fix(mark): properly init mark views (#22996) 2023-04-10 22:49:32 +08:00
marktree.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
marktree.h refactor(extmarks): some minor internal API changes 2023-03-16 13:56:05 +01:00
match.c refactor: remove redundant const char * casts 2023-04-07 19:40:57 +02:00
match.h
math.c build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
math.h
mbyte_defs.h feat!: make iconv a non-optional dep 2023-01-23 16:33:45 +00:00
mbyte.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
mbyte.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
memfile_defs.h refactor: replace char_u with char 20 (#21714) 2023-01-13 07:35:39 +08:00
memfile.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
memfile.h
memline_defs.h vim-patch:partial:9.0.0013: reproducing memory access errors can be difficult 2023-03-04 13:53:09 +08:00
memline.c refactor: fix PVS warnings (#23200) 2023-04-19 22:49:14 +08:00
memline.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
memory.c vim-patch:9.0.0749: alloc/free of buffer for each quickfix entry is inefficient 2023-03-05 17:02:24 +08:00
memory.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
menu_defs.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
menu.c refactor: remove redundant casts 2023-04-07 21:08:16 +02:00
menu.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
message.c refactor: remove redundant const char * casts 2023-04-07 19:40:57 +02:00
message.h fix(messages): reset msg_grid_scroll_discount when redrawing (#21000) 2022-11-10 06:16:54 +08:00
mouse.c fix(mouse): cmdline click registered as statuscolumn (#23163) 2023-04-18 08:00:49 +08:00
mouse.h feat(ui): add 'statuscolumn' option 2023-01-09 17:12:06 +00:00
move.c refactor: use bool type for global variables (#22842) 2023-04-01 08:56:44 +08:00
move.h
normal.c build: update uncrustify to 0.76 2023-04-19 17:04:00 +01:00
normal.h refactor: fix IWYU mapping file and use IWYU (#21802) 2023-01-15 14:16:33 +01:00
ops.c vim-patch:8.2.1049: Vim9: leaking memory when using continuation line 2023-04-14 09:42:59 +08:00
ops.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
option_defs.h vim-patch:9.0.1064: code for making 'shortmess' temporarily empty is repeated 2023-04-16 16:12:52 +08:00
option.c vim-patch:9.0.1311: Coverity warns for using a NULL pointer 2023-04-22 11:02:16 +01:00
option.h feat(ui): add 'statuscolumn' option 2023-01-09 17:12:06 +00:00
options.lua refactor(defaults)!: change default 'commentstring' value to empty (#22862) 2023-04-02 23:01:48 +08:00
optionstr.c fix(column): rebuild status column when sign column is invalid 2023-04-19 03:22:27 +02:00
optionstr.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
path.c fix(runtime): do not allow breakcheck inside runtime path calculation 2023-04-19 16:34:15 +02:00
path.h fix(runtime): do not allow breakcheck inside runtime path calculation 2023-04-19 16:34:15 +02:00
plines.c build: update uncrustify to 0.76 2023-04-19 17:04:00 +01:00
plines.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
popupmenu.c refactor(screen): screen.c delenda est 2023-03-14 13:37:43 +01:00
popupmenu.h refactor: replace char_u with char 21 (#21779) 2023-01-14 15:58:28 +08:00
pos.h
profile.c vim-patch:9.0.0398: members of funccall_T are inconsistently named (#23123) 2023-04-16 16:57:25 +08:00
profile.h
quickfix.c vim-patch:8.2.1080: Vim9: no line break allowed in a for loop 2023-04-14 16:10:09 +08:00
quickfix.h
rbuffer.c fix(rbuffer): handle edge case where write_ptr has wrapped around 2023-01-14 11:53:47 +01:00
rbuffer.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
README.md docs: how to debug TUI using gdb/lldb #22771 2023-03-25 12:25:28 -04:00
regexp_bt.c fix(runtime): do not allow breakcheck inside runtime path calculation 2023-04-19 16:34:15 +02:00
regexp_defs.h refactor: replace char_u with char or uint8_t (#22400) 2023-03-04 20:10:00 +08:00
regexp_nfa.c fix(runtime): do not allow breakcheck inside runtime path calculation 2023-04-19 16:34:15 +02:00
regexp.c fix(runtime): do not allow breakcheck inside runtime path calculation 2023-04-19 16:34:15 +02:00
regexp.h fix(runtime): do not allow breakcheck inside runtime path calculation 2023-04-19 16:34:15 +02:00
runtime.c fix(runtime): do not allow breakcheck inside runtime path calculation 2023-04-19 16:34:15 +02:00
runtime.h vim-patch:8.2.0154: reallocating the list of scripts is inefficient 2023-02-16 11:50:28 +08:00
search.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
search.h vim-patch:8.2.4463: completion only uses strict matching 2023-01-17 14:01:10 +08:00
sha256.c refactor: replace char_u with char (#21901) 2023-02-11 11:05:57 +01:00
sha256.h refactor: change char_u to uint8_t or char in sha256.c/undo.c (#21914) 2023-01-21 08:58:57 +08:00
shada.c vim-patch:9.0.0411: only created files can be cleaned up with one call 2023-04-16 15:04:41 +08:00
shada.h
sign_defs.h feat(api): evaluate 'statuscolumn' with nvim_eval_statusline() 2023-04-05 12:36:47 +02:00
sign.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
sign.h
spell_defs.h refactor: remove char_u (#22829) 2023-04-02 16:11:42 +08:00
spell.c refactor: remove redundant casts 2023-04-07 21:08:16 +02:00
spell.h
spellfile.c refactor: remove redundant casts 2023-04-07 21:08:16 +02:00
spellfile.h
spellsuggest.c refactor: remove redundant const char * casts 2023-04-07 19:40:57 +02:00
spellsuggest.h
state.c refactor: remove char_u (#22829) 2023-04-02 16:11:42 +08:00
state.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
statusline_defs.h feat(api): evaluate 'statuscolumn' with nvim_eval_statusline() 2023-04-05 12:36:47 +02:00
statusline.c fix(statusline): fix uninitialized variable and possible overflow 2023-04-21 12:14:48 +02:00
statusline.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
strings.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
strings.h refactor: move klib out of src/nvim/ #20341 2022-09-25 06:26:37 -07:00
syntax_defs.h refactor: use flexible arrays instead of the length-of-one trick (#22072) 2023-02-02 23:56:25 +01:00
syntax.c refactor: remove redundant casts 2023-04-07 21:43:00 +02:00
syntax.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
tag.c vim-patch:partial:9.0.0364: clang static analyzer gives warnings (#23059) 2023-04-13 13:27:50 +08:00
tag.h feat(cscope)!: remove 2022-10-13 16:37:23 +01:00
terminal.c refactor: remove use of reserved c++ keywords 2023-04-06 22:39:50 +02:00
terminal.h
testing.c refactor: remove redundant const char * casts 2023-04-07 19:40:57 +02:00
testing.h
textformat.c vim-patch:8.2.4183: cannot use an import in 'formatexpr' 2023-04-17 15:46:24 +08:00
textformat.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
textobject.c refactor(screen): screen.c delenda est 2023-03-14 13:37:43 +01:00
textobject.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
types.h refactor: remove use of reserved c++ keywords 2023-04-06 22:39:50 +02:00
ugrid.c build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
ugrid.h build: allow IWYU to fix includes for all .c files 2022-11-15 10:30:03 +01:00
ui_client.c refactor: revert incorrect change to ui_client.c code 2023-04-21 17:56:09 +02:00
ui_client.h fix(unittests): fix TUI broken test previously ignored 2023-01-18 14:56:55 +01:00
ui_compositor.c refactor: fix IWYU mapping file and use IWYU (#21802) 2023-01-15 14:16:33 +01:00
ui_compositor.h
ui.c refactor(log): reduce compile time LOG_LEVEL granularity 2023-03-04 15:26:17 +01:00
ui.h feat(ui): restore has('gui_running') 2023-02-27 19:50:59 +01:00
undo_defs.h refactor: replace char_u with char 2022-09-09 21:02:42 +02:00
undo.c vim-patch:9.0.0411: only created files can be cleaned up with one call 2023-04-16 15:04:41 +08:00
undo.h
usercmd.c fix(usercmd): Fix buffer overflow in uc_list() (#23225) 2023-04-21 19:16:32 +08:00
usercmd.h build: enable MSVC level 3 warnings (#21934) 2023-02-11 10:25:24 +01:00
version.c version.c: update [skip ci] (#22095) 2023-04-22 11:24:28 +08:00
version.h vim-patch: bump VIM_VERSION from 8.0 => 8.1 #20762 2022-10-21 03:56:09 -07:00
vim.h feat(ex_cmds)!: remove :behave 2023-04-13 12:15:30 +02:00
window.c vim-patch:9.0.1293: the set_num_option() is too long 2023-04-22 09:11:24 +01:00
window.h refactor: fix IWYU mapping file and use IWYU (#21802) 2023-01-15 14:16:33 +01:00

Nvim core

Module-specific details are documented at the top of each module (terminal.c, screen.c, …).

See :help dev for guidelines.

Filename conventions

The source files use extensions to hint about their purpose.

  • *.c, *.generated.c - full C files, with all includes, etc.
  • *.c.h - parametrized C files, contain all necessary includes, but require defining macros before actually using. Example: typval_encode.c.h
  • *.h - full headers, with all includes. Does not apply to *.generated.h.
  • *.h.generated.h - exported functions declarations.
  • *.c.generated.h - static functions declarations.

Common structures

  • StringBuilder
  • kvec or garray.c for dynamic lists / vectors (use StringBuilder for strings)

Logs

Low-level log messages sink to $NVIM_LOG_FILE.

UI events are logged at DEBUG level.

rm -rf build/
make CMAKE_EXTRA_FLAGS="-DLOG_DEBUG"

Use LOG_CALLSTACK() (Linux only) to log the current stacktrace. To log to an alternate file (e.g. stderr) use LOG_CALLSTACK_TO_FILE(FILE*). Requires -no-pie (ref):

rm -rf build/
make CMAKE_EXTRA_FLAGS="-DLOG_DEBUG -DCMAKE_C_FLAGS=-no-pie"

Many log messages have a shared prefix, such as "UI" or "RPC". Use the shell to filter the log, e.g. at DEBUG level you might want to exclude UI messages:

tail -F ~/.local/state/nvim/log | cat -v | stdbuf -o0 grep -v UI | stdbuf -o0 tee -a log

Build with ASAN

Building Nvim with Clang sanitizers (Address Sanitizer: ASan, Undefined Behavior Sanitizer: UBSan, Memory Sanitizer: MSan, Thread Sanitizer: TSan) is a good way to catch undefined behavior, leaks and other errors as soon as they happen. It's significantly faster than Valgrind.

Requires clang 3.4 or later, and llvm-symbolizer must be in $PATH:

clang --version

Build Nvim with sanitizer instrumentation (choose one):

CC=clang make CMAKE_EXTRA_FLAGS="-DENABLE_ASAN_UBSAN=ON"
CC=clang make CMAKE_EXTRA_FLAGS="-DENABLE_MSAN=ON"
CC=clang make CMAKE_EXTRA_FLAGS="-DENABLE_TSAN=ON"

Create a directory to store logs:

mkdir -p "$HOME/logs"

Configure the sanitizer(s) via these environment variables:

# Change to detect_leaks=1 to detect memory leaks (slower, noisier).
export ASAN_OPTIONS="detect_leaks=0:log_path=$HOME/logs/asan,handle_abort=1,handle_sigill=1"
# Show backtraces in the logs.
export UBSAN_OPTIONS=print_stacktrace=1
export MSAN_OPTIONS="log_path=${HOME}/logs/msan"
export TSAN_OPTIONS="log_path=${HOME}/logs/tsan"

Logs will be written to ${HOME}/logs/*san.PID then.

For more information: https://github.com/google/sanitizers/wiki/SanitizerCommonFlags

Reproducible build

To make a reproducible build of Nvim, set cmake variable LUA_GEN_PRG to a LuaJIT binary built with LUAJIT_SECURITY_PRN=0. See commit cb757f2663.

Debug: Performance

Profiling (easy)

For debugging performance bottlenecks in any code, there is a simple (and very effective) approach:

  1. Run the slow code in a loop.
  2. Break execution ~5 times and save the stacktrace.
  3. The cause of the bottleneck will (almost always) appear in most of the stacktraces.

Profiling (fancy)

For more advanced profiling, consider perf + flamegraph.

USDT profiling (powerful)

Or you can use USDT probes via NVIM_PROBE (#12036).

USDT is basically a way to define stable probe points in userland binaries. The benefit of bcc is the ability to define logic to go along with the probe points.

Tools:

  • bpftrace provides an awk-like language to the kernel bytecode, BPF.
  • BCC provides a subset of C. Provides more complex logic than bpftrace, but takes a bit more effort.

Example using bpftrace to track slow vim functions, and print out any files that were opened during the trace. At the end, it prints a histogram of function timing:

#!/usr/bin/env bpftrace

BEGIN {
  @depth = -1;
}

tracepoint:sched:sched_process_fork /@pidmap[args->parent_pid]/ {
  @pidmap[args->child_pid] = 1;
}

tracepoint:sched:sched_process_exit /@pidmap[args->pid]/ {
  delete(@pidmap[args->pid]);
}

usdt:build/bin/nvim:neovim:eval__call_func__entry {
    @pidmap[pid] = 1;
    @depth++;
    @funcentry[@depth] = nsecs;
}

usdt:build/bin/nvim:neovim:eval__call_func__return {
    $func = str(arg0);
    $msecs = (nsecs - @funcentry[@depth]) / 1000000;

    @time_histo = hist($msecs);

    if ($msecs >= 1000) {
      printf("%u ms for %s\n", $msecs, $func);
      print(@files);
    }

    clear(@files);
    delete(@funcentry[@depth]);
    @depth--;
}

tracepoint:syscalls:sys_enter_open,
tracepoint:syscalls:sys_enter_openat {
  if (@pidmap[pid] == 1 && @depth >= 0) {
    @files[str(args->filename)] = count();
  }
}

END {
  clear(@depth);
}

$ sudo bpftrace funcslower.bt
1527 ms for Slower
@files[/usr/lib/libstdc++.so.6]: 2
@files[/etc/fish/config.fish]: 2
<snip>

^C
@time_histo:
[0]                71430 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[1]                  346 |                                                    |
[2, 4)               208 |                                                    |
[4, 8)                91 |                                                    |
[8, 16)               22 |                                                    |
[16, 32)              85 |                                                    |
[32, 64)               7 |                                                    |
[64, 128)              0 |                                                    |
[128, 256)             0 |                                                    |
[256, 512)             6 |                                                    |
[512, 1K)              1 |                                                    |
[1K, 2K)               5 |                                                    |

Debug: TUI

TUI troubleshoot

Nvim logs its internal terminfo state at 'verbose' level 3. This makes it possible to see exactly what terminfo values Nvim is using on any system.

nvim -V3log

TUI Debugging with gdb/lldb

Launching the nvim TUI involves two processes, one for main editor state and one for rendering the TUI. Both of these processes use the nvim binary, so somewhat confusingly setting a breakpoint in either will generally succeed but may not be hit depending on which process the breakpoints were set in.

To debug the main process, you can debug the nvim binary with the --headless flag which does not launch the TUI and will allow you to set breakpoints in code not related to TUI rendering like so:

lldb -- ./build/bin/nvim --headless --listen ~/.cache/nvim/debug-server.pipe

You can then attach to the headless process to interact with the editor like so:

./build/bin/nvim --remote-ui --server ~/.cache/nvim/debug-server.pipe

Conversely for debugging TUI rendering, you can start a headless process and debug the remote-ui process multiple times without losing editor state.

For details on using nvim-dap and automatically debugging the child (main) process, see here

TUI trace

The ancient script command is still the "state of the art" for tracing terminal behavior. The libvterm vterm-dump utility formats the result for human-readability.

Record a Nvim terminal session and format it with vterm-dump:

script foo
./build/bin/nvim -u NONE
# Exit the script session with CTRL-d

# Use `vterm-dump` utility to format the result.
./.deps/usr/bin/vterm-dump foo > bar

Then you can compare bar with another session, to debug TUI behavior.

TUI redraw

Set the 'writedelay' and 'redrawdebug' options to see where and when the UI is painted.

:set writedelay=50 rdb=compositor

Note: neovim uses an internal screenbuffer to only send minimal updates even if a large region is repainted internally. To also highlight excess internal redraws, use

:set writedelay=50 rdb=compositor,nodelta

Terminal reference

Nvim lifecycle

Following describes how Nvim processes input.

Consider a typical Vim-like editing session:

  1. Vim displays the welcome screen
  2. User types: :
  3. Vim enters command-line mode
  4. User types: edit README.txt<CR>
  5. Vim opens the file and returns to normal mode
  6. User types: G
  7. Vim navigates to the end of the file
  8. User types: 5
  9. Vim enters count-pending mode
  10. User types: d
  11. Vim enters operator-pending mode
  12. User types: w
  13. Vim deletes 5 words
  14. User types: g
  15. Vim enters the "g command mode"
  16. User types: g
  17. Vim goes to the beginning of the file
  18. User types: i
  19. Vim enters insert mode
  20. User types: word<ESC>
  21. Vim inserts "word" at the beginning and returns to normal mode

Note that we split user actions into sequences of inputs that change the state of the editor. While there's no documentation about a "g command mode" (step 16), internally it is implemented similarly to "operator-pending mode".

From this we can see that Vim has the behavior of an input-driven state machine (more specifically, a pushdown automaton since it requires a stack for transitioning back from states). Assuming each state has a callback responsible for handling keys, this pseudocode represents the main program loop:

def state_enter(state_callback, data):
  do
    key = readkey()                 # read a key from the user
  while state_callback(data, key)   # invoke the callback for the current state

That is, each state is entered by calling state_enter and passing a state-specific callback and data. Here is a high-level pseudocode for a program that implements something like the workflow described above:

def main()
  state_enter(normal_state, {}):

def normal_state(data, key):
  if key == ':':
    state_enter(command_line_state, {})
  elif key == 'i':
    state_enter(insert_state, {})
  elif key == 'd':
    state_enter(delete_operator_state, {})
  elif key == 'g':
    state_enter(g_command_state, {})
  elif is_number(key):
    state_enter(get_operator_count_state, {'count': key})
  elif key == 'G'
    jump_to_eof()
  return true

def command_line_state(data, key):
  if key == '<cr>':
    if data['input']:
      execute_ex_command(data['input'])
    return false
  elif key == '<esc>'
    return false

  if not data['input']:
    data['input'] = ''

  data['input'] += key
  return true

def delete_operator_state(data, key):
  count = data['count'] or 1
  if key == 'w':
    delete_word(count)
  elif key == '$':
    delete_to_eol(count)
  return false  # return to normal mode

def g_command_state(data, key):
  if key == 'g':
    go_top()
  elif key == 'v':
    reselect()
  return false  # return to normal mode

def get_operator_count_state(data, key):
  if is_number(key):
    data['count'] += key
    return true
  unshift_key(key)  # return key to the input buffer
  state_enter(delete_operator_state, data)
  return false

def insert_state(data, key):
  if key == '<esc>':
    return false  # exit insert mode
  self_insert(key)
  return true

The above gives an idea of how Nvim is organized internally. Some states like the g_command_state or get_operator_count_state do not have a dedicated state_enter callback, but are implicitly embedded into other states (this will change later as we continue the refactoring effort). To start reading the actual code, here's the recommended order:

  1. state_enter() function (state.c). This is the actual program loop, note that a VimState structure is used, which contains function pointers for the callback and state data.
  2. main() function (main.c). After all startup, normal_enter is called at the end of function to enter normal mode.
  3. normal_enter() function (normal.c) is a small wrapper for setting up the NormalState structure and calling state_enter.
  4. normal_check() function (normal.c) is called before each iteration of normal mode.
  5. normal_execute() function (normal.c) is called when a key is read in normal mode.

The basic structure described for normal mode in 3, 4 and 5 is used for other modes managed by the state_enter loop:

  • command-line mode: command_line_{enter,check,execute}()(ex_getln.c)
  • insert mode: insert_{enter,check,execute}()(edit.c)
  • terminal mode: terminal_{enter,execute}()(terminal.c)

Async event support

One of the features Nvim added is the support for handling arbitrary asynchronous events, which can include:

  • RPC requests
  • job control callbacks
  • timers

Nvim implements this functionality by entering another event loop while waiting for characters, so instead of:

def state_enter(state_callback, data):
  do
    key = readkey()                 # read a key from the user
  while state_callback(data, key)   # invoke the callback for the current state

Nvim program loop is more like:

def state_enter(state_callback, data):
  do
    event = read_next_event()       # read an event from the operating system
  while state_callback(data, event) # invoke the callback for the current state

where event is something the operating system delivers to us, including (but not limited to) user input. The read_next_event() part is internally implemented by libuv, the platform layer used by Nvim.

Since Nvim inherited its code from Vim, the states are not prepared to receive "arbitrary events", so we use a special key to represent those (When a state receives an "arbitrary event", it normally doesn't do anything other than update the screen).

Main loop

The Loop structure (which describes main_loop) abstracts multiple queues into one loop:

uv_loop_t uv;
MultiQueue *events;
MultiQueue *thread_events;
MultiQueue *fast_events;

loop_poll_events checks Loop.uv and Loop.fast_events whenever Nvim is idle, and also at os_breakcheck intervals.

MultiQueue is cool because you can attach throw-away "child queues" trivially. For example do_os_system() does this (for every spawned process!) to automatically route events onto the main_loop:

Process *proc = &uvproc.process;
MultiQueue *events = multiqueue_new_child(main_loop.events);
proc->events = events;