408 comments

[ 3.5 ms ] story [ 418 ms ] thread
pssh.. they didn't mention the vimtectualist way - :q!

or the French way - ZZ

the french way :D
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 :-)

[0] https://unix.stackexchange.com/questions/93144/exit-vim-more...

Maybe because of our (I very much include myself) infamous inability to pronounce correctly the sound "th" and making it sound like "z" instead.
Ah yes, zis is it. Fank you.
I'd have thought it's because the French keyboard layout is arranged with the "Z" in place of the "W" on a qwerty layout
(Wild guess) If you pronounce the command aloud - "Zee-zee" - it translates to "Willy" (penis word used by children) in French. Easy mnemonic.
>Zee-zee

Only if you're American. Otherwise: "zed-zed". :)

> or the French way - ZZ

HOW DID I NOT KNOW THIS

People explained that it was [Shift] and [Z], which of course for you would have produced a lowercase 'z'.
I have the feeling something is missing on that list, but I can't put my finger on it ...
I think it's the Hulk way. I seriously considered the Hulk way the first time.

(since then I implemented the preemptive way: never ever try to open it again)

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.

:x
Thank you. I swear every time I see a tutorial where someone is using vim they say to save and close with :wq and it drives me nuts.
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.

I never use :wq because I obsessively save after every thought.
Edit - Related in that I used vim and probably won't again:

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. :)

The only vi command I know is :q!

(That and the Rogue navigation keys.)

Bonus geezer points for calling them Rogue navigation keys instead of NetHack navigation keys.
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?

Be the change you want to see in the world, bruv
it's called hacker news, not electrical engineer news, not startups news
It's on YCombinator, which is a startup accelerator
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.
CES hasn’t been relevant in the past decade. Why would we care?
> CES hasn’t been relevant in the past decade. Why would we care?

And Vim is? When there are editors like VS Code?

who needs vs code when u have nano
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!
I like

:x

which effectively does an :wq if there have been changes but is one character less.

ZZ
But these just close the current window, not the entire program
It also prevents the modification time from being changed after closing the file, if no changes were made.
They forgot the Freshman CS student way: Panic, Lock the computer in the computer room, run.
From the readme: "Remotely:

$ 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?

Ah, the famous CEVP Theorem (Consistently Exiting Vim under Partition).

Almost as important a problem in Computer Science as P!=:WQ.

I just do ZZ, if I want to save the buffer, or ZQ if I was just looking, or I messed up (I'm a vim newbie).
This one is the shortest way in the list :

The test driven development way

:echom test_null_list()

And it works. Just checked.

Doesn't work for me, just gives an error message "E730: Using List as a String" and returns me to command mode.
Use nvim, press Ctrl-C and it will show the corresponding help message
It is not necessary to use nvim to see this help message; it's in vim 8.0 that comes stock with my Mac.
True, I just checked, though the help message is a bit different
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.

(comment deleted)
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.

1: https://vimhelp.org/pattern.txt.html#gd

2: https://vimhelp.org/pattern.txt.html#gD

3: https://github.com/dense-analysis/ale

> `ddkP` is probably the most advanced command I know

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.

`P` pastes to the line above.
That’s why the poster above suggested doing it from the line above. kddp still saves you from the burden of pressing the shift key.

(Works if register contents after the operation do not matter to you; I don’t think the OP knows or cares what registers are)

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).
What is the text object for "current indentation level"? One you created or is it built in?
Nitpick: 'q' is an ed command. ('ed' Being the underlying line-editor upon which the original vi was layered.)
Why make it a nitpick and not a fun fact? :)
If it were a fun fact, it would have to point out that it is an ex command. Nitpicks do not have to be quite so factual. (-:
Meta-nitpick: Vi was built on Ex, not Ed.
You don’t have to use vim command in normal text editing (mostly). Vim (and emacs) draw lies mostly in programmatically writing text.
There was a tweet quite a bit ago:

> 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.

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.

What I do is I set a 25 min timeout, so not only it exits vim it also acts as a Pomodoro timer for me. Two birds, one stone.
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.
I believe the solution to this lies in using Rust and SIMD. It will achieve both performance and safety.
I would prefer a functional approach and formal verification so we can know for sure it will exit.
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.

Or, you could have just used Rust and SIMD.

This hits so close to home.
Let me halt you right there...
Pretty sure there will be a TAS in the sub-second range in the near future!
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

Must be GDQ season again.
There is a much faster way, but first you need to build up speed for 12 hours.
I'm curious if there is any work in fuzzing that could be applied here.
- So, how did you learn Vim? I heard there's quite a learning curve.

- 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.)

> - 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 :)

As far as I know, hjkl was first introduced in games and later used in vim because we don't have to move our hands far away from the keys.

Feel free to correct me If I'm wrong.

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.
The idea behind trying something new every day is just that I know what are the thing that are possible not to learn it by heart.

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.

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.

Thanks for the book suggestion. I will definitely check it out.

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.

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.

You might want to check out https://vim-adventures.com/

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.
Spacevim is very user-friendly. Or at least as close as vim gets.
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...

I'm in the same boat. Somehow, neither vim nor emacs have ever made a compelling case for me to switch from nano which "just works"
Emacs prompts you to use the tutorial on startup if you haven't configured it.
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.

[1] https://stackoverflow.com/questions/1218390/what-is-your-mos...

That was my way into learning Vi(m), too, and I also stayed with Emacs, but using Evil mode. I struggle with vanilla Emacs nowadays, tbh.
What do you do if you need more entropy? Open vim and ask a graphic designer to exit.
Just stay in Vim :)
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
I know this is humor, but I never knew about using Ctrl+R (<C-r>) within insert mode or within an Ex command.
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 /` ^^

That might delete the executable but the process would still be running.

Yep, `ps | grep` is a common and useful idiom!

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 ;-)
I do not like the grep -v grep pattern. I think the regexp trick should be prefered:

    :!ps axuw | grep [v]im | awk '{print $2}' | xargs kill -9
This can also be merged in the awk command:

    :!ps axuw | awk '/[v]im/{print $2}' | xargs kill -9
Ugh, ps|grep is unnecessary. Just use pgrep! Or even better, pkill -9 ;-)
Issue 26 (q.v.) is closed.
I started using Linux in 1997 and just today I've found out about pgrep and, on reddit, sudo !!

What a day!

Wow! Glad to be part of your journey in discovering linux.

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.

The UNIX ecosystem (digisystem?) always has more to find.

Also, your reply is the kindest comment I've ever seen on HN.

(comment deleted)
I got one: stop paying the electric bill.
I just installed a Kasa TP-Link smart plug, now I can kill Vim from an app!
On a saved buffer, I usually use `Ctrl-w q` (Window command, close). I have Ctrl mapped to caps lock, so this is super quick to do with one hand.
Just close the terminal window en delete all files starting with ~ in the directory. Very clean way to stop Vim.