Commit Graph

20301 Commits

Author SHA1 Message Date
zeertzjq
2df2e72e0a fix(undo): undefined behavior with empty entry in 'undodir' (#38849)
Problem:  Undefined behavior when 'undodir' contains empty entry.
Solution: Don't try to remove trailing slashes from empty path. Also
          don't remove a colon on Windows while at it.
2026-04-07 14:49:05 +08:00
zeertzjq
6b0367481c fix: don't make path empty when truncating trailing slashes (#38844)
Fixes the following Coverity warning:

*** CID 549779:         Integer handling issues  (INTEGER_OVERFLOW)
/src/nvim/undo.c: 717             in u_get_undo_file_name()
711           dir_name[dir_len] = NUL;
712
713           // Remove trailing pathseps from directory name
714           char *p = &dir_name[dir_len - 1];
715           while (vim_ispathsep(*p)) {
716             *p-- = NUL;
>>>     CID 549779:         Integer handling issues  (INTEGER_OVERFLOW)
>>>     Expression "dir_len--", where "dir_len" is known to be equal to 0, underflows the type of "dir_len--", which is type "size_t".
717             dir_len--;
718           }
719
720           bool has_directory = os_isdir(dir_name);
721           if (!has_directory && *dirp == NUL && !reading) {
722             // Last directory in the list does not exist, create it.
2026-04-07 10:07:32 +08:00
zeertzjq
e94e469324 Merge pull request #38669 from SanzharKuandyk/fix-38667
fix(channel): fix Windows console regressions from #37977
2026-04-07 08:48:07 +08:00
zeertzjq
b36eafd5da vim-patch:794c304: runtime(doc): clarify incsearch feature and typed chars (#38830)
fixes: vim/vim#19886

794c304479

Co-authored-by: Christian Brabandt <cb@256bit.org>
2026-04-07 06:22:45 +08:00
zeertzjq
9d6453b771 vim-patch:9.2.0312: C-type names are marked as translatable (#38829)
Problem:  C-type names are marked as translatable
Solution: Use them as-is, do not translate them
          (Eisuke Kawashima)

closes: vim/vim#19861

a5b6c2d6e9

Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2026-04-07 06:22:32 +08:00
luukvbaal
1354787029 fix(cmdline): 'inccommand' preview after setcmdline() #38795
Problem:  'inccommand' preview is not executed after setcmdline(),
          and as a result cmdline_show event is emitted when redrawing
          is not allowed (5b6477be).
Solution: Call command_line_changed() when ccline.cmdbuff_replaced is
          set (by setcmdline()).
2026-04-06 13:15:46 -04:00
Josh Triplett
889572a358 fix(tui): check background color on resume #38726
Problem:
We normally get the background color via continuous reporting. However,
if we were backgrounded while the light/dark mode changed, we won't have
received the report, and we'll have the wrong background color.

Without this change, if you background nvim, toggle the light/dark mode,
resume, and check `:set bg`, it will not match the current state.

Solution:
Query it on resume as well. (This requires separating the query from the
flush, to just do the query along with all the others, while waiting to
flush until we've set up uv.)

With this change, if you background nvim, toggle the light/dark mode,
resume, and check `:set bg`, it will have updated.
2026-04-06 12:44:03 -04:00
Luuk van Baal
fa302037f9 fix(events): avoid recursive loop_uv_run() from vim.ui_attach() shell message
Problem:  vim.ui_attach() msg_show callback runs the risk of a recursive
          loop_uv_run() when trying to display a message from a shell
          command stream.
Solution: Schedule the message callback on the fast_events queue.
2026-04-06 10:07:23 +02:00
Sanzhar Kuandyk
8bb7533639 fix(channel): fix Ctrl-C handling regression in terminal
Problem: Normal Windows builtin-TUI startup spawns the embedded server as DETACHED_PROCESS, which breaks Ctrl-C delivery to :terminal jobs.
Solution: Restores the default behavior once the embedded server has a
console so terminal jobs inherit it.
2026-04-06 11:17:48 +05:00
nameearly
eb9be11da8 refactor(typval.c): fix wrong argument to macro (#38813) 2026-04-06 04:11:57 +00:00
zeertzjq
870e50f0ff vim-patch:9.2.0293: :packadd may lead to heap-buffer-overflow
Problem:  :packadd may lead to heap-buffer-overflow when all entries in
          'runtimepath' have the same length (after 9.2.0291).
Solution: Check for comma after current entry properly (zeertzjq).

related: vim/vim#19854
closes:  vim/vim#19911

bc182ae56e
2026-04-06 11:47:44 +08:00
zeertzjq
4d7dfa081b vim-patch:9.2.0291: too many strlen() calls
Problem:  too many strlen() calls
Solution: refactor concat_fname() and remove calls to strlen()
          (John Marriott)

Function `concat_fnames()` can make up to 5 calls to `STRLEN()` (either
directly or indirectly via `STRCAT()`). In many cases the lengths of
arguments `fname1` and/or `fname2` are either known or can simply be
calculated.

This Commit refactors this function to accept the lengths of arguments
`fname1` and `fname2` as arguments. It also adds new argument `ret` to
return the resulting string as a `string_T`.

Additionally:
- function `add_pack_dir_to_rtp()` in `scriptfile.c`:
   Use a `string_T` to store local variables `new_rtp` and `afterdir`.
   Replace calls to `STRCAT()` with calls to `STRCPY()`.
   Change type of variable `keep` to `size_t` for consistency with
   other lengths.

- function `qf_get_fnum()` in `quickfix.c`:
  Use a `string_T` to store local variables `ptr` and `bufname`
- function `qf_push_dir()` in `quickfix.c`:
  Use a `string_T` to store local variable `dirname`.
  Replace call to `vim_strsave()` with `vim_strnsave()`.

- function `qf_guess_filepath()` in `quickfix.c`:
  Use a `string_T` to store local variable `fullname`.

- function `make_percent_swname()` in `memline.c`:
  Rename some variables to better reflect their use.
  Use a `string_T` to store local variables `d` and `fixed_name`.
  Slightly refactor to remove need to create an extra string.
- function `get_file_in_dir()` in `memline.c`:
  Use a `string_T` to store local variables `tail` and `retval`.
  Move some variables closer to where they are used.

- function `cs_resolve_file()` in `if_cscope.c`:
  Use a `string_T` to store local variable `csdir`.
  Remove one call to `STRLEN()`.

- function `add_pathsep()` in `filepath.c`:
  Refactor and remove 1 call to `STRLEN()`

- function `set_init_xdg_rtp()` in `option.c`:
  Use a `string_T` to store local variable `vimrc_xdg`.

closes: vim/vim#19854

cb51add7ae

Co-authored-by: John Marriott <basilisk@internode.on.net>
Co-authored-by: Christian Brabandt <cb@256bit.org>
2026-04-06 11:47:44 +08:00
Justin M. Keyes
42f6c55139 Merge #38796 from justinmk/doc2 2026-04-05 20:36:45 -04:00
Justin M. Keyes
6b796696c3 docs: statusline
fix https://github.com/neovim/neovim/issues/38670
2026-04-06 02:29:29 +02:00
Elijah Koulaxis
bba48ee1b0 fix(windows): force console codepage to UTF-8 for shell/system() #38742
Problem:
On Windows, `:!echo тест` shows `????` because the console code page defaults to a legacy ANSI encoding (e.g. CP1252) instead of `UTF-8`

Solution:
Call `SetConsoleOutputCP(CP_UTF8)` and `SetConsoleCP(CP_UTF8)` in `do_os_system()` before spawning child processes, and restore the original values after. It covers both `:!` and `system()` since they both go through `do_os_system()`
2026-04-05 19:16:48 -04:00
Jibril
cfbac23235 fix(coverity): coverity/530031, coverity/530027 resource leaks #37916
Fixed resource leak caused by overwriting lp->sl_midword by freeing
lp->sl_midword first.
2026-04-05 15:08:30 -04:00
zeertzjq
9705a1c13b fix(help): show error when using :help! with nothing at cursor #38775
It's possible to still show the old Easter egg, but then the user won't
know about the new feature, so showing E349 is better.
2026-04-05 10:59:22 -04:00
github-actions[bot]
38c32aa029 docs: update version.c #38752
vim-patch:9.2.0286: still some unnecessary (int) casts in alloc()
vim-patch:9.2.0288: libvterm: signed integer overflow parsing long CSI args
vim-patch:bd8b6c6b0 CI: Bump codecov/codecov-action
vim-patch:9.2.0294: if_lua: lua interface does not work with lua 5.5
vim-patch:9.2.0297: libvterm: can improve CSI overflow code

vim-patch:8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
vim-patch:8.2.0647: MS-Windows: repeat count for events was not used
2026-04-05 10:51:18 -04:00
zeertzjq
9927d9259d fix(:restart): inherit stderr fd on Unix (#38755)
This in turn gives TTY access to channel_from_stdio() in the new server,
if the old server has access to a TTY.
2026-04-04 21:57:27 +08:00
zeertzjq
e20c4ea966 fix(channel): crash on exit after closing v:stderr channel (#38754)
Problem:  Crash on exit after closing v:stderr channel when piping
          to stdin.
Solution: Reopen stderr as /dev/null or NUL instead of closing it.
          This also avoids writing to an related file if one is opened
          after closing v:stderr.
2026-04-04 20:54:27 +08:00
zeertzjq
426cbfbd76 vim-patch:9.2.0298: Some internal variables are not modified (#38758)
Problem:  Some internal variables are not modified
Solution: Add const qualifier to static table data
          (Hirohito Higashi).

Several static arrays that are never modified at runtime were missing the
const qualifier. Add const to move them from .data to .rodata section.

closes: vim/vim#19901

3c79e33aeb

Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
2026-04-04 20:50:01 +08:00
zeertzjq
e2bced7703 vim-patch:9.2.0296: Redundant and incorrect integer pointer casts in drawline.c (#38757)
Problem:  Currently `colnr_T` and `int` and the same type, so casting
          `int *` to `colnr_T *` is redundant. Additionally, even if
          they are changed to different types in the future, these casts
          are incorrect as they won't work on big-endian platforms.
Solution: Remove the casts. Also fix two cases of passing false instead
          of 0 to an integer argument (zeertzjq).

related: vim/vim#19672
closes:  vim/vim#19907

18cd55dbc4
2026-04-04 20:49:43 +08:00
zeertzjq
d10dda8a47 vim-patch:9.2.0295: 'showcmd' shows wrong Visual block size with 'linebreak' (#38756)
Problem:  'showcmd' shows wrong Visual block size with 'linebreak' after
          end char (after 7.4.467).
Solution: Exclude 'linebreak' from end position. Also fix confusing test
          function names.

closes: vim/vim#19908

08bd9114c1
2026-04-04 20:49:26 +08:00
zeertzjq
164dfa1d5f vim-patch:9.2.0289: 'linebreak' may lead to wrong Visual block highlighting (#38749)
Problem:  'linebreak' may lead to wrong Visual block highlighting when
          end char occupies multiple cells (after 7.4.467).
Solution: Exclude 'linebreak' from the ending column instead of setting
          'virtualedit' temporarily (zeertzjq).

fixes:  vim/vim#19898
closes: vim/vim#19900

23be1889d1
2026-04-04 08:58:17 +08:00
zeertzjq
20e46cb38d vim-patch:af58a9f: runtime(doc): adjust :h 'autowrite' and :h 'autowriteall'
- Don't go over 78 columns.
- Change the first "and" to "or", as "or" is used below.
- Change "takes one" to "switches", as "one" may be mistaken as
  referring to the command instead of the user.
- Use backticks in :h 'autowriteall' like in :h 'autowrite'.

closes: vim/vim#19859

af58a9f5e9
2026-04-04 06:04:28 +08:00
zeertzjq
76a917a81e vim-patch:9.2.0267: 'autowrite' not triggered for :term
Problem:  'autowrite' not triggered for :term
Solution: Trigger autowrite for :term command
          (rendcrx)

closes: vim/vim#19855

466b5f531a

Co-authored-by: rendcrx <974449413@qq.com>
2026-04-04 06:04:25 +08:00
github-actions[bot]
b346b87fb2 docs: update version.c #38625
vim-patch:f4f175332 translation(ru): updated the Russian man page the xxd
vim-patch:e4502b603 translation(ru): updated lang/README.ru.txt
vim-patch:2c976d0de SECURITY.md: clarify the use of AI
vim-patch:9.2.0279: terminal: out-of-bounds write with overlong CSI argument list
vim-patch:9d83ca5ca runtime(preproc_indent): Ignore Swapfiles when loading buffers

Co-authored-by: marvim <marvim@users.noreply.github.com>
2026-04-03 10:41:17 -04:00
zeertzjq
d7ef77d175 vim-patch:9.2.0285: :syn sync grouphere may go beyond end of line (#38727)
Problem:  :syn sync grouphere may go beyond end of line.
Solution: Start searching for the end of region at the end of match
          instead of a possibly invalid position (zeertzjq).

closes: vim/vim#19896

b7cffc8434
2026-04-03 09:22:26 +00:00
zeertzjq
fb9c843ab0 feat(:restart): reattach all UIs (#38683)
This is quite easy since [command] is now only executed once on UIEnter.
2026-04-02 20:57:02 +08:00
Lewis Russell
3309b48c83 refactor(treesitter): add nts_parser_parse_buf
This PR creates a C function `nts_parser_parse_buf()`
which is like `ts_parser_parse_string()` but instead can be passed
an nvim buffer number to parse.
2026-04-02 14:29:36 +02:00
zeertzjq
f2cdf73afc fix(api): avoid error when parsing invalid expr after :echo (#38695)
Problem:  Parsing :echo followed by invalid expression leads to error.
Solution: Suppress error when skipping over expression.
2026-04-01 23:05:47 +00:00
Sanzhar Kuandyk
789741bb83 refactor(channel): defer hidden console allocation to :detach
Refactor #37977: instead of allocating a hidden console at startup, borrow the parent's console via AttachConsole() and only create an isolated hidden console when :detach is called, with fd 0/1/2 re-bound to the new CONIN$/CONOUT$.
2026-04-01 20:39:45 +05:00
zeertzjq
65e2218585 vim-patch:9.2.0277: tests: test_modeline.vim fails (#38672)
Problem:  tests: test_modeline.vim fails (after v9.2.0276)
Solution: Rewrite the tests to use the existing s:modeline_fails()
          function, update documentation (zeertzjq).

8c8772c6b3
2026-04-01 08:43:03 +00:00
zeertzjq
c7604323e3 vim-patch:9.2.0276: [security]: modeline security bypass (#38657)
Problem:  [security]: modeline security bypass
Solution: disallow mapset() from secure mode, set the P_MLE flag for the
          'complete', 'guitabtooltip' and 'printheader' options.

Github Advisory:
https://github.com/vim/vim/security/advisories/GHSA-8h6p-m6gr-mpw9

75661a66a1

Co-authored-by: Christian Brabandt <cb@256bit.org>
2026-04-01 08:00:33 +08:00
zeertzjq
a89d7dcb91 docs: misc (#38578) 2026-04-01 07:59:51 +08:00
zeertzjq
0860b24c2c vim-patch:52169db: translation(cleanup): squeeze successive empty lines and remove stray comments
closes: vim/vim#19860

52169dbc28

Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2026-04-01 07:46:16 +08:00
zeertzjq
9b9c72f6d4 vim-patch:cca3df9: translation: improve the po/cleanup.vim script
explicitly delete into the black-hole register

closes: vim/vim#15499

cca3df9275

Co-authored-by: RestorerZ <restorer@mail2k.ru>
2026-04-01 07:46:16 +08:00
Justin M. Keyes
2b7d793cd6 Merge #38579 from liskin/terminfo-urxvt
fix(termkey): use terminfo for (shift+)left/right keys
2026-03-31 18:07:08 -04:00
luukvbaal
cd2a27507a fix(window): clear cmdline 'ruler' when window is closed #38631
Problem:  When 'ruler' is in last line of the screen and the current
          floating window is closed, the ruler is not cleared.
Solution: When closing the current floating window, redraw the cmdline
          if that contained, and will no longer contain the 'ruler'.
2026-03-31 11:11:33 -04:00
luukvbaal
1685ced335 fix(cmdline): redraw cmdline after empty message (#38485)
Problem: Cmdline is not redrawn after an empty message clears it.
Remembered last drawn cursor position may be outdated but
equal to the current cmdline content with UI2.
Solution: Ensure cmdline is redrawn after an empty message clears it.
Compare wanted cursor position with actual cursor position.
2026-03-31 14:16:55 +02:00
zeertzjq
19fff0e0be vim-patch:9.2.0232: fileinfo not shown after :bd of last listed buffer (#38453)
Problem:  fileinfo not shown after :bd of last listed buffer
          (memeplex)
Solution: Set need_fileinfo to true in empty_curbuf()
          (Hirohito Higashi)

When deleting the last listed buffer with :bd, the new empty buffer's
file info (e.g. "[No Name]" --No lines in buffer--) was not displayed.
do_ecmd() only calls fileinfo() for existing buffers (oldbuf), not for
newly created empty buffers.

Set need_fileinfo in empty_curbuf() so the file info is displayed after
redraw.

fixes:  vim/vim#548
closes: vim/vim#19802

3d472d8675

Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:13:54 +08:00
Eisuke Kawashima
dbc4800dda vim-patch:2844765: translation: do not add message location as comments into vim.pot (#38587)
Let's add the --no-location to the xgettext command line call, so that
the generated vim.pot file does not contain the message location. Those
will get out of date soon and we don't want to update vim.pot just
because the location in a comment changes.

2844765e90

Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
Co-authored-by: Christian Brabandt <cb@256bit.org>
2026-03-31 07:59:57 +08:00
zeertzjq
a3a48392c5 fix(:restart): only pass --headless when there is no UI (#38580)
Change --embed so that the first UI can be on non-stdio channel even if
neither --headless nor --listen is passed.
2026-03-31 07:00:34 +08:00
github-actions[bot]
183933998c docs: update version.c #38505
vim-patch:9.1.0333: tests: test_xdg fails on the appimage repo
vim-patch:9.1.0336: tests: typo in test_xdg
vim-patch:9.1.0339: tests: xdg test uses screen dumps
vim-patch:9.1.0347: A few typos in test_xdg when testing gvimrc
vim-patch:b9897ec27 runtime(xdg): remove // from 'undo' and 'viwedir'
vim-patch:2e9e7cb8e runtime(xdg): Move viminfofile storage to state dir
vim-patch:9.2.0255: tests: Test_popup_opacity_vsplit() fails in a wide terminal
vim-patch:9.2.0260: statusline not redrawn after closing a popup window
vim-patch:9.2.0261: terminal: redraws are slow
vim-patch:9.2.0264: Cannot disable kitty keyboard protocol in vim :terminal
vim-patch:9.2.0268: memory leak in call_oc_method()
vim-patch:9.2.0269: configure: Link error on Solaris

vim-patch:9.2.0258: memory leak in add_mark()
2026-03-30 11:02:32 -04:00
zeertzjq
80e5ccdd44 refactor(buffer.c): fix coverity warning (#38589)
The NULL checks added in #35679 are no longer needed after #38473.

_____________________________________________________________________________________________
*** CID 645258:           (REVERSE_INULL)
/src/nvim/buffer.c: 645             in close_buffer()
639             // Autocommands deleted the buffer.
640             emsg(_(e_auabort));
641             return false;
642           }
643           buf->b_locked--;
644           buf->b_locked_split--;
>>>     CID 645258:           (REVERSE_INULL)
>>>     Null-checking "win" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
645           if (abort_if_last && win != NULL && one_window(win, NULL)) {
646             // Autocommands made this the only window.
647             emsg(_(e_auabort));
648             return false;
649           }
650         }
/src/nvim/buffer.c: 626             in close_buffer()
620           // Autocommands deleted the buffer.
621           emsg(_(e_auabort));
622           return false;
623         }
624         buf->b_locked--;
625         buf->b_locked_split--;
>>>     CID 645258:           (REVERSE_INULL)
>>>     Null-checking "win" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
626         if (abort_if_last && win != NULL && one_window(win, NULL)) {
627           // Autocommands made this the only window.
628           emsg(_(e_auabort));
629           return false;
630         }
631
2026-03-30 14:50:12 +08:00
Tomas Janousek
c4283caa17 fix(termkey): use terminfo for (shift+)left/right keys
Problem:
Since neovim 0.12, shift + arrow keys no longer works in rxvt-unicode
(TERM=rxvt-unicode-256color).

Solution:
Re-add `left` and `right` to `wanted_termkeys` so they're read from
terminfo instead of being handled by driver-csi. There seems to be quite
a few other terminals that define kLFT in terminfo.src and these are
likely to be affected as well.

Fixes: https://github.com/neovim/neovim/issues/38571
Fixes: 4b678a499c ("refactor(termkey): make termkey use internal terminfo properly")
2026-03-30 00:42:01 +01:00
Tomas Janousek
7150ae0150 revert: "fix(scripts): gen_terminfo clears Windows terminfo definitions #36736"
Problem:
`gen_terminfo.lua`'s output is unpredictable and depends on the system
ncurses version.

Invoking `tic` on `scripts/windows.ti` alone makes it use the system
terminfo definitions for the `use=…` fragments in `windows.ti` such as:

    use=xterm+256color, use=xterm+sl, use=xterm-new

This is particularly problematic on Debian, as they build ncurses with
`--with-xterm-kbs=del` [1], and thus some of the windows entries end up
with different definitions for `kTermKey_left`, which is almost
certainly not desired.

[1]: 2d238cf387/debian/rules (L149)

Solution:
This reverts commit 9f90992934.
2026-03-30 00:41:49 +01:00
zeertzjq
33e17d66c6 vim-patch:9.2.0271: buffer underflow in vim_fgets() (#38575)
Problem:  buffer underflow in vim_fgets()
Solution: Ensure size is always greater than 1
          (Koda Reef)

3c0f8000e1

This currently never happens in Nvim.

Co-authored-by: Koda Reef <kodareef5@gmail.com>
2026-03-30 07:20:21 +08:00
Sean Dewar
8579946eda vim-patch:9.2.0254: w_locked can be bypassed when setting recursively
Problem:  w_locked can be bypassed when recursively set if not restored
          to its prior value.
Solution: Rather than save/restore everywhere, just make it a count,
          like other locks (Sean Dewar)

Requires the previous commit, otherwise b_nwindows will be wrong in
tests, which causes a bunch of weird failures.

closes: vim/vim#19728

7cb43f286e

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
2026-03-29 23:49:24 +01:00
Sean Dewar
6617f85b76 vim-patch:9.2.0253: various issues with wrong b_nwindows after closing buffers
Problem:  close_buffer() callers incorrectly handle b_nwindows,
          especially after nasty autocmds, allowing it to go
          out-of-sync.  May lead to buffers that can't be unloaded, or
          buffers that are prematurely freed whilst displayed.
Solution: Modify close_buffer() and review its callers; let them
          decrement b_nwindows if it didn't unload the buffer.  Remove
          some now unneeded workarounds like 8.2.2354, 9.1.0143,
          9.1.0764, which didn't always work (Sean Dewar)

(endless yapping omitted)

related: vim/vim#19728

bf21df1c7b

b_nwindows = 0 change for free_all_mem() was already ported.

Originally Nvim returned true when b_nwindows was decremented before the end was
reached (to better indicate the decrement). That's not needed anymore, so just
return true only at the end, like Vim. (retval isn't used anywhere now anyways)

Set textlock for dict watchers at the end of close_buffer() to prevent them from
switching windows, as that can leave a window with a NULL buffer. (possible
before this PR, but the new assert catches it; added a test)

Despite textlock, things still aren't ideal, as watchers may observe the buffer
as unloaded and hidden (b_nwindows was decremented), yet still in a window...
Likewise, for Nvim, wipe_qf_buffer()'s comment may not be entirely accurate;
autocmds are blocked, but on_detach callbacks (textlocked) and dict watchers may
still run. Might be problematic, but those aren't new issues.

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
2026-03-29 23:49:24 +01:00