Bug in :vmap <silent>

15 views
Skip to first unread message

Gary Johnson

unread,
Jun 14, 2023, 7:13:04 PM6/14/23
to vim...@googlegroups.com
Help for :map-<silent> says that with <silent>, the right side of
a mapping will not be echoed on the command line, but messages from
the executed command are still given. This works with :nmap but not
with :vmap. I would expect it to work with :vmap as well.

Steps to reproduce

1. Put the following in a file, say foo.vim.

nmap <silent> gx :call DebugSilent()<CR>
vmap <silent> gx :call DebugSilent()<CR>
function DebugSilent()
echomsg "from DebugSilent"
endfunction

2. Start vim and source that file.

$ vim -N --clean
:so foo.vim

3. Enter some word into the current buffer.

4. Visually select that word.

viw

5. Type the mapping.

gx

6. Note that no message appears, or just flashes by briefly.

7. Execute :messages to verify that the message was generated and
saved in message history.

8. Without visually selecting the word, type the mapping.

gx

9. Note that the message does appear in the command line and
remains there.

Expected behavior

I expect the message to remain in the command line after the
execution of the vmap just as it does for a normal map.

Version of Vim
9.0.1632

Environment

Operating system: Ubuntu 20.04
Terminal: XTerm(380)
Value of $TERM: xterm-256color
Shell: bash 5.0.17

Regards,
Gary

Bram Moolenaar

unread,
Jun 15, 2023, 11:35:28 AM6/15/23
to vim...@googlegroups.com, Gary Johnson
It appears to work as you expect when 'cmdheight' is 2 or more.

Most likely the message is cleared when the "-- VISUAL --" mode message
is removed. Setting 'noshowmode' helps.

This should not happen though, when the message overwrites the mode then
there is no need later to clear the mode message.

--
If Microsoft would build a car...
... The airbag system would ask "are you SURE?" before deploying.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Gary Johnson

unread,
Jun 15, 2023, 12:28:00 PM6/15/23
to vim...@googlegroups.com
I would expect it to work like gf (which itself is inconsistent).
If I put the cursor over "later" in the paragraph above and type
gf, I get a persistent error message in the command line:

E447: Can't find file "later" in path

If I visually-select "later" with viw and type gf, I get the same
message, but it appears for only about one second. It seems like it
should also persist, but at least I see it and can look in :messages
to read it again.

'cmdheight' doesn't seem to affect the behavior of gf, but setting
'noshowmode' does "fix" it. It would be nice if visual mode could
be made smarter about clearing "-- VISUAL --" when that message has
been overwritten, or at least leave it for a second or two as
{Visual}gf does.

Regards,
Gary

Bram Moolenaar

unread,
Jun 15, 2023, 1:45:34 PM6/15/23
to vim...@googlegroups.com, Gary Johnson
The patch I made first had a strict condition of where the message is
displayed. The "gf" error message is on a different line, causing that
condition not to be true. I'll fix that.

--
hundred-and-one symptoms of being an internet addict:
178. You look for an icon to double-click to open your bedroom window.

Gary Johnson

unread,
Jun 15, 2023, 4:45:35 PM6/15/23
to vim...@googlegroups.com
Your second patch seems to work fine, but the problem in my original
mapping and function remained. I finally found and fixed the
problem, but I don't understand what's going on.

This test mapping and function (from the original problem report)
now works fine when I move the cursor over a word and type "viwgx".

vmap <silent> gx :call DebugSilent()<CR>
function DebugSilent()
echomsg "from DebugSilent"
endfunction

But if I add this :normal command to the function, the message
disappears.

function DebugSilent()
normal gvy
echomsg "from DebugSilent"
endfunction

If I add :silent in front of the :normal command, the message
persists again as desired.

function DebugSilent()
silent normal gvy
echomsg "from DebugSilent"
endfunction

I don't understand why the :normal command affects a message echoed
_after_ the :normal command.

Regards,
Gary

Bram Moolenaar

unread,
Jun 19, 2023, 3:45:47 PM6/19/23
to vim...@googlegroups.com, Gary Johnson
When the "normal" command is executed Vim is still in Visual mode. In
that mode "gv" is an error. I'm not sure how an error is handled in
this specific situation, but a flag may be set that causes what follows
to work differently.

> If I add :silent in front of the :normal command, the message
> persists again as desired.
>
> function DebugSilent()
> silent normal gvy
> echomsg "from DebugSilent"
> endfunction
>
> I don't understand why the :normal command affects a message echoed
> _after_ the :normal command.

That is unexpected, ":silent" should not suppress the error, only
":silent!" should have that effect. I currently don't have time to look
into this. Best is to avoid the error caused by "gv", hopefully then
your problems won't occur.

--
hundred-and-one symptoms of being an internet addict:
193. You ask your girlfriend to drive home so you can sit back with
your PDA and download the information to your laptop

Gary Johnson

unread,
Jun 20, 2023, 12:14:33 PM6/20/23
to vim...@googlegroups.com
The gv doesn't generate an error message and without it, my function
doesn't yank anything.

I now have a version of my actual function that behaves as I want it
to, so in that sense, the problem has been solved. Thank you for
looking into it to the extent that you did and for your help.

If you do ever have the time and inclination to look at this
further, I can show you the actual function (it's only 17 lines), if
that would help at all.

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages