1. 44

  2. 27

    I once walked up to the computer of a colleague new to linux. He know how to exit, but he didn’t know how not to exit. Every single time he needed to save he did a :wq and then re-opened the file.

    1. 9

      A coworker once asked me how to exit vim. When I got to her desk, though, she said she had already solved it.



      1. 8

        TLDR for posterity: type esc like 4 times just to be sure, then colon then letter q (to quit without saving) or the letters qw (to quit and write/save the data) and then hit enter.

        1. 6

          if you’re in crazy mode you might need a double :q (or :q followed by :q!)

          1. 8

            Vim mode (anti-)golf!

            How about something Deep Vim like: digraph inside the expression register inside Ex inside Insert (to get here: i<Ctrl-O>gQ<Ctrl-R>=<Ctrl-K>)? From here hitting escape n times doesn’t work.

            A sequence of commands that works no matter where you are in that stack of modes is something like:

            1. <Esc> exit digraph mode (or do nothing in Ex-Mode or expression-register)
            2. <Ctrl-U><Enter> exit expression register (or execute empty command in Ex-Mode)
            3. <Ctrl-U>vi<Enter> exit Ex-Mode
            4. <Esc>:qa! exit Insert mode and quit

            This sequence also works for other modes I tried, like a half-entered command inside Insert-Visual (i<Ctrl-O>vg) – here, pushing v in step 3 gets you back into Insert and then the rest will exit.

          2. 3

            for posterity: it’s actually :q! if you made changes and you want to exit without saving.

            1. 4

              Nope. If you already in insert mode you can :q! until you blue in the face.

              esc :q!

              usually saves the day.

            2. 3

              the letters qw (to quit and write/save the data)

              I recently discovered that x does the same job as qw. Now I remember q for exit with no changes (or q! as @weaksauce points out), and x for exit-and-save

              1. 1

                I use that too, but I think for new people its better for them to learn qw first so they know w is write and q is quit. Like building a vocabulary for vim commands.

            3. 4

              I have the same problem with nano - give me vi any day :~)

              1. 3

                nano displays the shortcut to exit at the bottom (provided you know what keys ^X are)

                1. 2

                  And vim tells you to type :quit<enter> when you press Ctrl-C.

                  (Why not simply exit when Ctrl-C is pressed? Because in vim Ctrl-C is used to abort an operation that’s taking too long, eg. a search over a gigantic file.)

              2. 3

                ZZ for terseness sake? (two keypresses rather than three ;)

                1. 1

                  Isn’t that still three, because shift? :)

                  1. 3

                    Well yeah but it still occurs over the space of two key presses since its a combo. Besides :q is four by that definition

                2. 3

                  I remember my first time on vim. I couldn’t even exit. I tried typing ctrl-q, alt-q, esc, q, quit, exit, alt-f4, f1, help, smashing the keyboard etc. none of that worked.

                  And that’s why I’m an emacs user.

                  1. 4

                    How is quitting emacs easier? I remember the first time I tried emacs I had the same problem… impossible to quit. Isn’t quitting emacs: “ctrl-x” followed by “ctrl-c”?