Strange behavior about <C-o> in Insert mode

43 views
Skip to first unread message

Kana Natsuno

unread,
Apr 7, 2012, 11:00:51 PM4/7/12
to vim_dev
According to the :help i_CTRL-O --

> The CTRL-O command takes you to Normal mode. If you then use a command enter
> Insert mode again it doesn't nest. Thus when typing "a<C-O>a" and then <Esc>
> takes you back to Normal mode, you do not need to type <Esc> twice.

There are several commands to enter Insert mode, for example, a, i, S,
cc.
So I think that Insert mode will never be nested even if such commands
are
used after <C-o>. But Vim seems not to behave so. For example:

$ vim -u NONE -N -e -s -c 'execute "normal!" "ifoo\<C-o>abar
\<Esc>Fb" | verbose echo getline(1, "$") line(".") col(".") | qall!'
['foobar'] 1 4

$ vim -u NONE -N -e -s -c 'execute "normal!" "ifoo\<C-o>ccbar
\<Esc>Fb" | verbose echo getline(1, "$") line(".") col(".") | qall!'
['barFb'] 1 5

$ vim -u NONE -N -e -s -c 'execute "normal!" "ifoo\<C-o>Sbar
\<Esc>Fb" | verbose echo getline(1, "$") line(".") col(".") | qall!'
['barFb'] 1 5

<C-o>a works as documented. But both <C-o>cc and <C-o>S don't work as
documented. They behave as if Insert mode is nested.

Furthermode, <C-o>cc and <C-o>S work as documented if they are
interactively
typed by user. The "nested" behavior only happens if <C-o>cc and <C-
o>S are
executed via :normal or :map.

Is this behavior intentional?
I confirmed it with the following :version:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Apr 8 2012 11:17:30)
MacOS X (unix) version
Included patches: 1-494
Compiled by kana@avril
Huge version without GUI. Features included (+) or not (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset
+cindent
-clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info
+comments
+conceal +cryptv -cscope +cursorbind +cursorshape +dialog_con +diff
+digraphs
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi
+file_in_path
+find_in_path +float +folding -footer +fork() -gettext -hangul_input
+iconv
+insert_expand +jumplist +keymap +langmap +libcall +linebreak
+lispindent
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -
mouseshape
+mouse_dec -mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse
+mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme -
netbeans_intg
+path_extra -perl +persistent_undo +postscript +printer +profile -
python
-python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs
+smartindent
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse
+textobjects +title
-toolbar +user_commands +vertsplit +virtualedit +visual +visualextra
+viminfo
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -
xim -xsmp
-xterm_clipboard -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/Users/kana/.vvm/vims/vimorg--v7-3-494/share/
vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -no-
cpp-precomp -g -O -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -o vim -lm -lncurses -liconv -
framework Cocoa

h_east

unread,
Apr 18, 2012, 12:24:43 PM4/18/12
to vim...@googlegroups.com
Hi, Kana and Bram

2012/4/8(Sun) 12:00:51 UTC+9 Kana Natsuno:

I fixed this. But It may be broke below comment's behavior...
(normal.c : 2019~)
/* This is a new edit command, not a restart. Need to
* remember it to make 'insertmode' work with mappings for
* Visual mode. But do this only once and not when typed and
* 'insertmode' isn't set. */

What do you think?

Regards,
--
Hirohito Higashi

patch_i_ctrl-o.diff

Bram Moolenaar

unread,
Apr 18, 2012, 4:56:42 PM4/18/12
to h_east, vim...@googlegroups.com

Hirohito Higashi wrote:

This looks risky. We need to make sure this actually fixes the problem.
What is the problem really? Perhaps it's just a documentation
unclarity?

Keep in mind that typing something and executing a mapping or command
from the command line may work slightly different.


--
FATHER: You only killed the bride's father - that's all -
LAUNCELOT: Oh dear, I didn't really mean to...
FATHER: Didn't mean to? You put your sword right through his head!
LAUNCELOT: Gosh - Is he all right?
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

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

Reply all
Reply to author
Forward
0 new messages