Vim can be in "stacked-mode", like insert -> <c-o> -> :norm! is normal-mode inside-command-mode inside insert-mode.
mode() function reports ony one mode, this is incompete info. It makes a difference whether we are in "command-mode inside insert-mode", or in "command-mode not inside insert mode". Currently, with mode(), script does not know this. Is it possible to add function to make script aware of the whole stack of modes vim is currently in ? Yakov