How do I exit the Vim editor?

后端 未结 10 2263
青春惊慌失措
青春惊慌失措 2020-11-22 02:26

I\'m stuck and cannot escape. It says:

\"type :quit to quit VIM\"

But when I type that it simply appears in the object body.

相关标签:
10条回答
  • 2020-11-22 03:10

    In case you need to exit Vim in easy mode (while using -y option) you can enter normal Vim mode by hitting Ctrl + L and then any of the normal exiting options will work.

    0 讨论(0)
  • 2020-11-22 03:10

    I got Vim by installing a Git client on Windows. :q wouldn't exit Vim for me. :exit did however...

    0 讨论(0)
  • 2020-11-22 03:16

    The question has been asked here.

    The q command with a number closes the given split in that position.

    :q<split position> or :<split position>q will close the split in that position.

    Let's say your Vim window layout is as follows:

    -------------------------------------------------
    |               |               |               |
    -------------------------------------------------
    |               |               |               |
    |               |               |               |
    |    Split 1    |    Split 2    |     Split 3   |
    |               |               |               |
    -------------------------------------------------
    

    If you run the q1 command, it will close the first split. q2 will close the second split and vice versa.

    The order of split position in the quit command does not matter. :2q or :q2 will close the second split.

    If the split position you pass to the command is greater than the number of current splits, it will simply close the last split.

    For example, if you run the q100 on the above window setup where there are only three splits, it will close the last split (Split 3).

    0 讨论(0)
  • 2020-11-22 03:19

    This is for the worst-case scenario of exiting Vim if you just want out, have no idea what you've done and you don't care what will happen to the files you opened.

    Ctrl-cEnterEnterviEnterCtrl-\Ctrl-n:qa!Enter

    This should get you out most of the time.

    Some interesting cases where you need something like this:

    • iCtrl-ovg (you enter insert mode, then visual mode and then operator pending mode)

    • QappendEnter

    • iCtrl-ogQCtrl-r=Ctrl-k (thanks to porges for this case)

    • :set insertmode (this is a case when Ctrl-\Ctrl-n returns you to normal mode)


    Edit: This answer was corrected due to cases above. It used to be:

    EscEscEsc:qa!Enter

    However, that doesn't work if you have entered Ex mode. In that case you would need to do:

    viEnter:qa!Enter

    So a complete command for "I don't want to know what I've done and I don't want to save anything, I just want out now!" would be

    viEnterEscEscEsc:qa!Enter

    0 讨论(0)
提交回复
热议问题