Now Reading
Inform HN: Vim customers, `:x` is like `:wq` however writes solely when modifications are made

Inform HN: Vim customers, `:x` is like `:wq` however writes solely when modifications are made

2023-01-07 06:22:11

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

Thanks great link. tldr:

> vim encryption uses old,
obsolete algorithms that are poorly implemented.
Since insecure cryptography is worse than no
cryptgraphy, the community voted in favor of
removing all crypto.

I’ve been a vim (and :x) user for about a decade, and have never once faced this issue. I don’t think I’m a particularly exceptional person, so I tend to suspect my experience isn’t far from average.

In any case, if you’re using vim or the like to edit files without buffering, source control, or backup, I get that it sucks but that footgun had your name on it from the start.

I’ve been a vim user for 15 years and I still often type `:Q` and `:W`. Everyone types differently and some people make mistakes.

Your blaming the victim instead of the software.

What parent @waisbrot is saying seems uncommon (the source of this whole conversation), but granted, perhaps common enough (or is it instead worrisome enough) that nvim community took it out.

I still type :Q and :W as well, but that is not what is being discussed.

Have you ever irrevocably bricked your system, as @waisbrot mentioned they have twice, from typing :W or :Q? Have you ever bricked your system from typing :X? If so, that isn’t a “use 😡 vs :wq” problem, that’s seems more of a use common sense problem.

OP said exactly “I’ve twice encrypted my file with password like `cd tmp`”

Not sure how you get “irrevocably bricked your system” from “encrypted my file”, but you do you, I guess

You should also let the OP do the OP. They said they made a mistake. Simply, without complaining, and they do something else now. It’s that simple

Parent (not OP) said more exactly

> I’ve twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system.

I get “irrevocably bricked system” from the fact that they “broke their system” and I am inferring it could only be something worth mentioning if it were irreversible.

I originally was trying to point out that parent was off-topic, because 😡 and :X are different. But a fleet of downvotes flooded in, so I defended my viewpoint for the catharsis.

Some people value stability and gvim. I don’t consider nvim an upgrade, it’s just a fork with different priorities which may or may not suit you. I continue to use vim and gvim.

Me either, but that’s because I type `:wq!` every single time instead. I’m not one of those who is afraid of typing more than a single character so I don’t care if it’s actually 3 I’m hitting. I am someone whose entire brain comes to an absolute crash if I type “wq” and it’s asking me if I want to save over a RO file. It’s like having a belt loop or pocket catch on a door handle and I despise it.

So, `:wq!`, or as I call it “write the fucking file and quit, _with feeling_”

I just tried it. :X asks you to enter an encryption key, then asks you to enter it again, and only continues if the keys match. And then you’re still in vim and need to save your file to overwrite anything. Seems hard to do by mistake.

(though I prefer ZZ)

If only!

I was a TA for an introductory CS class that taught C++ and, in passing, vi. A hour before one assignment was due, a student showed up in a panic. “I just had it working but then the computer corrupted my file. Look! Can I have an extension?” The other TA and I smirked: What a lame excuse! We offered some generic advice about starting earlier and visiting office hours. He left in a huff.

A few minutes later, a second student appeared with the same story, and then a third and fourth.

We eventually tracked the problem down to some handwritten notes, where someone had written a largish 😡 for “save and quit.” The students were doing things like spamming :X (since it didn’t seem to respond the first time—-and it was over a sluggish ssh connection) or a reflexive quit-and-compile cycle. I think we eventually recovered one or two assignments by guessing what they might have done.

We obviously apologized profusely and the next class started with a discussion of 😡 versus :X—-and emacs!

What did you apologize for?

In any case, switching an editor because someone misunderstood 😡 vs :X (and didn’t bother to read what the editor was asking next) seems like a bit of an overreaction to me.

He was legitimately confused and panicked and we could have been more understanding (especially since this turned out not to be a one-off thing). It’s good to be kind.

The editor thing wasn’t a big deal: a few minutes of “Beware :X! If you no longer trust vi, feel free to use emacs or nano, which are also installed on our system. They work a bit differently [details, resources]. You can write your code locally too, but if so, make sure it runs on our system with the autograder. Here are a few options for that too.”

I have computer-literate parents and grew up in the PC era, so as a child I typed my elementary school assignments in vi. Accidentally using :X, encrypting one of my school papers, and having to completely rewrite it, was one of the slightly-traumatizing moments in my childhood.

FWIW, I switched to :wq for a while but I’m back to using 😡 instead of :wq. I’m just very careful now. 🙂

I did this same thing on a large programming assignment in college. I’m 46 and can still remember the way the lab smelled and what the people sitting next to me were wearing the moment it happened.

I get annoyed by “:W is not a valid command” errors and aliased it, and that’s not even dangerous to get wrong, just have to retype “:w”. Why be so careful instead of just aliasing it?

vimrc excerpt:

    command Wq wq
    command WQ wq
    command W w
    command Q q
    command Bd bd
    cnoreabbrev q1 q!

I hate having to get the shift key timing correct so much that I also aliased : to ; for commands, but that’s more radical and gets me into trouble on remote systems that are not my own, not sure if I recommend it. I’d recommend vim to change the default for everyone, though (fat chance, I know).

Another annoying thing in vim is whatever the heck Q does. Try to type :q, fail, retry, and now suddenly you have an extra window to close or something. Solution: nnoremap Q <nop>

I used to use the W alias whenever I noticed myself doing it on a new setup, but I haven’t had to do it recently. I suspect my “slow on the shift” issue was due in part to the lousy keyboards I used to use.

Thanks for bringing this up.

I’m toying with either disabling it,

    cmap X <Nop>

or, mapping it down to a lower x.

    cmap X x

1. Does anyone see anything this could interfere with?

2. Does anyone know a better way to turn off the `:X` encryption option?

Sadly, having to remap definitely dulls the shine of `:x`.

Well, in fairness, `:X` brings up a prompt, so an accidental `:X` won’t seamlessly masquerade itself as `:x`.

Otherwise, I feel a remap is just a valid option as any to disable it. I’m not sure there’s a way (a quick skim of the docs made me think `set key=` would do it but that didn’t work for me, or at least I didn’t understand what it does) but either way you’d still have to add config.

But again, as I say to everyone I see using commands to quit and keeps getting brought up here: `ZZ` is the same thing.

Yeah, but it’s possible to quickly type the next command (that you would after exiting vim) as the encryption key.

That said, given that neovim doesn’t have this feature at all makes it less of an issue to me.

On my build, I have to confirm the key — is this not the case with yours?

I suppose one could naively type the same thing twice, but I feel like some caution also goes a long way. Driving without looking at the road is generally dangerous

Any time I accidentally shift-mod my saves, I immediately see the encryption prompt, and back out with SIGINT. I don’t really buy the problem, so to speak

Mapping to ‘x’ is dangerous since on a system where you don’t have your vimrc you’ll get the original behavior of ‘X’. Ideally you’d map ‘X’ to deliver a small electric shock. 😉

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

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

It’s not shorter—there is an implied `<cr>` at the end there and as you have it written it’s the same length. Also, if you did make a change, `:q` will yell at you. If that’s what you want, though, that’s totally cool.

The advantage of `ZZ` is that it can be used as a general “close this window” command. It’ll work on unmodifiable buffers as well without complaining.

How I’ve dodged that in the decades of using vim, I don’t know. Though these days I roll with space for entering command mode, so the danger is nil.

nnoremap <space> :

Has done wonders for my fingers.

That’s a really bad affordance. It makes it possible for the user trying to do something non-destructive (only write if there are changes) to accidentally destroy and replace the file.

Thanks, this is absolutely horrible. Filing this as yet another item under “Why vim is the worst example of 1970s bullshit UX still recommended by cargo cultists everywhere.”

I don’t know, I grew up with IDEs and came into console based editing much later in my programming life. It is so much better when working with multiple systems over ssh, especially if modifying linux at all, writing drivers, etc.

It is a huge learning curve, but the ease of remote editing and the speed increase is really incredible. Being able to rapidly move around a file with just a keyboard is a super power, but it just takes muscle memory which means a lot of practice and time.

It may or may not be worth it, but it definitely is not a cultist offering. There is a large value add.

I always :q when I didn’t change anything.

If I changed something intentionally, :wq and 😡 are equivalent. If I changed something accidentally, 😡 won’t catch that, and :q complaining will require me to decide if :q! or :wq is correct.

So 😡 does not fit my workflow of avoiding accidental writes. Just like ZZ does not.

ZZ is only 3 keystrokes as opposed to 4 for 😡 (shift + z + z = 3 and shift + ; + x + enter = 4). It also doesn’t require timing the release of shift before the press of x.

I use the ‘confirm’ option in my vim config, that way I can always use :q and then get a prompt on what to do if a file’s been changed.

I also map <C-q> to :q to speed things up a bit.

Yes, but if I :q and it complains that the file was modified, and I decide that the change is worthwhile, :wq and 😡 are equivalent, since 😡 is only different when the file isn’t modified.

You may argue that 😡 is shorter, but one thing is character count and another is muscle memory distance because of mnemonic similarity between :q and :wq.

It’s funny but I use q when I don’t intend to change things and wq in whatever state I’m seeing them and x when I’m working on clean git state.

Honestly it sounds complex, but I don’t even think about it and it only struck me reading your comment.

The warning note on q is desirable.

I can’t help but see that argument as post rationalization from people who have
bee using :wq their whole life

s

Been using 😡 from the start about 4 years ago and I never accidentally
encrypted a file.

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

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

See, 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)

> even though I’m a terminal user … I really like the discoverability of GUIs, and that’s where a good GUI is unbeatable by CLI.

CLI has poor discoverability? Sure; but even on the terminal, discoverability can still be good:

A couple of nice examples of discoverability in keyboard-focused programs:

– emacs’ which-key[0]; there’s a vim port[1] too. This shows you (some) of the available keybindings for the next input, and a short label. So you don’t have to remember what `SPC h p …` or all the options under `SPC f…`.. but it still helps to recall that `SPC h` is for ‘help’ related commands, `SPC f` for file related commands.

– emacs’ magit[2][3]. Magit is so good at discoverability, that I’d rate it as the best tool for using git with. I’ve learned more about git from using it.

[0] https://github.com/justbur/emacs-which-key

[1] https://github.com/liuchengxu/vim-which-key

[2] https://magit.vc/

[3] https://emacsair.me/2017/09/01/magit-walk-through/

Yeah, you’re right that CLI discoverability can still be good, but that’s the same “can” than when talking about how “Electron apps can be responsive and fast” when putting VSCode as the prime example… yes, they can, but only with a great deal of extra effort from the devs, compared to the instantaneous visual feedback that a new entry provides on a GUI.

In practice (which is what matters, ultimately), most CLI tools don’t have this desirable property of “discoverable by accident”.

Slight nit-picking; maybe the distinctions are useful for this conversation:

I’d use “CLI” more precisely to refer to command-line invocation of programs (using some shell like bash, fish, or powershell).

For programs like vim or nano, I think “TUI” (text-based UI, or sometimes terminal UI) is more suitable.

> yes, they can, but only with a great deal of extra effort from the devs, compared to the instantaneous visual feedback that a new entry provides on a GUI.

Right.

I’d say instantaneous visual feedback is what helps discoverability. Both menus in a GUI, and the menus in a TUI like in the examples above, exhibit that.

But, I wouldn’t go so far as to say that a GUI menu is inherently discoverable. e.g. The image editor GIMP doesn’t have good discoverability, despite being a GUI program with menus.

Whereas e.g. nano is a TUI program, but its essential features are much more discoverable compared to vim. The new tmux-alternative zellij borrows the same “show the keymap at the bottom” feature.

> I’d use “CLI” more precisely to refer to command-line invocation […] For programs like vim or nano, I think “TUI” (text-based UI, or sometimes terminal UI) is more suitable.

Agree! I also consider that distinction but didn’t think of it when writing. Luckily we knew we were talking about the same thing 🙂

You’re right about the GIMP example, but I think that just means that being a GUI program is not an automatic, free-pass guarantee to discoverability. GUIs make software capabilities more evident by the mere fact that they are there right in your line of sight, but of course it still needs a touch of good organization. But that becomes then a matter of visual design and information overload, which is a whole new area.

TUI programs can be perfectly discoverable, as any well written Ncurses app can show. I don’t use many, but the first one that comes to mind is Aptitude. You can just run it and, again, most if not all of the possible actions and settings of the program are right there in front of you to explore or notice.

`which-key` is great. But that is already ubiquitous through the standard top-left drop-downs in a GUI:[1] Press `Alt-F` (File, underlined F), all options drop down, then `S` (Save, underlined S).

[1] Or a standard GUI. Emacs can be run as a GUI (not terminal).

I agree that Vim’s a mess, but I don’t think a good GUI is unconditionally better because you’d need to cut down Vim’s gigantic command set in order to make the GUI comprehensible.

Just in this thread we’ve seen options for: close unless there are changes, discard changes and close, save and close, save if changed and close, and save with encryption and close. These would not be menu items.

In a GUI, you would have close (which would always prompt if there were changes, unless you turned it off globally), save (which wouldn’t do anything if there were no changes), and perhaps some extra setting somewhere about an encryption key. Which would mean you’d lose the option to unconditionally save (useful sometimes if you have something watching the file and you’re testing), and you’d have an extra dialog box which pops up sometimes. In terms of discoverability, it’s unconditionally better, but it’s not unconditionally better in all other ways.

Personally, I think Sublime Text and VSCode’s feature to search for a command (Cmd-Shift-P, Ctrl-Shift-P) strikes the right balance for discoverability within a large set of commands in a GUI app. I wish the feature was standard in all GUI apps. I wish macOS provided the feature for GUI apps as part of its menu bar implementation.

programs 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

gvim suggest :wqa for “save and quit” in the file menu, which is like “:x” but will save all changed buffers, not just the current buffer.

both :xa and :wqa work for this though.

GVim does have a menu which lists the commands next to the menu options. That’s one area in which I feel neovim has regressed -having a default built-in discoverable interface. The various GUIs on offer for it seem aimed at the expert console user, rather than being an effort to bring good GUI to vim.

A good software interface must be discoverable by the user. I imply here that hardly anyone knows about ZZ because of improper design, which explains why it’s not generally mentioned in tutorials.

Compare vim or its clones with any KDE application, which always has keybindings shown in menus, and always a complete list of rebindable keybindings in the settings menu.

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

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

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

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

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

See Also

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

Really? 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”.

No, a tool can be designed well and still require training. It’s not the tool’s job to teach the user how to use it.

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

This is a terrible example. Why is it ctrl? Why is it to the right instead of the left?

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

> ctrl+C is copy, and ctrl+V is the key right next to it for paste

That works in English on a QWERTY keyboard. Maybe not in other languages, and while it can be explained, it doesn’t necessarily help to recall. I remember my father coming up with mnemonics to remember Ctrl-V.

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

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

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

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

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

Been using vi for just over 25 years now. The only thing I know how to do in emacs is exit 😀 vi uses the ctrl key a ton if you know what you are doing.

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

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

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

Maybe it’s just me, but I find :wq a lot easier to type… For 😡 (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.

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

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

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

TIL that :wq is like 😡

I only knew about :x. So thus far I’ve only edited with :x, and then used :q! to quit without writing the changes.

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

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

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

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

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

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

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

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

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

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

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

I know maybe 4 Vim commands I use to write git commit messages as I was too lazy to change the default editor. 😡 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.

A 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

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

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

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

Its one of the things about exiting Vim. If you type :q, and there are unsaved changes it will prompt you to save it first and not let you quit.

So most people do :wq so that it saves and then quit or do :q! to quit without saving changes. Most people stop using :q.

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

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top