From c644228e1dfe9f70aae53292b328be98dc95b8f7 Mon Sep 17 00:00:00 2001 From: Marcus Caisey Date: Mon, 25 Nov 2024 22:33:11 +0000 Subject: fix(defaults): omit empty line from unimpaired mapping messages (#31347) Problem: The default unimpaired mappings display an empty line after the command's output. This results (with default configuration) in the `Press ENTER or type command to continue` prompt to be displayed, like so: ``` (2 of 16): item2 Press ENTER or type command to continue ``` Solution: The cause is that we're checking the second return value from `pcall(vim.api.nvim_cmd, opts, {})` to determine whether the call was successful. `nvim_cmd` returns an empty string on success, so this value is an empty string in the successful path which we then display. The fix is simple: check the first return value instead which is the "status code" of the call. --- runtime/lua/vim/_defaults.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 06f6ed6829..2687f34302 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -222,8 +222,8 @@ do --- Execute a command and print errors without a stacktrace. --- @param opts table Arguments to |nvim_cmd()| local function cmd(opts) - local _, err = pcall(vim.api.nvim_cmd, opts, {}) - if err then + local ok, err = pcall(vim.api.nvim_cmd, opts, {}) + if not ok then vim.api.nvim_err_writeln(err:sub(#'Vim:' + 1)) end end -- cgit