Hacker News new | past | comments | ask | show | jobs | submit login
How to Get Out of Vi (2015) (liw.fi)
46 points by Brajeshwar 10 months ago | hide | past | favorite | 50 comments



Additional methods for vi(m) users [0] :p

[0]: https://github.com/hakluke/how-to-exit-vim


I'm surprised Ctrl-Z, kill -9 %1 is not on there :-)


The real question is why would anyone want to leave Vim.

If, by any chance, you've entered it accidentally, acknowledge the fortuitous twist of fate you've just witnessed and enjoy the enlightenment that is soon to follow.


I used vi once. In fact I still am, because I can't exit.


Perhaps because you want to edit some text?


Then you came to the right place and “recursive” is the best possible user name for such reply.


Bad advice. Just :q not :q!

Let it give you the warning and then hit :q! if you're really sure.

Also, it's probably better to tell new vi users to write and exit with :w it works just as well and is more consistent.


I use :wq always when saving and exiting so I can see and remember exactly what's happening, despite shortcuts existing.

And :q when just exiting as you mentioned for exactly this reason. Tell me I'm quitting without saving so I can decide what to do next.


:w only writes, doesn't exit. :wq writes and exits, or :x


I have found a new "how-to-quit-it" challenge for myself in the past weeks.

I use minicom to communicate with some devices via serial-over-USB - I also tend to suspend my machine while there is still an active connection. When I unsuspend my machine, often my serial connection changes address - and minicom complains that it can't communicate anymore. And here comes the challenge: `ctrl-a q` supposed to quit, but not in this state - it stays unresponsive to all combos I try. I literally smash all keys on my keyboard, and then `ctrl-a q` start working again for some reason.

Maybe `ctrl-smash-everything-78-times` is an easter egg... oh well, I guess I will figure it out one day.


My personal "how-to-quit-it" challenge was Windows 8. I tried to approach it from the perspective of someone who has previously used Windows but is not a power user knowing shortcuts like Alt + F4 or Ctrl + Alt + Del. In the first Windows 8 versions, it was not obvious at all how to turn off the computer. The classic start menu was gone. The start menu button had no context menu, as far as I can remember. There was no obvious button in the "new" full-screen start menu. I tried quite a few places, I think in the end it took me close to ten minutes to figure out that I had to click on the user profile picture in the new start menu to reach the shutdown option, or something like that. It really was all but obvious. In later updates they improved it a bit.


This happens to me with screen. I end up spamming Ctrl-C and Ctrl-D until something positive happens.


I love that vi lost this part of the propaganda battle versus Emacs, when Emacs has the unintuitive ^C^X exit sequence. Maybe it also had a file menu?


I was a bit confused when you mentioned this, but then I realised the actual sequence is ^X^C. It's because ctrl-X is a sort of metacharacter, and ctrl-C is used for the standard INT signal you know from other programs.

And to be fair, GTK emacs has File->Quit as well (which helpfully reminds you you could use C-x C-c instead!).


And I did not speak out, for I was a nano user.


Now that everyone uses VSCode, who is left to speak for you?


I still use nano! The nice part about it is that it shows the command keys at the bottom. I forget what it is to exit, but I don’t need to remember!


Nano is very supportive, any time I find myself using it it knows that what I need most is to "Exit" and "Get Help"


As it should be. I miss Windows 95 for stuff like this


^X^C, but yes, Emacs also has a menu by default so you can click your way out of it.


> Given that the vi user interface is logical, and therefore easy to learn

This is the number one problem with tech industry. Autists don't understand that people other than them don't spend thousands of hours on what they so happen to be intersted in (for example caring this much about one text editor, when there are literally 1000 other things to learn in operating a computer). While you're at it, explain that you are supposed to press esc then wait 500ms (it's obvious why it works this way if you invest a few hundred hours in studying terminals) then type :q and explain that people born in 2010 are supposed to know what a terminal is even though nobody even used terminals by the late 90s.


Did this used to be real? It’s just :q, or escape first if you aren’t in normal mode. Is this going over my head?


Most users who struggle with this don't know that vim has modes, and often have found themselves forced into vim accidentally, e.g. having automatically launched vim by running "git commit."

In order to quit vim, you have to understand the difference between normal mode and insert mode, and you have to understand the difference between :q and :q!.

If you :q when you wanted to :q!, you're going to get this useless error message:

    E37: No write since last change (add ! to override)
But if you don't know about :q!, "(add ! to override)" means nothing. Override what? How do I "add !"??

And since you're a total novice, it's likely that you don't even know that you haven't saved your changes to disk yet, so it's not clear to you that "No write since last change" is calling you to :w before :q.

And if you try to explain all that, the user gets pouty. "I just want to quit vim! Why do I have to learn all of this stuff just to stop using it?!?"


:q! if you’ve changed something since the last write.


ZZ if you're musically inclined.


ZZ and then afterwards `top` just to make sure you really quit


Also cq if you want to exit with an exit code, which is useful if Vim was launched to write a Git commit message.


I end up stuck forgetting how to get out of nano more than vi(m).

Someone should make a safe "get out of any editor" sequence. Kind of like those universal remotes that send all the codes for each button.


Since we're here talking about Vim, hope everyone doesn't mind me asking this question!

This is specifically about neovim, but I've run into the same issue with regular Vim too. I want to install and use packages like NERDTree and maybe an LSP. I do not want to have to install Node for these plugins. If I want to add plugins to neovim, is it pretty much a given I also have to maintain a Node install?


I am not sure why the advice starts with "ctrl+q". In insert mode, "ctrl+q" followed by "ctrl+c" will cause the literal ctrl+c character to be inserted, and ":q!" after that won't have the desired effect. Similarly for search mode.

A better suggestion is probably to just hit Esc repeatedly to try to get back to normal mode, and exit via ZZ (save) or ZQ (don't save).


I read this post in a sarcastic voice. Better that way.


The page reminds me the git revert last commit panic search. Get me out this ultra efficient editor!


Interesting - in the early 80s I was trying out vi and emacs to decide which I preferred and it was because it took me 30 minutes to figure out how to exit emacs that pushed me into a lifetime of vi and latterly vim.


  :!bash


I have a print of these commands stuck on a pinboard near me. For the 1 or 0 times per year I need to edit some config file on a machine where vi is the only sensible option.


>vi is the only sensible option

Of course, that's a tautology.

What? It's flamewardnesday.



I was hoping this would be about someone who was stuck in/addicted to Vi and wanted to use another editor.


What's wrong with using :q ?


To a novice it appears not to work if you've hit Ctrl+S in your terminal to suspend output, for example. Ctrl+Q to release your terminal, Ctrl+C to return control to Vi if something else has it, Esc to get into normal mode if you're not already there.


Thanks for clarifying. I understand this is a bit different, but if folks are using vim, the best resource (in my opinion) for novices is vimtutor. Just type "vimtutor" in the console. It uses an interactive tutorial to explain the basics of editing, saving, moving around — plus the various modes.


A rite of passage in the pre-Google time: your computer suddenly enters this unfamiliar editor and you have no idea what to do.

(People who love getting hazed and being in cults are then converted into vim users, I guess.)


You never leave Vim. And Vim never leaves you.


^[:q


"Did you try turning your computer off and then back on again?"


I typed all of this out, and I'm still stuck in Vi. Please send help. /s


Usually, I just restart my computer. So far, it's worked every time.


:q!


OMG this page was hilarious. What's funnier is that I don't think the author was trying to be funny, I think the author was trying to seed Google searches.

Anyway, sometimes Git is misconfigured and dumps me into vi. (I use Windows.) When this happens, I just open Task Manager and kill the process. Otherwise, I have no need to learn vi, nor do I think vi is a useful skill to learn.


The variants of the vi editor are found in a vast array of POSIX systems, and knowledge of it is invaluable for these platforms.

There is a well-known tutor file that will teach the basic use of vi. On the RedHat 9 family, this is the manual page:

  $ rpm -ql vim-common | grep tutor | grep man/man1
  /usr/share/man/man1/gvimtutor.1.gz
  /usr/share/man/man1/vimtutor.1.gz
Loading Oracle Linux 9 into the WSL subsystem on Windows will bring in this RPM.

  C:\Users\bofh\>wsl.exe -l -o
  The following is a list of valid distributions that can be installed.
  The default distribution is denoted by '*'.
  Install using 'wsl --install -d <Distro>'.

    NAME                                   FRIENDLY NAME
  * Ubuntu                                 Ubuntu
    Debian                                 Debian GNU/Linux
    kali-linux                             Kali Linux Rolling
    Ubuntu-18.04                           Ubuntu 18.04 LTS
    Ubuntu-20.04                           Ubuntu 20.04 LTS
    Ubuntu-22.04                           Ubuntu 22.04 LTS
    OracleLinux_7_9                        Oracle Linux 7.9
    OracleLinux_8_7                        Oracle Linux 8.7
    OracleLinux_9_1                        Oracle Linux 9.1
    openSUSE-Leap-15.5                     openSUSE Leap 15.5
    SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
    SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
    openSUSE-Tumbleweed                    openSUSE Tumbleweed




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: