As a vim noob, I needed to look it up [0]. ZZ saves the current file if modified and closes it. ZQ closes it without saving. Thank you, that will save me a few seconds per year.
Why the French way? I don't get it and I am very curious :-)
BRS, that old classic Big Red Switch, kills all known operating systems and proc's, dead in their tracks.
Me, It's usually :wq, or sometimes :q! or more than likely ZZ - which can be done with shift zz or if you truly want to do it with just one finger, capslock then zz.
That is because it is easier to teach as x you will associate with exit, though wq is write quite, but more so if you just want to save without exit you logically understand to just use w and from that you start to think - could I do :q, why yes you can if nothing changed and if so it will tell you.
But stressing how people exit vi is like stressing about people's fashion, just not worth it. If anything, have a private laugh at them to yourself and use that to remove other stress as more than enough stress in life, more so IT without seeking it out.
Oh looks, it's only been 10 minutes since the last Vim article was trending on HN, we're rivalling Hollywood levels of bubble here.
Seriously, when CES is currently showing hundreds of new tech products and services, including a Hyundai electric helicopter - Vim is what we still talk about?
Yes, but it’s never been just about startups or business. It’s always been any topic of interest to hacker types which includes startups and business, but also technology, programming, tools, peoples projects and even sometimes satire of such.
Vim is still VERY relevant. Lot's of us prefer its keyboard driven interface and it runs everywhere so if you do learn it it's something you can always have with you.
It's not like VS Code has much in the way of functionality that's not available to Vim/Nvim users via VSCode's extensions or LSP servers.
You have just been arrested on suspicion of wrong-think. If this audience loves Vim and you don't, you have landed on the wrong planet and committed a thought-crime.
You don't have to say anything because the HN jury has already found you guilty on multiple accounts of high treason with a thought-crime and the maximum penalty is a lifetime ban.
Oh look, it’s only been 10 minutes since somebody complained that a post shouldn’t be on HN or that a topic is over represented and what a bubble HN is!
Bold claim, and how would you know? What if there is a network partition preventing you from getting the message that exiting vi failed and Chuck Norris?
The question is not "How" but "Why" you would want to ever do that in the first place;-)
Many years ago I knew a university professor and students said about him he might leave uni occasionally but he sure never leaves Emacs. Some live in Emacs, some live in Vim.
I live in a different universe to you it seems. The only vim command I know is :q.
Honestly, I tried several times over the decades and walked away with my head buzzing.
PS: I don't live in emacs either!
What I do love in both camps is how the explanations begin... "All you have to do is...[insert irrational (to non-vim/emacs users) command]" which makes me laugh every time.
Love the article, which ironically proves my stance of me keeping well clear.
I know some basic commands and know it well enough to edit git commit messages and interactive rebase (`ddkP` is probably the most advanced command I know). But I've never thought "I prefer this over my regular editor this is amazing". I just don't get the satisfaction.
And of course I'd have to dive deep into the ecosystem in order to get the same benefits that my main editor provides out of the box, like idk, cmd+click to go to definition, or error reporting like squiggly red lines.
> And of course I'd have to dive deep into the ecosystem in order to get the same benefits that my main editor provides out of the box,
To me, vim shines as a modal editor, not an IDE. I use it for two purpose:
1. quick editing configuration files, or single file scripts
2. an editing mode in an IDE (mostly VSCode)
The main benefit of vim is to save you from using the mouse or the touch pad. I touch type, my indexes rest on F and J, and I can do pretty much anything without leaving the keyboard, without using the arrow keys, and keeping my eyes on the screen. It's not something I'd know how to do without Vim. If I'm using the arrow keys, I need extra-time to relocate the "J" key, which breaks the typing flow.
My hypothesis is that vim style work (without moving a wrist even a bit) is the reason people get carpel tunnel. I anecdotally see far fewer (none?) People who don't do vim/emacs getting these injuries. Makes sense as well right? Just like "take a walk and don't sit in the same place" but for your fingers
I don't know about carpel tunnel, but the reason I became interested in Vim/Emacs was due to RSI caused by using a mouse. This was my first job, doing shudders Java-EE (7) web development (no live re-loading, tons of clicking in IDE, manually reloading web-page etc, crappy windows touch-pad etc).
Started learning Rails, drank the Kool-Aid, switched to VIM. I don't use VIM for development at my day-job, mostly just key-bindings in Intellij/VS Code, however, the amount of time saved has been worth the effort, and no RSI (also thankfully am able to use the fantastic track-pad on mac and a trackball for anything else).
Lately I've been feeling the pull to learn Emacs after learning about ORG-Mode and the extensibility of the software... unfortunately, the time investment here is likely to have no real benefit in my (current) work as a Java dev. Sigh, time to browse the who's hiring thread.
Using Vim has helped my finger/wrist/arm/shoulder/neck pain and soreness, but you're on to something in that the real problem is probably more repetitive motions than any specific motions.
But Vim (and emacs) solves the repetitive motion problem by providing several means of readily repeating commands.
Most people seem to both type and use their mouse much more slowly than I do. And they also don't often have to (or want to), e.g. cleanup thousands of rows in an Excel worksheet, or have to repeat some kind of action in an app or web app dozens of times.
But I hate using my mouse generally. There are very few times where I want to use a mouse and having to use one, instead of being able to use the keyboard, is endlessly frustrating.
Thankfully, there are several great 'vi-style' browser extensions and there's even [Vimac](https://vimacapp.com/) for MacOS, tho I haven't tried the latter yet.
Maybe that's a bit like saying that running shoes are harmful because people with running shoes sustain running-related injuries more often than the average person, who in reality just doesn't run as much.
If you don't like vim for that you can point to another executable by setting gitconfig core.editor to an executable command which starts an editor of your choice. Mine points to Notepad++ (Windows box with msysgit installed).
Mileage may vary depending on language support, but vim does have a go to definition feature[1][2]. I believe there is also out box error checking for some languages, and if that is not enough for you (and at the risk of offending a large number of vim purists), there is a fantastic plugin called ALE[3] that will likely provide you with what you want.
text objects are a big reason for the satisfaction for me. I spend a fair amount of time moving code around and I like being able to say "delete everything in this indentation level and copy it" in 3 keystrokes. It's pretty sweet when you're use to it and you have it customized to do what you want (which takes time and isn't for everyone).
I honestly don't know how vim deals with unsaved changes upon shutdown and don't use it enough to look that up, so that's why I'll first exit.
As to why shutdown: cultural thing in the end. I was raised with the idea that wasting is bad (and objectively speaking it's very hard to argue with that) so if I don't need the machine running after I'm done with it, I just can't stand the idea of the thing using energy literally for nothing.
Depends on how you configure your swap, backup and undo files. You can have all the extremes from "everything is lost" to "everything is saved" if you suddenly kill the vim process.
Emacs users live in emacs, but vim users usually live in the terminal, not directly in vim. Good thing there's a terminal version with vim bindings of pretty much every program out there :)
(As I finished writing this, and was about to type ^[fG to submit this reply, I couldn't help but smile a bit)
I came into this with a sense of "oh not again" and came out surprisingly happy. TIL that ZZ, ZQ exist and that a disown command exist on the command line.
Also my preferred method from the list is the timeout, it would be nice to have counter in a corner of the vim window to know how much time is left though.
It's amazing to think how far we've come since June 2018 where the record was just shy of three minutes (https://www.youtube.com/watch?v=TLbfqZBL8t8). These new strategies could allow experienced speedrunners to exit vim in times of 10 seconds (or perhaps less!?). I'm excited to see how this progresses, the vim speedrun community is vibrant and creative and I've no doubt we'll see a sub 5-second run within my lifetime.
Since the real world is not necessarily deterministic as demonstrated by the methods using random(), I hope to see more development in stochastical methods describing parameters of probability distributions of successful exits.
In the face of vim's unyielding resilience to exiting, I think we may need to devise a new algorithm for this using quantum superposition. I heard IBM can help with that.
But who would support it? While a formally verified functional approach may satisfy one's doctorate requirements, the author will graduate and move onto blockchain development, leaving behind an exit-vim code base that no other engineer could possibly understand without the equivalent training. Upon receiving said training, an engineer would also take newly acquired doctorate and also move onto blockchain development. Essentially, supporting a formally verified functional approach to exiting Vim creates a pipeline of well-credentialed and rigorously trained professionals for blockchain development. If Vim were, however, put on the blockchain, we may be able to address this concern and you can get what you wanted.
I'm confident we're at the dawn of a new era of AI driven vim closing.
My first attempts ended up with my bot buying stock in a clorox brand before posting questionably racist comments to my twitter, but these are minor concerns on the journey.
I'm streaming the process on twitch but please note that donations won't be considered as seed capital for stock assignment
> - So, how did you learn Vim? I heard there's quite a learning curve.
You can go through the interactive vimtutor.
Type :help tutor
Or you can just type :help and find the link to the vimtutor. If you are using gVim, then it should be one of the menu items ( maybe under help? ).
My suggestion is to just search for basic vim cheat sheet if you are getting started. There are also youtube tutorials online. Sometimes watching someone work with vim can help you get over the hump.
> - I just open it, but I couldn't figure out how to quit.
:q to quit.
:q! to quit without saving.
Remember to hit ESC to get back to the normal mode first if you are in other modes.
When you are comfortable with Vim then you can go on to some of the advanced vim topics. Also, in the beginning you might have to ddg/google/etc a bit. Good luck.
I have tried to start using vim so many times and failed. Even this year I thought to start using vim. Daily I open vim once try to do something new with it. Although I don't have much of hope that I will start using it an soon.
I first used vi / vim about 30 years back. There are other editors that provide fancy features and I do use them routinely but there is no day I have not started (and exited) vim. Get used to it.
As a sysadmin, not a programmer, what I found helpful for learning Vim was not to try something new each day, but to find one or two commands that were valuable enough that I would at least open Vim somewhat regularly. The two that did it for me are delete line (dd), and change inner word (ciw), both extremely helpful for config file editing, especially when combined with repeat command (.)
After learning these first simple commands, it was enough to get me to open Vim at least a few times a day, which then motivated me to start learning more of the commands and it just snowballed along. I still only know probably 25% of Vim, but I feel incredibly comfortable in it now and rarely run into trouble when doing beginner to intermediate editing tasks.
As a fellow sysadmin, I would advise to learn vi properly then switch to Vim because the former is pretty much everywhere, and for example you could mess the file with cursor keys in Insert mode instead of using hjkl in it.
That's good advice, but in all practical situations I have been able to use Vim directly or know enough vi to get by, though I am much less comfortable with it.
I don't touch type, so hjkl, even though I understand the benefits, has never been my preference. Perhaps it's the gamer in me, I've never had trouble using the arrow keys :)
One neat thing this misses is that in ASCII, H is left, CTRL-H is backspace (which goes left while doing a thing); J is down, CTRL-J is linefeed (which goes down while doing a thing, sorta). It ends there, unfortunately - I don't see a good connection between vertical tab and up or formfeed and right.
I've made quasi-regular attempts to get truly comfortable with both Emacs and Vim at various points over the... last two decades, honestly. Strangely, I was always a little more comfortable in Vim, even though the other editors I've been comfortable with through the years have been modeless. Last year, though, Vim actually took for me, and I think there were three reasons:
(1) Buying the book Practical Vim from the Pragmatic Programmers, which is aimed at people who kinda-sorta know Vim but don't know much of Vim. I still haven't truly internalized a lot of what I've read, but just understanding the magic of ":find", "." and a slightly greater number of the Ten Thousand Ways to Select has been amazing.
(2) Trying to do as much as possible with "native" commands rather than plugins, then adding a smaller number of considered plugins back in.
(3) Having a real project -- of sorts -- to work on and sticking with Vim for that project. In this case, the project was going through the entire Pragmatic Studio course on Rails 6. (It's good.)
I'm pretty sure these same three steps would work for learning Emacs, too. (Obviously with a good book on Emacs in step 1, not Vim, yes, yes.) But I'm actually pretty happy with Vim.
Also, the proper way to quit MacVim is clearly to select "Force Quit" from the Apple menu.
I finally started using Vim sort of by force, and am already becoming proficient with it after a few hours (and liking it). The reason was that my ISP sent me a cheap Chromebook for free, and I've started using it for coding during my commute (and relegating my old laptop to my music studio). A few days ago there was a ChromeOS update that seems to have killed the ability to connect to code-server (a VS Code server) from the browser, no matter what I tried, and then I tried my old trusty Emacs and I can't get MELPA to detect go-mode at all.
Infuriated by all of the above I found a nice tutorial on how to set up Vim for Go development, used vimtutor, and now I've been able to do non-trivial amount of work while on the train. I actually rather enjoy vim now.
I very much enjoyed the first level. Already quite proficient in vim, I balked at the cost of the full game - but it might well be worth it in your situation.
I'm not sure if I should mention it here, but in case some people are not familiar -- these lines make using vim a very easy experience for those used to CUA editing interfaces:
set nocompatible
source $VIMRUNTIME/mswin.vim
behave mswin
It doesn't really change the command mode if you're used to traditional vim, but you can use shift-arrow keys to select text in VISUAL mode, use CUA commands like C-c, C-x and C-v, etc. Keys like Home, End, C-insert, and S-delete also work.
One day several years ago I found a ~15 year old laptop on the side of the road and wondered what I'd do with it. 300MHz processor, "what's Ethernet?", and I didn't have the little pile of flaky USB Wi-Fi dongles I have now.
And it was only through attempting to actually install from the Slackware CDs I'd burnt several years earlier that I discovered the scratches on them were unfortunately not just decorative scars.
So: gcc, corrupt. g++, corrupt. Python, corrupt. Perl, corrupt. sed, ...not corrupt. grep, also not corrupt.
I love working on little projects. At one point I noticed that installing specific packages quickly and easily wasn't straightforward because I couldn't see what was already installed.
dialog was among the uncorrupted, and I wondered if I might use this to show installed and uninstalled packages side by side.
That was when I discovered the info pages were also intact, and that sed and grep both had excellent info documentation.
Unfortunately I deliberately gave up working on the project after a few days, as I developed headaches from staring at multiple ~5-6 line (ie, ~480 char) monster regexes over the course of a week or so. (Imagine multiple blocks of modem line noise each 2-4 times longer than http://bash.org/?464385 and you're in the ballpark.)
I do plan to finish that script at some point though (when I regain access to that laptop's HDD). It was only 5 sed commands and 4 grep commands...
The accepted answer here [1] is what got me to see the light. Once I realized how composable the main commands are, vi became kind of fun.
I still prefer Emacs because of macros and org-mode, but I no longer fear vi when I'm doing a quick edit, editing a huge file, or on a emacsless new machine.
You could send a PR with an “Acceptance way”.
Also there’s “Radical acceptance way”: kill every other process, although I’m from mobile and too lazy to work out an exact shell command for that
Fun read! My next bash exercise will be to try and understand some of these commands, quite a feat! greping the ps output would work with any program, right ? That was pretty cool. Killing it from emacs was def a good laugh !
They should add the script kiddie way: `sudo rm -rf /` ^^
In fact "pkill init" or "kill 0" (each with sudo/root privileges executed) will most likely kill all processes and is some kind of process equivalent to delete all files ;-)
Next you'll be telling people to use SIGHUP instead of SIGKILL. Or to use the PID. Or to get VIM to substitute its own PID into the ex command using getpid().
408 comments
[ 3.5 ms ] story [ 418 ms ] threador the French way - ZZ
Why the French way? I don't get it and I am very curious :-)
[0] https://unix.stackexchange.com/questions/93144/exit-vim-more...
Only if you're American. Otherwise: "zed-zed". :)
HOW DID I NOT KNOW THIS
took me a while to get it
(since then I implemented the preemptive way: never ever try to open it again)
Me, It's usually :wq, or sometimes :q! or more than likely ZZ - which can be done with shift zz or if you truly want to do it with just one finger, capslock then zz.
But stressing how people exit vi is like stressing about people's fashion, just not worth it. If anything, have a private laugh at them to yourself and use that to remove other stress as more than enough stress in life, more so IT without seeking it out.
I recently did an interview where I had to implement something to flatten a deeply nested structure into a map of path -> value.
The interviewee's had me use VIM. That was my first real dive into it. Solved the problem, already forget how to use VIM. :)
(That and the Rogue navigation keys.)
https://stackoverflow.com/a/29243081/1891877
Seriously, when CES is currently showing hundreds of new tech products and services, including a Hyundai electric helicopter - Vim is what we still talk about?
And Vim is? When there are editors like VS Code?
It's not like VS Code has much in the way of functionality that's not available to Vim/Nvim users via VSCode's extensions or LSP servers.
You don't have to say anything because the HN jury has already found you guilty on multiple accounts of high treason with a thought-crime and the maximum penalty is a lifetime ban.
:x
which effectively does an :wq if there have been changes but is one character less.
$ while true; do curl http://vi-host:8888/kill-vi-$RANDOM; done vi will eventually exit"
Bold claim, and how would you know? What if there is a network partition preventing you from getting the message that exiting vi failed and Chuck Norris?
Almost as important a problem in Computer Science as P!=:WQ.
The test driven development way
:echom test_null_list()
And it works. Just checked.
Many years ago I knew a university professor and students said about him he might leave uni occasionally but he sure never leaves Emacs. Some live in Emacs, some live in Vim.
Honestly, I tried several times over the decades and walked away with my head buzzing.
PS: I don't live in emacs either!
What I do love in both camps is how the explanations begin... "All you have to do is...[insert irrational (to non-vim/emacs users) command]" which makes me laugh every time.
Love the article, which ironically proves my stance of me keeping well clear.
And of course I'd have to dive deep into the ecosystem in order to get the same benefits that my main editor provides out of the box, like idk, cmd+click to go to definition, or error reporting like squiggly red lines.
To me, vim shines as a modal editor, not an IDE. I use it for two purpose:
1. quick editing configuration files, or single file scripts 2. an editing mode in an IDE (mostly VSCode)
The main benefit of vim is to save you from using the mouse or the touch pad. I touch type, my indexes rest on F and J, and I can do pretty much anything without leaving the keyboard, without using the arrow keys, and keeping my eyes on the screen. It's not something I'd know how to do without Vim. If I'm using the arrow keys, I need extra-time to relocate the "J" key, which breaks the typing flow.
Started learning Rails, drank the Kool-Aid, switched to VIM. I don't use VIM for development at my day-job, mostly just key-bindings in Intellij/VS Code, however, the amount of time saved has been worth the effort, and no RSI (also thankfully am able to use the fantastic track-pad on mac and a trackball for anything else).
Lately I've been feeling the pull to learn Emacs after learning about ORG-Mode and the extensibility of the software... unfortunately, the time investment here is likely to have no real benefit in my (current) work as a Java dev. Sigh, time to browse the who's hiring thread.
But Vim (and emacs) solves the repetitive motion problem by providing several means of readily repeating commands.
Most people seem to both type and use their mouse much more slowly than I do. And they also don't often have to (or want to), e.g. cleanup thousands of rows in an Excel worksheet, or have to repeat some kind of action in an app or web app dozens of times.
But I hate using my mouse generally. There are very few times where I want to use a mouse and having to use one, instead of being able to use the keyboard, is endlessly frustrating.
Thankfully, there are several great 'vi-style' browser extensions and there's even [Vimac](https://vimacapp.com/) for MacOS, tho I haven't tried the latter yet.
1: https://vimhelp.org/pattern.txt.html#gd
2: https://vimhelp.org/pattern.txt.html#gD
3: https://github.com/dense-analysis/ale
Maybe I'm not thinking straight because of the sickness, but I think `ddp` from the line above does the same thing with one fewer keystroke.
(Works if register contents after the operation do not matter to you; I don’t think the OP knows or cares what registers are)
> My husband uses vim. It’s why I married him. But I just found out his email client is emacs. I don’t know how I feel about this.
https://github.com/hakluke/how-to-exit-vim/blob/master/READM...
As to why shutdown: cultural thing in the end. I was raised with the idea that wasting is bad (and objectively speaking it's very hard to argue with that) so if I don't need the machine running after I'm done with it, I just can't stand the idea of the thing using energy literally for nothing.
(As I finished writing this, and was about to type ^[fG to submit this reply, I couldn't help but smile a bit)
Also my preferred method from the list is the timeout, it would be nice to have counter in a corner of the vim window to know how much time is left though.
Or, you could have just used Rust and SIMD.
My first attempts ended up with my bot buying stock in a clorox brand before posting questionably racist comments to my twitter, but these are minor concerns on the journey.
I'm streaming the process on twitch but please note that donations won't be considered as seed capital for stock assignment
- I just open it, but I couldn't figure out how to quit. Then I have been using it for three years already.
(Same applies to Emacs.)
You can go through the interactive vimtutor.
Type :help tutor
Or you can just type :help and find the link to the vimtutor. If you are using gVim, then it should be one of the menu items ( maybe under help? ).
My suggestion is to just search for basic vim cheat sheet if you are getting started. There are also youtube tutorials online. Sometimes watching someone work with vim can help you get over the hump.
> - I just open it, but I couldn't figure out how to quit.
:q to quit.
:q! to quit without saving.
Remember to hit ESC to get back to the normal mode first if you are in other modes.
When you are comfortable with Vim then you can go on to some of the advanced vim topics. Also, in the beginning you might have to ddg/google/etc a bit. Good luck.
After learning these first simple commands, it was enough to get me to open Vim at least a few times a day, which then motivated me to start learning more of the commands and it just snowballed along. I still only know probably 25% of Vim, but I feel incredibly comfortable in it now and rarely run into trouble when doing beginner to intermediate editing tasks.
I don't touch type, so hjkl, even though I understand the benefits, has never been my preference. Perhaps it's the gamer in me, I've never had trouble using the arrow keys :)
Feel free to correct me If I'm wrong.
For example, Now I know if I need to go to the next instance of the word under the cursror. There's a command for it.
(1) Buying the book Practical Vim from the Pragmatic Programmers, which is aimed at people who kinda-sorta know Vim but don't know much of Vim. I still haven't truly internalized a lot of what I've read, but just understanding the magic of ":find", "." and a slightly greater number of the Ten Thousand Ways to Select has been amazing.
(2) Trying to do as much as possible with "native" commands rather than plugins, then adding a smaller number of considered plugins back in.
(3) Having a real project -- of sorts -- to work on and sticking with Vim for that project. In this case, the project was going through the entire Pragmatic Studio course on Rails 6. (It's good.)
I'm pretty sure these same three steps would work for learning Emacs, too. (Obviously with a good book on Emacs in step 1, not Vim, yes, yes.) But I'm actually pretty happy with Vim.
Also, the proper way to quit MacVim is clearly to select "Force Quit" from the Apple menu.
I learned the 2nd point the hard. The first time I tried vim, I added as much plugin as I can end. In the end, it was a giant mess.
Infuriated by all of the above I found a nice tutorial on how to set up Vim for Go development, used vimtutor, and now I've been able to do non-trivial amount of work while on the train. I actually rather enjoy vim now.
I very much enjoyed the first level. Already quite proficient in vim, I balked at the cost of the full game - but it might well be worth it in your situation.
And it was only through attempting to actually install from the Slackware CDs I'd burnt several years earlier that I discovered the scratches on them were unfortunately not just decorative scars.
So: gcc, corrupt. g++, corrupt. Python, corrupt. Perl, corrupt. sed, ...not corrupt. grep, also not corrupt.
I love working on little projects. At one point I noticed that installing specific packages quickly and easily wasn't straightforward because I couldn't see what was already installed.
dialog was among the uncorrupted, and I wondered if I might use this to show installed and uninstalled packages side by side.
That was when I discovered the info pages were also intact, and that sed and grep both had excellent info documentation.
Unfortunately I deliberately gave up working on the project after a few days, as I developed headaches from staring at multiple ~5-6 line (ie, ~480 char) monster regexes over the course of a week or so. (Imagine multiple blocks of modem line noise each 2-4 times longer than http://bash.org/?464385 and you're in the ballpark.)
I do plan to finish that script at some point though (when I regain access to that laptop's HDD). It was only 5 sed commands and 4 grep commands...
I still prefer Emacs because of macros and org-mode, but I no longer fear vi when I'm doing a quick edit, editing a huge file, or on a emacsless new machine.
[1] https://stackoverflow.com/questions/1218390/what-is-your-mos...
They should add the script kiddie way: `sudo rm -rf /` ^^
Yep, `ps | grep` is a common and useful idiom!
Most other constructions can backfire in some unexpected way.
* https://mywiki.wooledge.org/ProcessManagement#The_risk_of_pa...
What a day!
I have been amazed by linux since my teenager years and it still has so much more to offer.
May we be blessed to be amazed for the eternities of our mortal lives.
Also, your reply is the kindest comment I've ever seen on HN.
;-)