Skip to content

Commit 612cc38

Browse files
committed
patch 8.1.0225: mode() does not indicate using CTRL-O from Insert mode
Problem: Mode() does not indicate using CTRL-O from Insert mode. Solution: Add "niI", "niR" and "niV" to mode() result. (closes #3000)
1 parent 91f84f6 commit 612cc38

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

runtime/doc/eval.txt

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6224,32 +6224,38 @@ mode([expr]) Return a string that indicates the current mode.
62246224
a non-empty String (|non-zero-arg|), then the full mode is
62256225
returned, otherwise only the first letter is returned.
62266226

6227-
n Normal, Terminal-Normal
6228-
no Operator-pending
6229-
v Visual by character
6230-
V Visual by line
6231-
CTRL-V Visual blockwise
6232-
s Select by character
6233-
S Select by line
6234-
CTRL-S Select blockwise
6235-
i Insert
6236-
ic Insert mode completion |compl-generic|
6237-
ix Insert mode |i_CTRL-X| completion
6238-
R Replace |R|
6239-
Rc Replace mode completion |compl-generic|
6240-
Rv Virtual Replace |gR|
6241-
Rx Replace mode |i_CTRL-X| completion
6242-
c Command-line editing
6243-
cv Vim Ex mode |gQ|
6244-
ce Normal Ex mode |Q|
6245-
r Hit-enter prompt
6246-
rm The -- more -- prompt
6247-
r? A |:confirm| query of some sort
6248-
! Shell or external command is executing
6249-
t Terminal-Job mode: keys go to the job
6227+
n Normal, Terminal-Normal
6228+
no Operator-pending
6229+
niI Normal using |i_CTRL-O| in |Insert-mode|
6230+
niR Normal using |i_CTRL-O| in |Replace-mode|
6231+
niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6232+
v Visual by character
6233+
V Visual by line
6234+
CTRL-V Visual blockwise
6235+
s Select by character
6236+
S Select by line
6237+
CTRL-S Select blockwise
6238+
i Insert
6239+
ic Insert mode completion |compl-generic|
6240+
ix Insert mode |i_CTRL-X| completion
6241+
R Replace |R|
6242+
Rc Replace mode completion |compl-generic|
6243+
Rv Virtual Replace |gR|
6244+
Rx Replace mode |i_CTRL-X| completion
6245+
c Command-line editing
6246+
cv Vim Ex mode |gQ|
6247+
ce Normal Ex mode |Q|
6248+
r Hit-enter prompt
6249+
rm The -- more -- prompt
6250+
r? A |:confirm| query of some sort
6251+
! Shell or external command is executing
6252+
t Terminal-Job mode: keys go to the job
62506253
This is useful in the 'statusline' option or when used
62516254
with |remote_expr()| In most other places it always returns
62526255
"c" or "n".
6256+
Note that in the future more modes and more specific modes may
6257+
be added. It's better not to compare the whole string but only
6258+
the leading character(s).
62536259
Also see |visualmode()|.
62546260

62556261
mzeval({expr}) *mzeval()*

src/evalfunc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8366,10 +8366,9 @@ f_mkdir(typval_T *argvars, typval_T *rettv)
83668366
static void
83678367
f_mode(typval_T *argvars, typval_T *rettv)
83688368
{
8369-
char_u buf[3];
8369+
char_u buf[4];
83708370

8371-
buf[1] = NUL;
8372-
buf[2] = NUL;
8371+
vim_memset(buf, 0, sizeof(buf));
83738372

83748373
if (time_for_testing == 93784)
83758374
{
@@ -8435,6 +8434,12 @@ f_mode(typval_T *argvars, typval_T *rettv)
84358434
buf[0] = 'n';
84368435
if (finish_op)
84378436
buf[1] = 'o';
8437+
else if (restart_edit == 'I' || restart_edit == 'R'
8438+
|| restart_edit == 'V')
8439+
{
8440+
buf[1] = 'i';
8441+
buf[2] = restart_edit;
8442+
}
84388443
}
84398444

84408445
/* Clear out the minor mode when the argument is not a non-zero number or

src/testdir/test_functions.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,18 @@ func Test_mode()
464464
call assert_equal('n', mode(0))
465465
call assert_equal('n', mode(1))
466466

467+
" i_CTRL-O
468+
exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>"
469+
call assert_equal("n-niI", g:current_modes)
470+
471+
" R_CTRL-O
472+
exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>"
473+
call assert_equal("n-niR", g:current_modes)
474+
475+
" gR_CTRL-O
476+
exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>"
477+
call assert_equal("n-niV", g:current_modes)
478+
467479
" How to test operator-pending mode?
468480

469481
call feedkeys("v", 'xt')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ static char *(features[]) =
798798

799799
static int included_patches[] =
800800
{ /* Add new patch number below this line */
801+
/**/
802+
225,
801803
/**/
802804
224,
803805
/**/

0 commit comments

Comments
 (0)