21 ms·
Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
`:x` leaves the modification time of files untouched if nothing was changed.
:help :x
Like ":wq", but write only when changes have been made.
- hdjjhhvvhga 4y agoCumulatively, you've just saved quite a lot of my time - thanks!
- tomcam 4y agoWHAT My life just began again. Thank you
- warrenm 4y agoI had a CS prof years ago tell us all the only thing we needed to know about vi(m) was the dammit key As in "escape-q-dammit"
- manaskarekar 4y agoJust throwing another one out there: `Ctrl + [` instead of `Esc` to save some finger travel.
- cassepipe 4y agoToo fundamental of a key to even be a combination IMHO. I terminate each edit operation by it, like a dot at the end of a sentence, it needs to be a half a second operation so I can spend most of my time in normal mode. I just remap Caps Lock to Esc system wise (a setting in both Linuxes and MacOs) and use both shift for Caps Lock (setting on Linux, Idk about MacOS) I have always found the "jk" solution quite elegant although I don't use it The benefit of using it system wise is that it then works with all programs that have a vi mode (zsh, gdbtui, etc.)
- RMPR 4y agoYou can escape with alt too https://news.ycombinator.com/item?id=34168031 https://news.ycombinator.com/item?id=34168031
- jeffbee 4y agoctrl+c is the same and even easier to type. I never use escape.
- avgcorrection 4y agoThat’s not the exact same as Escape.
- jeffbee 4y agoOK but as I personally see no need for escape in my use of vim, I judge it to be equivalent for my purpose (returning to normal mode).
- lucb1e 4y agoSo how is it different?
- shiomiru 4y ago^C interrupts the current operation, while ^[ actually finishes the input sequence. The only practical difference I can think of is that when you entered input mode with a prefixed number, ^C ignores it. So 2iabc^C only writes `abc', but 2iabc^[ writes `abcabc'. Edit: apparently ^C also ignores abbreviations. :ab lhs rhs, then ilhs^[ writes rhs, but ilhs^C writes lhs.
- xigoi 4y agoAlso, ^C doesn't trigger InsertLeave autocommands.
- cmeacham98 4y agoKeybinds (in normal mode): Shift + ZZ -> :x (save only if needed and quit) Shift + ZQ -> :q! (quit without saving)
- codesnik 4y agohuh. I'm using ZZ all the time, but I thought it is :wq
- cmeacham98 4y agoIt's possible it was at some point, but my local copy of vim tells me it is 'same as ":x"' in `:help ZZ`
- sodapopcan 4y agoYou never accidentally used it on an unnamed buffer?
- codesnik 4y agounnamed as [No Name]? both :wq and ZZ (:x) do the same: "E32: No file name"
- sodapopcan 4y agoSorry, unnamed AND unmodified. My bad. And actual advantage here is that `ZZ` can be your "quietly quit anything" key. It'll close quickfix, locationlist, previewwindow, etc without complaining.
- hitpointdrew 4y agoI always preferred these over the :wq! And :q!, but for some reason seem way less popular. Most tutorials don’t even mention ZZ and ZQ.
- KMnO4 4y agoIf you’re learning Vim, command mode instructions are a LOT better because they actually show up on the screen.
- secondcoming 4y agoWhy would it write if no changes have been made?
- wruza 4y agoBecause it commands to “write”. Also related to 'autoread'.
- aendruk 4y agoBecause you told it to write.
- Sakos 4y agoI can imagine any number of situations where it might be wanted. Keep the file open in vim, changes are made from somewhere else, but you'd like to keep the original version, so you :w. It makes sense to me the :write actually writes regardless of context (assuming sufficient permissions) and with no hidden conditions like "something must have changed". That kind of thing leads to weird user behavior like editing whitespace just to be able to re-save a file.
- ergonaught 4y agoIf you tell it to write, and it doesn't write, then it is no longer your tool, but rather someone else's tool that you happen to be using.
- Eleison23 4y agoThere are strange cases which may make this a logical choice. Since vi doesn't traditionally lock the file it's editing, another process could change the file on-disk while you have it in the editing buffer. I think you'll get a message in these situations, because it's usually not what you want. Then you'd have the choice of writing out the buffer, whether it's changed or not, to restore the contents of the file from when you began your vi session.
- dwater 4y agoVim is from an era when software was written to do exactly what you commanded it, not what you intended. It was your responsibility as a user to learn how to turn your intentions into commands.
- messe 4y agoYou can also type ZZ (no colon) while in normal mode to exit and save. This also appears to only write when changes have been made (according to some testing in neovim on my local machine).
- Maursault 4y ago> You can also type ZZ (no colon) while in normal mode to exit and save. That's insane. What if you need to type the following words in all caps? DRIZZLE GRIZZLY BUZZARD PIZZAZZ The last would make that command from normal mode particularly annoying. Unless you meant when not in input mode... duh.
- acupofnope 4y agoHe did say in "Normal Mode"
- messe 4y ago"Normal mode" ≠ "Insert mode"
- anthomtb 4y agoNormal mode in vim does not have the meaning normal people associate with a normal text editor.
- shiomiru 4y agoTo be fair, `normal mode' may be a vimism. Both traditional vi's and nvi's man pages refer to the vim `normal mode' as `command mode', and `insert mode' (mostly) as `input mode'. (Though :set showmode still says Insert, and `insert mode' is occasionally used on the man pages too.)
- layer8 4y agoNo need to test, it's documented: https://neovim.io/doc/user/editing.html#ZZ https://neovim.io/doc/user/editing.html#ZZ
- wruza 4y agoSee also ZZ :silent! wa
- chrismorgan 4y agoThe really fun part: > This command is not supported in Vim9 script, because it is too easily confused with a variable name. So you can’t just write “x”, but must instead go for something bland like “exit”, or something exciting like “exe'x'”. (I’m presuming “execute 'x'” will work, but my mental model of how you’d unsupport the command in Vim9 script could be wrong.)
- jrochkind1 4y agoI barely ever use vi(m), but occasionally use it when I have to or it's convenient for me to edit something at a CLI only, which in my work practice is only an occasional brief thing. `:x` is one of only like 8 commands I know! I'm surprised that it's apparently not one of the basic commands everyone knows?
- MayeulC 4y agoIt's pretty well-known (a bit less than :wq though). What most didn't know (myself included) is that the behavior is slightly different from wq.
- joeatwork 4y agoThis is the first time my life has changed from just reading a Hacker News headline.
- jjallen 4y agoMake sure to see this comment about :X encrypting your file instead of exiting https://news.ycombinator.com/item?id=34288446 https://news.ycombinator.com/item?id=34288446
- cassepipe 4y agoI can't help but see that argument as post rationalization from people who have bee using :wq their whole life \s Been using :x from the start about 4 years ago and I never accidentally encrypted a file.
- dgabriel 4y agoSame (but for a longer period of time). I'm kind of surprised people don't know this.
- deleted 4y ago[deleted]
- pkulak 4y agoSame. Been using :x for about 20 years. Had no idea there was some similar encryption nonsense.
- maxbond 4y agoI've been using `rm` and `rm -rf` for as long without losing data, but I understand why some people like having a trash can. Different workflows are susceptible to different hazards.
- cassepipe 4y agoIf you're not parent, you will definitely be interested in : https://github.com/rushsteve1/trash-d https://github.com/rushsteve1/trash-d
- cyberge99 4y agoShift Z Z will instantly save and exit, same as wq!
- Tepix 4y agoIsn't it like ":x"?
- ergonaught 4y agoI just tried this and I think that in 40ish years of typing on computer keyboards, this is the most difficult thing I've ever typed. And I use emacs.
- amalgamated_inc 4y agoWhat do you mean? Super easy and fluid, I've been doing it for about a decade. Left pinky on left shift, left middle finger (you could try ring I suppose) on zz, tap twice.
- ergonaught 4y agoI mean pretty much what I wrote. It's literally the most difficult thing I've ever typed on a keyboard. Blame my hand geometry or the keyboard or muscle memory or 10,000 other things, I just noted it was super hard and unnatural for me to type that. (The downvoting on that is pretty epic, though.)
- amalgamated_inc 4y agoSo weird, I literally never, ever typed :wq ever again after the first time I experienced the smooth bliss of ZZ. Maybe you're right about hand geometry and it's just for me. It's satisfying in the way that whacking ESC is, but smoother and gentler.
- favadi 4y agoI don't think C-x C-s + C-x C-q is any easier.
- deleted 4y ago[deleted]
- tempodox 4y ago... and you can append `a` (`:xa`) to write out all modified buffers and quit.
- shiomiru 4y agoMaybe it's just me, but I find :wq a lot easier to type... For :x (or worse, ZZ), I either have to move my hand or bend my ring finger/pinky to reach the keys. On the other hand, my fingers reach both w and q at the same time with very little effort.
- lionkor 4y agoWith a German keyboard, which I use, Z and Y are swapped - so even more reason to use :wq
- avgcorrection 4y agoI just use it because it’s shorter.
- mzzter 4y agoTIL that :wq is like :x I only knew about :x. So thus far I’ve only edited with :x, and then used :q! to quit without writing the changes.
- waisbrot 4y agoI learned to do `:wq` after I learned that `:X` encrypts your file. When typing without really paying attention to the screen, I've twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system. After that, I switched to `:wq` (and sometimes `:w` `:q`) which is much safer against over-typing.
- tomxor 4y agoThanks for this warning. Even worse for me, because my laptop keyboard has some kind of horrible encoding causing latency on the shift key, so I'm constantly doing :Wq when I type fast enough... Yeah I had the suspicion it was human error - but I've tested using a single finger for shift and w, so it's definitely the keyboard. [edit] Looks like that feature is not necessarily built in by default though.
- DwnVoteHoneyPot 4y agoi did an alias mapping :Wq to :wq
- dunham 4y agoYeah I do that a lot. And on macos, vi decides that :Wq is an error and returns a non-zero status code on my subsequent :wq, cancelling my git commit. So I get to type the commit message again.
- jjallen 4y agoYeah, thanks for this. `:wq` is pretty fast to write. I think I will stick to it.
- sodapopcan 4y agoOr, as other have pointed out, just use `ZZ` which is even easier and equivilant to `:x`.
- sshine 4y ago
- bitwize 4y agoI've been using ZZ all these years
- SecurityMinded 4y agoNever liked ":wq" construct since I started to use vi, almost three decades ago. Always used ":x". Now realizing, it had a hidden benefit. Good for me. <pats himself on the back>
- andrewshadura 4y agoNever liked ":x" construct since I started to use vi. Always used ":wq". Now realising, it had a hidden benefit. Good for me. <pats himself on the back>
- lucb1e 4y agoSo what's your hidden benefit
- bluecalm 4y agoI know maybe 4 Vim commands I use to write git commit messages as I was too lazy to change the default editor. :x is one of them. It's funny how different people learn tools differently. I've learnt by googling "Vim basic commands for git commit messages" and never spent any more time on it but apparently this is a revelation for many long time Vim users here.
- mmastrac 4y agoI learned early on that the easiest way to quit Vim without saving was ctrl-Z and then kill -9 %1
- j1elo 4y agoSee, that's why even though I'm a terminal user first and foremost, I really like the discoverability of GUIs, and that's where a good GUI is unbeatable by CLI. This would have just been an entry "Save if needed" in the File menu, right below "Save", and users would probably find it by accident while looking at the menu, even while not actively looking for new ways to save a file. (Not getting into the fact that a well programmed Save function would, IMO, not do anything if there are no changes, i.e. if I was the one writing the code, the Save button would be greyed out, or in the case of vim, :wq would not write anything if no changes had been made... but that's a different discussion)
- Am4TIfIsER0ppos 4y agoA menu? WTF is that? Some sort of out-dated ui element no doubt.
- photonbeam 4y agoIt should be some phrase you tell a smart speaker, or perhaps a chatbot
- armchairhacker 4y agoprograms like vim and tmux desperately need a menu which just shows all available commands (including plugins), even if it’s opt-in. AFAIK no such menu actually exists in vim or neovim because of the way some of the commands are hard-coded
- Tmpod 4y agoTelescope[1] on NeoVim can provide such interface. It is not standard, but telescope is becoming really widespread. [1]: https://github.com/nvim-telescope/telescope.nvim https://github.com/nvim-telescope/telescope.nvim
- earthling8118 4y agoCheck out zellij in place of tmux https://github.com/zellij-org/zellij https://github.com/zellij-org/zellij
- tipsytoad 4y ago:update is like :w but only writes when changes are made. While we're at it :earlier and :later are undo/redo but instead of using an undo stack they use change points in time, so your undo history is never overwritten :)
- lucb1e 4y ago:earlier 30s is such a life saver when you've messed up the standard undo/redo order (u and ctrl+r). I need it so rarely that I have a hard time remembering what the command was again whenever I need it. Needed it a few weeks ago, so now it's at the front of my mind again :D
- nicolaslem 4y agoI am surprised it is not already mentioned in the comments, but I personally cannot use an editor that doesn't automatically write changes when I am done typing. I just forget to save and wonder why the app I am working on did not change. So my (neo)vim setup uses a plugin like `Pocco81/auto-save.nvim`. This solves the problem mentioned by OP because I can just `:q` anytime.
- DwnVoteHoneyPot 4y agoI really hate autosave. I like using saving like a checkpoint where i have the ultimate undo button by ditching the unsaved changes. Second, in a large Excel file, the auto save is constantly slowing me down because there’s a slight hang after every cell change.
- RMPR 4y ago> I really hate autosave. I like using saving like a checkpoint where i have the ultimate undo button by ditching the unsaved changes. Although I don't use autosave, I don't think it matters that much with vim because you can always use undotree[0] 0: https://github.com/mbbill/undotree https://github.com/mbbill/undotree
- villgax 4y agoA lot of the pain could've been avoided if they just wrote somewhere that you need to type ':' or something else to access help/commands when inside of vi/vim
- lucb1e 4y agoI wonder where the first place is for people to look when needing help with random commands. man vim The :help command is mentioned in the second paragraph. And repeated the third. Though most people probably just use web searches anyway nowadays.
- omar_alt 4y agoZZ for me as well and I mapped :WQ to :w !sudo tee % >/dev/null
- sshine 4y agoI always :q when I didn’t change anything. If I changed something intentionally, :wq and :x are equivalent. If I changed something accidentally, :x won’t catch that, and :q complaining will require me to decide if :q! or :wq is correct. So :x does not fit my workflow of avoiding accidental writes. Just like ZZ does not.
- hhjj 4y agoCan't you use :q and then :x instead of :q then :wq ?
- sshine 4y agoYes, but if I :q and it complains that the file was modified, and I decide that the change is worthwhile, :wq and :x are equivalent, since :x is only different when the file isn’t modified. You may argue that :x is shorter, but one thing is character count and another is muscle memory distance because of mnemonic similarity between :q and :wq.
- caust1c 4y agoCould alias x to wq? :-) That's what I'm doing after discovering this!
- moloch-hai 4y agoAlias x to q, I think you mean?
- pkulak 4y agoI use :x cus it's one less keystroke. And yes, I still use :q to make sure I don't save in case I changed something by mistake.
- JelteF 4y agoZZ is only 3 keystrokes as opposed to 4 for :x (shift + z + z = 3 and shift + ; + x + enter = 4). It also doesn't require timing the release of shift before the press of x.
- GTP 4y agoTIL that VIM has built-in encryption.
- simonebrunozzi 4y agoI became quite an advanced vim user in 1999, during my military service in Italy (I was stationed at the Ministry of Aerial Defense, and working on IT stuff). It's quite incredible and a bit weird that today, in 2023, I can say "Yes, I knew this", despite non having used vim much since ~2012. I would have never guessed I'd be able to recall things like this.
- RMPR 4y agoI don't know Vim, my fingers do. More seriously sometimes I'll get a question about how I did/do something, and have to sit at the keyboard and actually perform the action to be able to provide the answer.
- Cardinal7167 4y agoA sure sign of a well designed tool imo
- RheingoldRiver 4y agoReally? IMO that's the sign of an extremely poorly designed tool that a lot of users have learned to use very well despite how poorly it's designed. A tool that's designed well should have its actions all extremely intuitive, in which case one would not forget things in this manner because all of the actions would be derivable from their justifications. For example: ctrl+C is copy, and ctrl+V is the key right next to it for paste, making that not just muscle memory but also extremely easy to remember and even easier to explain: "press the the key to the right of C for paste".
- MayeulC 4y agoWhile I agree this is the ideal, it's often hard to be newcomer-friendly while keeping a stable interface (absolutely needed to build a muscle memory). You can reduce the feature set, but then it doesn't work for power users. An example of this is that new users often expect conventions they're used to; and both vim and emacs predate a lot of these, like Ctrl-S for saving. Muscle memory can also be a sign for poorly designed software, where simple actions require a lot of repetitive steps. At least, it's easy to go fast with a keyboard. As an example, I learned by heart some sub-sub-menu items in Cadence, accessed by Alt+x,y,z (I'm thankful for these underlined letters in toolbars).
- tasuki 4y agoI'm rarely in a situation where I'd want to quit vim. One off config files on a remote machine perhaps?
- anthomtb 4y agoConfig files on an embedded device got me into using vim 10+ years ago. This seems to be a common use case. Eg, “I use vim for short term editing on remote machines but VS Code for any serious editing.” This is not me though. I love me a plug-in heavy vim for coding sessions. Maybe one of these days I’ll be stuck working with some ECMA-based language and will finally start using VS Code.
- thayne 4y agoYou can also use ZZ. It is equivalent to :x
- hosteur 4y agoYou can also just press ZZ in normal mode.
- bxparks 4y agoI map 'S' to this in my .vimrc: nmap S :wall<cr> which saves all changed buffers into their respective files. It is probably the single most productive customization in my .vimrc file. I save my files very often, and I usually have multiple files and buffers open. 'cc' is an alias for the old 'S', so I don't lose much.
- Invictus0 4y agoYou could also just use a modern text editor with autosave
- RMPR 4y agoAnother pro tip. You can escape insert mode with alt https://news.ycombinator.com/item?id=34168031 https://news.ycombinator.com/item?id=34168031
- snapplebobapple 4y agofor me, I don't want it to write only when there are changes. I want it to error out if I try to quit without saving changes so I go and figure out if I changed something by accident before I save it and I want it to write specifically when I tell it to write. This cuts down on so many problems, at least in my use cases.
- amelius 4y agoBy the way, why does visudo sometimes give me another editor (like nano) on a new system. Isn't "vi" supposed to mean "vi"?
- tingletech 4y agoI think it uses whatever EDITOR is set to. EDITOR=vi visudo should let you override it
- layer8 4y agoYou're showing that you didn't read the second paragraph of the visudo man page yet.
- lucb1e 4y agoThis is why I always 'sudo vim /etc/sudoers'. I don't want to have to deal with using and exiting nano somehow (that I need to edit sudoers means that the system isn't properly set up, so odds are that there won't be vim configured as default editor yet either). Of course, one should make one's own risk assessment here. It's not as though visudo can read your mind and prevent you from locking yourself out or something, so if you are on a system where you can't fall back to modifying the file on the (virtual) disk directly, you might want to first open a second shell and test your changes after saving and before quitting either vim or visudo.
- deleted 4y ago[deleted]
- amelius 4y agoI have a question about this. If I type ":w" and then immediately do Ctrl+Z to suspend the session, it seems that Vim is always able to save the file before the editor suspends. Is this by design? Or was I just lucky so far? Anyway, it would be great to have a default shortcut for this combination of keys too.
- jeffbee 4y agoCtrl+Z sends a signal to the process which is purely advisory. The process can do anything or nothing. Vim's extensive and unreadable signal handling logic can be gazed upon at: https://github.com/vim/vim/blob/master/src/os_unix.c https://github.com/vim/vim/blob/master/src/os_unix.c
- Existenceblinks 4y agoI also have a funny related thing to Tell HN: `git --amend` -> `:wq` is shorter and faster to type than `git --amend --no-edit`
- freeCandy 4y ago`ce` if you have fugitive
- Existenceblinks 4y agoNot going to beat `wq` on keyboard position without yet another thing (alias) in existence to maintain.
- a3w 4y agoI often have the variant with --amend --no-edit in my bash history, so that I press up about two or three times instead of writing anyting at all.
- Existenceblinks 4y agoI'm thinking if you are joking or not! You press arrow 3 times + hope it hits whereas `:wq` 3 chars with 100% certainty.
- kens 4y agoIs there a good way to manage saved-but-not-exited vim windows so I don't open the same file twice? I keep running into a problem where I'm editing a dozen files, and then I try to re-open a file I already have opened. Vim gives me a warning about this but my choices are a) tab through all my open windows until I find the right one, or b) open a new editing window and hope that I didn't have unsaved changes in the first one. Is there a way to have vim just go to the open window? Or is there a better way to manage my windows? (I'm using MacVim if it makes a difference.)
- aidenn0 4y agosetting "nohid" will cause vim to close non-active buffers, so at least then you only need to tab through active buffers. If I run into this situation, I just close all of my open vim windows, saving as needed, but you might have a good use case for many open vim windows.
- kens 4y agoThanks for the suggestion! I also found that MacVim has tabs, which may be better than having a bunch of open windows.
- JelteF 4y agoHold shift and press Z twice will also close and save. It's only three key presses instead of 4 for :x (shift + ; + x + enter)
- deleted 4y ago[deleted]
- alexiaa 4y agoI knew about `:x`, but I had no idea there was an actual distinction beyond just being a shortcut for `:wq`.
- blitz_skull 4y agoWhich is the same as ZZ in normal mode. I don’t think I’ve hit “:wq” in years.
- waych 4y agoI almost exclusively exit vi using CTRL_W-CTRL-Q. It's a 3 finger chord that I use all the time to close vi windows. Makes sense that I'd use it to close the last one too.
- vostok 4y agoYou might as well use emacs at that point.
- waych 4y agoBeen using vi for just over 25 years now. The only thing I know how to do in emacs is exit :D vi uses the ctrl key a ton if you know what you are doing.
- manaskarekar 4y agoCtrl-W based shortcuts are especially very useful.
- hk1337 4y ago:x gang checking in
- johncoltrane 4y agoFront page and more than a hundred comments for a basic Vim command. Reddit is leaking.
- pungentcomment 4y agoYou get that kind of response anytime the subject matter is vi or vim. Still more if it mentions nvim, nano or, god forbid, emacs(!)
- NegativeLatency 4y agoI may not be an uber geek but I’ve been using vim for 10 years, even written a plug-in and I didn’t know this.
- badrequest 4y agoSorry we're not all living up to your expectations.
- Arisaka1 4y agoWhat do you mean by "Reddit is leaking"? Do we hold ourselves to a higher standards out of merit of posting here? Is there some sort of tribalistic exclusivity that was broken? Was there perhaps a manual of commands a Vim user who posts here must know before creating an account?
- _blz2 4y agoThe chances of the crowd here using emacs or vim are very high. Yes that makes it an 'elite board' if you consider basic editor commands as the standard.
- flippinburgers 4y agoHasn't it been obvious for years now that the demographic on HN has shifted?
- chewz 4y ago" https://stackoverflow.com/questions/7883803 https://stackoverflow.com/questions/7883803 silent !stty -ixon > /dev/null 2>/dev/null nnoremap <C-q> :x<CR> inoremap <C-q> <ESC>:x<CR>
- yodsanklai 4y agoWhy is it useful? I would do ZZ to quit with saving, or :q! to quit without saving. Incidentally, I find :w to be very inefficient to type (any : command really, but there are not normally the most common operations), for such a common operation. I wonder if people remap it.
- michaelmior 4y agoI use the following in my vimrc so I can just use semicolon instead. nore ; :
- MayeulC 4y agoI like that AZERTY has colon on the lower row :) You can remap your keyboard as well.
- michaelmior 4y agoI've thought about remapping my keyboard before (and I do use caps lock as escape), but any significant changes just mean I'll be totally confused whenever I use a regular QWERTY keyboard.
- yodsanklai 4y agoSounds like a good idea. Any drawback that I don't see? Why not ; in the first place? perhaps to avoid hitting it accidentally.
- michaelmior 4y agoIt does mean you can't use any key bindings in normal mode that use a semicolon. But I don't have any that I use.
- SuperCuber 4y agoI remap `<space>` to save because I like to obsessively spam it after every couple edits. Fun fact, ZQ quits without saving, like :q!
- gpvos 4y agoAlso, `ZZ` is the same as `:x`.
- thefaux 4y agoWait, people exit vim?! ;)
- OlleTO 4y agoMaybe well-known, but: Ctrl-C exits interactive mode and goes back to normal mode. Easier to reach than Esc and I usually find rebinding/aliasing keys to be too much of a hassle
- williamsmj 4y ago`:cq` exits vim with exit code 1. This is useful if you're in vim to write a git commit message and you realize don't actually want to commit. Or you're in vim from `fc` to edit a shell command and you realise you don't actually want to run it.
- turtleyacht 4y agoThank-you. That beats `HdG :wq` to delete everything and abort the commit.
- wruza 4y agoVCSs usually abort a commit if a temporary message file remains unmodified, so :q! is fine too.
- drudru 4y agoAgreed. I use this all the time.
- hwestiii 4y agoHow is it that this is news?
- bradknowles 4y agoTry "ZZ" instead. No ":" required.
- 1-KB-OK 4y agoI've been using `:x` successfully for years after finding it. I had no idea that `:X` actually encrypts the file and can cause havoc lol.
- seanhunter 4y agoSeriously. Just type Shift-double-z in normal mode. No colon, no fuss, no mistakes, no confusion with anything else. No need to remap in case you press shift, because you press shift on purpose. Works everywhere vim is installed, even if your dotfiles aren’t.
- t312227 4y agoi have to admit, i heavily prefer exit & save ZZ exit without save ZQ these are vi(m) commands, the :x & :wq crap is there for ed-compatibility but: whatever floats your boat ;))
- Block77 4y agoZZ gang