Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim's '(insert) VISUAL' mode?

Tags:

vim

insert

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?

like image 483
Ein Avatar asked Apr 24 '13 22:04

Ein


People also ask

How do I go into visual mode in Vim?

To get into the Vim Visual Line mode, press “Shift+V” while you are in Vim's Normal mode.

How do I exit visual mode in Vim?

Visual mode is a mode in which the Vim (not Vi) editor allows you to select text, either by character, by line, or by block (you may then perform various actions on the selected text). Pressing Esc would exit this mode and return you command/normal mode.

What are the three modes of Vim?

In Vim, there are three modes of operation: Normal, Insert, and Visual.


1 Answers

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.

like image 85
romainl Avatar answered Oct 05 '22 21:10

romainl