-*autocmd.txt* For Vim version 9.1. Last change: 2024 May 05
+*autocmd.txt* For Vim version 9.1. Last change: 2024 Jun 20
VIM REFERENCE MANUAL by Bram Moolenaar
|CursorHold| the user doesn't press a key for a while
|CursorHoldI| the user doesn't press a key for a while in Insert mode
|CursorMoved| the cursor was moved in Normal mode
+|CursorMovedC| the cursor was moved in the |Command-line|
|CursorMovedI| the cursor was moved in Insert mode
|WinNewPre| before creating a new window
Careful: This is triggered very often, don't
do anything that the user does not expect or
that is slow.
+ *CursorMovedC*
+CursorMovedC After the cursor was moved in the command
+ line. Be careful not to mess up the
+ command line, it may cause Vim to lock up.
+ <afile> is set to a single character,
+ indicating the type of command-line.
+ |cmdwin-char|
*CursorMovedI*
CursorMovedI After the cursor was moved in Insert mode.
Not triggered when the popup menu is visible.
CursorHoldI autocmd.txt /*CursorHoldI*
CursorIM mbyte.txt /*CursorIM*
CursorMoved autocmd.txt /*CursorMoved*
+CursorMovedC autocmd.txt /*CursorMovedC*
CursorMovedI autocmd.txt /*CursorMovedI*
D change.txt /*D*
DOS os_dos.txt /*DOS*
-*version9.txt* For Vim version 9.1. Last change: 2024 Jun 19
+*version9.txt* For Vim version 9.1. Last change: 2024 Jun 20
VIM REFERENCE MANUAL by Bram Moolenaar
Autocommands: ~
+|CursorMovedC| after the cursor was moved in the comamnd-line
|SessionWritePost| after writing the session file |:mksession|
|TermResponseAll| after the terminal response to |t_RV| and others is
received
KEYVALUE_ENTRY(EVENT_CURSORHOLD, "CursorHold"),
KEYVALUE_ENTRY(EVENT_CURSORHOLDI, "CursorHoldI"),
KEYVALUE_ENTRY(EVENT_CURSORMOVED, "CursorMoved"),
+ KEYVALUE_ENTRY(EVENT_CURSORMOVEDC, "CursorMovedC"),
KEYVALUE_ENTRY(EVENT_CURSORMOVEDI, "CursorMovedI"),
KEYVALUE_ENTRY(EVENT_DIFFUPDATED, "DiffUpdated"),
KEYVALUE_ENTRY(EVENT_DIRCHANGED, "DirChanged"),
|| event == EVENT_CMDLINECHANGED
|| event == EVENT_CMDLINEENTER
|| event == EVENT_CMDLINELEAVE
+ || event == EVENT_CURSORMOVEDC
|| event == EVENT_CMDWINENTER
|| event == EVENT_CMDWINLEAVE
|| event == EVENT_CMDUNDEFINED
int res;
int save_msg_scroll = msg_scroll;
int save_State = State; // remember State when called
+ int save_cmdspos = ccline.cmdspos;
int some_key_typed = FALSE; // one of the keys was typed
// mouse drag and release events are ignored, unless they are
// preceded with a mouse down event
* (Sorry for the goto's, I know it is ugly).
*/
cmdline_not_changed:
+ // Trigger CursorMovedC autocommands.
+ if (ccline.cmdspos != save_cmdspos)
+ trigger_cmd_autocmd(cmdline_type, EVENT_CURSORMOVEDC);
+
#ifdef FEAT_SEARCH_EXTRA
if (!is_state.incsearch_postponed)
continue;
if (is_state.winid != curwin->w_id)
init_incsearch_state(&is_state);
#endif
+ // Trigger CmdlineChanged autocommands.
if (trigger_cmdlinechanged)
- // Trigger CmdlineChanged autocommands.
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED);
#ifdef FEAT_SEARCH_EXTRA
new_cmdpos = 0;
else
new_cmdpos = pos;
+
+ // Trigger CursorMovedC autocommands.
+ trigger_cmd_autocmd(get_cmdline_type(), EVENT_CURSORMOVEDC);
+
return 0;
}
au! CmdlineEnter
au! CmdlineLeave
let &shellslash = save_shellslash
+
+ au! CursorMovedC : let g:pos = getcmdpos()
+ let g:pos = 0
+ call feedkeys(":hello\<Left>\<ESC>", 'xt')
+ call assert_equal(5, g:pos)
+ call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
+ call assert_equal(3, g:pos)
+ au! CursorMovedC
+
+ " CursorMovedC changes the cursor position.
+ au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)
+ let g:pos = 0
+ call feedkeys(":hello\<Left>\<ESC>", 'xt')
+ call assert_equal(5, g:pos)
+ au! CursorMovedC
endfunc
" Test for BufWritePre autocommand that deletes or unloads the buffer.
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 507,
/**/
506,
/**/
EVENT_CURSORHOLD, // cursor in same position for a while
EVENT_CURSORHOLDI, // idem, in Insert mode
EVENT_CURSORMOVED, // cursor was moved
+ EVENT_CURSORMOVEDC, // cursor was moved in Command line mode
EVENT_CURSORMOVEDI, // cursor was moved in Insert mode
EVENT_DIFFUPDATED, // after diffs were updated
EVENT_DIRCHANGED, // after user changed directory