2

Vim is an interesting program and all, but I switched back to nano for the time being because normal mode keeps behaving strangely. This might be bugs, yet I think its just as likely that I accidently uses one of Vim's gazillion features and I don't know how to get out of it.

If you've typed things you didn't mean to in normal mode, and you want to clear what you typed, what is the way to tell Vim to start over? Does what you type in normal mode go into a buffer that needs to be cleared?

8
  • You can always "undo" whatever "changes" you made (in normal mode or otherwise) in a session !
    – Prem
    Nov 6, 2022 at 16:18
  • Adding on to Prem's comment, you can "undo" with u, and "redo" with CTRL-R
    – husB
    Nov 7, 2022 at 1:33
  • I don't really understand what you're asking. What is the specific problem you're facing? In what way does normal mode behave strangely?
    – Rich
    Nov 8, 2022 at 11:17
  • @Rich an example is me using the G key to hope to a line number but the cursor isn't budging. One thing i did to make vim behave again was start command mode with : then hit escape, but it's honestly not worth using imo if i have to do that.
    – user8919
    Nov 8, 2022 at 17:08
  • So the G key stops working but all the other keys still do work?
    – Rich
    Nov 9, 2022 at 9:17

2 Answers 2

2

I am a newbie but realised a few things so far. Vim is the beast but this comes with price: you need time to get used to it!

In Normal mode (aka command mode), you simply press u and undo the last change, which could be a deleted line, the result of regexp substitution, a repeated change by pressing . etc.

However, in insert mode, Vim considers the last change everything since the last time you entered the Insert mode: if you wrote the whole paragraph and realised you are wrong, pressing Ctrl - Ou will remove everything since you entered the mode; this is equivalent of pressing u in Normal mode, afterwards.

You can also activate a new change while in the Insert mode by pressing Ctrl - Gu and Vim will consider last change at that point.

Have a look at :help i_Ctrl-G_u and Undo in insert mode.

4

I had the problem when I started using Vim and the following advices helped me a lot.

Before the command is finished

If your buffer is not yet modified but your are in the middle of a command (e.g.: di) you can simply escape and cancel the command using Esc

If you add to your .vimrc file:

set showcmd

enter image description here

you'll see at the bottom right of the screen the command partly entered.

If you add to your .vimrc file:

set notimeout

Vim will wait forever that you complete the command (and not cancel it after a timeout). I found that useful to let me see what I'm typing in normal mode.

After the command has been executed

If your buffer has been changed and you want revert it back you can:

  • Go to normal mode using Esc
  • Undo your changes using u

Advice: Switch back regularly to Normal mode when you edit files (insert text) such that the granularity of the undo is fine enough.

Stuck in other modes

Busy recording a macro

If you hit qa you are busy recording macro a. You have in the bottom left a text telling you recording @a.

enter image description here

To stop you can either type Ctrlc to cancel the recording or q to stop the recording.

In the Ex mode

If you hit Q you are in the Ex mode:

enter image description here

To leave the visual mode you have to type visual Enter

The Ex mode is very exotic. A number add:

nnoremap Q <Nop>

This prevent you to go the Ex mode.

In the "Ed" mode

If you hit :i Enter or :a Enter you enter in "Ed" mode:

enter image description here

In this mode you have no visual clue to indicates you that you are in that mode.

You type a text that will be inserted if you validate it with .Enter

To leave the "Ed" mode without inserting anything you can type Ctrlc to go back to Normal mode.

In Summary

If you hit twice Ctrlc you can be nearly sure you are back to normal mode (with the only exception of Ex mode that I advice you to deactivate)

Cursor move

Sometime your buffer isn't changed but your cursor is moved. You can use: Ctrlo to moves it back to the previous location.

If you go too far back you can use: Ctrli to move forward in the history.

8
  • 1
    I appreciate every response to my question here, but spammin "esc" never fixes anything when normal mode stops behaving, ill decide how to respond to everything else when i get back to my desktop (which might take a while) thanks everyone.
    – user8919
    Nov 7, 2022 at 18:03
  • Maybe I didn't catch some of your use cases. Maybe have you been catch in other modes than Normal. Some screenshot Maybe helpful. For other mode Ctrl-c is some time necessary to go back to normal mode. Nov 7, 2022 at 18:34
  • 1
    Usually i'm just making standard edits, like i was having this problem: i hit dd to try and clear a line, but it went into this mode where it was only deleting characters, pressing esc wasn't changing the behavior. A picture wouldn't help, that's part of the issue is default in normal mode it doesn't display anything like command mode.
    – user8919
    Nov 8, 2022 at 17:05
  • What is the exact symptoms? You type dd in normal mode and from then on you can only delete character? Is it delete or override? Could you share a screen cast? Nov 8, 2022 at 17:15
  • 1
    @thinksinbinary C-o u would undo from insert mode, or in normal mode jump back and then undo. That doesn't make much sense to me. Can you try with something like vim --clean (How to debug my vimrc)?
    – D. Ben Knoble
    Nov 8, 2022 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.