Vim's '(insert) VISUAL' mode?

2019-03-30 00:09发布

The "(insert) VISUAL" mode can be entered by CTRL+O , v starting from insert mode. This enters visual mode, but is displayed as "(insert) VISUAL" from within vim, and pressing Esc from this mode brings you back to insert mode, not normal mode. The "(insert) VISUAL" mode is also entered by shifted arrowed keys from insert mode.

Two related questions:

  1. There does not seem to be much documentation on this special mode. Is there an easy way to search for information about it? (edit: I'm aware of what CTRL+O normally does. The interaction with visual mode seems to be special. The first paragraph was the easiest way to refer to what this mode is in the first place, as I don't know of a searchable name for it.)

  2. How do you write vmap mappings reliably? Namely, is there a consistent way to leave visual mode and end up in, say normal mode? Or consistently end up in insert mode?

标签: vim insert
4条回答
对你真心纯属浪费
2楼-- · 2019-03-30 00:23

About the second question: you can switch to normal mode from any other using <C-\><C-n>. There are no commands for reliably switching to visual or insert modes this way, but if you need only always switching to normal mode after visual it is sufficient. Note that most of the visual-mode mappings are working in i<C-o>v special mode without modifications.

查看更多
Viruses.
3楼-- · 2019-03-30 00:27

It's documented at :h Operator-pending and just below that at :h mode-switching. Mappings for visual mode will also work for (insert) visual mode. See :h map-modes for a review of mode mapping. vmap will map for both visual and select modes, xmap will map for only visual but not select, and smap will map for only select but not visual. In general, you should use the noremap versions of these mapping commands to avoid unexpected behavior.

查看更多
ゆ 、 Hurt°
4楼-- · 2019-03-30 00:39

For the first question.

CTRL+O in insert mode executes one command and then exits back to insert mode. See :h i_CTRL-O.

For the second question.

I do not think you there is a reliable way to exit into one mode or another. The most reliable way I think is to start in the mode you want to end in.

查看更多
别忘想泡老子
5楼-- · 2019-03-30 00:44

In insert mode, <C-o> allows you to execute normal mode commands without leaving insert mode. Vim tries to indicate the new state with (insert). Since you are now temporally in normal mode, hitting v puts you in visual mode and Vim tries, again, to indicate the new state with (insert) VISUAL. Vim is in this state only because of the sequence of commands you performed and, as pointed out by others, that behavior is documented. At this point, it is normal and expected that <Esc> puts you back in insert mode since that's your original mode.

Someone with a deeper Vim understanding than me may be able to tell you if there's a reliable way to end up in normal from insert -> (normal) -> visual but I'd say that the whole idea sounds fishy to me.

Proper usage is:

  1. do stuff in normal mode
  2. enter insert mode to "insert" something
  3. exit insert mode to go back to normal mode
  4. do more stuff in normal mode
  5. enter visual mode
  6. do stuff in visual mode
  7. exit visual mode to go back to normal mode
  8. etc.

Basically, you are not supposed to be further than one <Esc> away from normal mode.

I can't imagine a scenario where using v after <C-o> makes any sense.

The best and preferred way to use Vim is to stay out of insert mode as much as possible. Using <C-o> to avoid leaving insert mode is a very poor strategy. I have no idea if that's what you do but, if you do it, you should reconsider that approach as soon as possible.

But I suspect you are trying to do something else which you, somehow, didn't think we needed to know.

查看更多
登录 后发表回答