Most active commenters

    ←back to thread

    1062 points mixto | 14 comments | | HN request time: 0s | source | bottom
    1. aidos ◴[] No.42946123[source]
    Not wrong, but since you’re mentioning vim in the context of git, might be worth adding :cq as a way to exit with a non-zero status to prevent git from finishing the commit / operation.
    replies(7): >>42947682 #>>42948679 #>>42948693 #>>42950588 #>>42952635 #>>42954667 #>>43021805 #
    2. usrme ◴[] No.42947682[source]
    This is a fantastic mention! I've been commenting out my commit message lines and then saving as a way to trigger this. Feeling like a caveman...
    replies(1): >>42955330 #
    3. dotancohen ◴[] No.42948679[source]
    I just love nuggets like this. I've been using VIM for 26 years and git for about 15. I never knew about adding c. I've always felt that :q! should exit with a non-zero status code, at least if no :w had been made.
    4. ericholscher ◴[] No.42948693[source]
    I usually use :q! which seems to do the same thing
    replies(2): >>42952186 #>>42966198 #
    5. beej71 ◴[] No.42950588[source]
    TIL! The funny thing about Vim is that you can have used vi/Vim for 30+ years and still learn new things. I'll add this to the Vim appendix. Cheers!
    replies(1): >>42952451 #
    6. alexjm ◴[] No.42952186[source]
    The minor difference is that :q! quits without saving but returns zero as the exit code, but :cq quits with a nonzero exit code. Git interprets the nonzero exit code as "editing failed", following the Unix convention that zero means success. If you didn't save the commit message while working on it, :q! will send the empty template back to Git, which Git is smart enough to not commit. But if you accidentally save your work partway through, :q! will still commit the message you wanted to abandon.
    7. dexzod ◴[] No.42952451[source]
    It is the same with Git
    replies(1): >>42955481 #
    8. iN7h33nD ◴[] No.42952635[source]
    Interesting I’ve always just deleted the contents of the entire buffer and :wq to cause a failure due to lack of message
    9. olalonde ◴[] No.42954667[source]
    Mnemonic to help remember: cancel quit
    10. celticninja ◴[] No.42955330[source]
    Guilty as changed your honour
    replies(1): >>42961622 #
    11. agent281 ◴[] No.42955481{3}[source]
    If you have been using git for 30+ years, you need to take me to your time machine. It turns 20 this year.
    12. malvim ◴[] No.42961622{3}[source]
    Guilty as UNchanged*
    13. sangnoir ◴[] No.42966198[source]
    That only works if the edit buffer is blank or only has commented out lines. In other cases, such as when you're trying to cancel a `git commit --amend` that loads up the last commit message in your buffer, :q! will not cancel the commit, but :cq will.
    14. rstuart4133 ◴[] No.43021805[source]
    :cq is useful in a shell loop that compares two directory trees that invokes vim to let you see what's changed in every file that's different. I use it often:

        ((cd /tmp/t; find . -type f -print) | sort | while read f; do cmp -s {/tmp/t,/tmp/t1}/$f || vim -f -d {/tmp/t,/tmp/x1}/$f 0<&9 || break; done) 9<&0
    
    Typing ^C to vim doesn't get you very far, so if you make a mistake causing the loop to return 1000's of files you are in for a bit of pain without :cq. The :cq triggers the break, exiting the loop.