-*autocmd.txt* For Vim version 9.1. Last change: 2024 Jul 11
+*autocmd.txt* For Vim version 9.1. Last change: 2024 Jul 17
VIM REFERENCE MANUAL by Bram Moolenaar
InsertLeave Just after leaving Insert mode. Also when
using CTRL-O |i_CTRL-O|. But not for |i_CTRL-C|.
*KeyInputPre*
-KeyInputPre Just before a key is processed. The pattern is
- matched against a string that indicates the
- current mode, which is the same as what is
- returned by `mode(1)`.
+KeyInputPre Just before a key is processed after mappings
+ have been applied. The pattern is matched
+ against a string that indicates the current
+ mode, which is the same as what is returned by
+ `mode(1)`.
The |v:char| variable indicates the key typed
and can be changed during the event to process
a different key. When |v:char| is not a
character is used.
The following values of |v:event| are set:
typed The key is typed or not.
+ typedchar The (actual) typed key.
It is not allowed to change the text
|textlock| or the current mode.
{only with the +eval feature}
static int typeahead_char = 0; // typeahead char that's not flushed
+#ifdef FEAT_EVAL
+static char_u typedchars[MAXMAPLEN + 1] = { NUL }; // typed chars before map
+static int typedchars_pos = 0;
+#endif
+
/*
* When block_redo is TRUE the redo buffer will not be changed.
* Used by edit() to repeat insertions.
ml_sync_all(c == 0, TRUE);
count = 0;
}
+#ifdef FEAT_EVAL
+ if (typedchars_pos < MAXMAPLEN)
+ {
+ typedchars[typedchars_pos] = c;
+ typedchars_pos++;
+ }
+#endif
}
/*
#ifdef FEAT_EVAL
c = do_key_input_pre(c);
+
+ // Clear the next typedchars_pos
+ typedchars_pos = 0;
#endif
// Need to process the character before we know it's safe to do something
else
buf[(*mb_char2bytes)(c, buf)] = NUL;
+ typedchars[typedchars_pos] = NUL;
+ vim_unescape_csi(typedchars);
+
get_mode(curr_mode);
// Lock the text to avoid weird things from happening.
v_event = get_v_event(&save_v_event);
(void)dict_add_bool(v_event, "typed", KeyTyped);
+ (void)dict_add_string(v_event, "typedchar", typedchars);
if (apply_autocmds(EVENT_KEYINPUTPRE, curr_mode, curr_mode, FALSE, curbuf)
&& STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0)
call feedkeys('j', 'nx')
au! KeyInputPre
+
+ " Test for v:event.typedchar
+ nnoremap j k
+ au KeyInputPre n
+ \ call assert_equal(v:event.typedchar, 'j')
+ \ | call assert_equal(v:char, 'k')
+ call feedkeys('j', 'tx')
+
+ au! KeyInputPre
endfunc
" vim: shiftwidth=2 sts=2 expandtab
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 597,
/**/
596,
/**/