News for hackers. Stuff that matters.
Re:How to Exit Vim by yason on Wednesday January 08, 2020 @05:56AM (#21990283)
In the opposing vein, as an Emacs user the best configuration I ever made was to rebind C-x C-c to execute-extended-command instead of kill-emacs. It was way too easy to (even accidentally!) kill emacs with a sweep of a finger. And I probably use a few hundred execute-extended-command calls for each kill-emacs (which I now have to type manually as 'C-x C-c kill-emacs' - no problemo).

A similar optimisation was with tmux to bind the prefix to C-z. It's in a handy location next to ctrl and I very rarely use suspend anyway (which is still available as easily as C-z z). Stretching your fingers between ctrl and b (the default prefix key) merely made me wonder who the heck thought of something like this?

As for vi, I made a point of learning to use it enough to do useful work editing config files and small texts. Every once in a while another application brought up 'vi' for some reason (maybe I lost VISUAL or EDITOR while sudoing or the app was looking for another variable) and I could never exit the damn thing.

So instead of just learning :q and figuring out how to make the particular program or script relaunch another editor I thought it's the path of least resistance to just edit with vi directly. It has been an incredibly handy skill: I never use vi for anything larger but these days I actually do 'vi /etc/fstab' myself instead of calling for emacsclient.

However, I've been toying around with the idea of eventually writing a minimal 'vi' clone that you cannot exit. I'm sure there's pent-up demand just waiting for one!

Re:How to Exit Vim by anotheryou on Wednesday January 08, 2020 @06:40AM (#21990506)
I think emacs is the winner here. It's true beauty is that most users have remapped everything so all you can do is bruteforce your way to the exit.

And where do you get exiting an OS? We don't know... maybe another OS...

Re:How to Exit Vim by dan-robertson on Wednesday January 08, 2020 @04:57PM (#21996225)
Usually people don’t remap the menus much so I think if you clicked around the modeline enough you could pull up some help and eventually figure out the binding for kill-emacs or execute-extended-command.
Re:How to Exit Vim by mvilim on Wednesday January 08, 2020 @09:47AM (#21991871)

  | However, I've been toying around with the idea
  | of eventually writing a minimal 'vi' clone that
  | you cannot exit. I'm sure there's pent-up demand
  | just waiting for one!
If a user space program can be truly unexitable without restarting (including the possibility of killing it through another shell, of course), then would you consider it to be a bug in the operating system? Seems a reasonable conclusion to me.
Re:How to Exit Vim by cjfd on Thursday January 09, 2020 @06:29AM (#22000302)
I once played a maze game on X where the maze would literally not allow the mouse cursor to go through the walls so it would be taken hostage. The only way to continue your X session was to solve the maze. That was quite funny. Oh, well, there could have been some other keys that would have done something about it but it was fun anyway.
Re:How to Exit Vim by stefco_ on Wednesday January 08, 2020 @06:29PM (#21996924)
It would indeed be a bug, which is why any self-respecting operating system should include uninterruptible vi in the kernel /s
Re:How to Exit Vim by dbtx on Thursday January 16, 2020 @10:08PM (#22071511)
Alt+SysRq+k

(read linux/Documentation/admin-guide/sysrq.rst before you try this)

Re:How to Exit Vim by namelosw on Wednesday January 08, 2020 @07:24AM (#21990745)
Emacs is so dynamic and easily configurable, that people can actually rebind a lot of things when their colleague go to the bathroom as a prank.

Just open a scratch file, enter some s-expressions, evaluate them, then kill the buffer.

Re:How to Exit Vim by bregma on Wednesday January 08, 2020 @08:53AM (#21991383)
The last time I went to the bathroom as a prank HR had to have another talk with me.
Re:How to Exit Vim by kanon11 on Wednesday January 08, 2020 @09:11AM (#21991546)
Never go to the bathroom as a prank.
Re:How to Exit Vim by nine_k on Wednesday January 08, 2020 @09:54PM (#21998122)
Would serve the victim right.

Never leave your unattended keyboard and screen unlocked.

Re:How to Exit Vim by eitland on Thursday January 09, 2020 @12:40AM (#21998821)
At some place I worked there was a policy that a small prank was allowed if the workstation was not locked when someone left. I'd almost recommend that policy for some places.

Acceptable pranks would be things like:

- innocent videos (annoying videos for toddlers etc)

- change Spotify playlist from rock to childrens songs or rickroll or something

- open MS Paint and draw something (those pranks weren't necessarily small, we got three huge monitors side by side on those workstations)

- etc

Unacceptable pranks:

- anything that wasn't possible to revert in a hurry

- anything a customer couldn't see (we were on display :-/ )

At another place I know someone sent a mail to the team from someone elses account that they would bring cake the next day.

I once burned myself by doing what I thought was the obvious thing: leaving a message in a text editor and locking the machine. Turns out for some reason he couldn't unlock it after it had been locked that way and he needed to leave the campus to have IT at the main site unlock it. (When he locked it he always did it by closing the lid instead of through the system menu.)

Re:How to Exit Vim by jhoechtl on Wednesday January 08, 2020 @11:28AM (#21992843)
That's why my scratch buffer is by default NOT in elisp mode
Re:How to Exit Vim by greggyb on Wednesday January 08, 2020 @12:22PM (#21993536)
You can evaluate an elisp expression anywhere in any mode.
Re:How to Exit Vim by dan-robertson on Wednesday January 08, 2020 @04:59PM (#21996241)
As an aside you can also make a (non-elisp) scratch buffer on the fly: when you switch buffer just enter a name that isn’t taken (I usually use b, bb, bbb, ...)
Re:How to Exit Vim by e12e on Wednesday January 08, 2020 @11:36AM (#21992939)
> A similar optimisation was with tmux to bind the prefix to C-z. It's in a handy location next to ctrl and I very rarely use suspend anyway.

I think gnu screen has the right idea here: ctrl-a.

And you say z is close to control - does that mean you use emacs without shift lock as control?! (I mean sure, still closer than b...).

Re:How to Exit Vim by smabie on Wednesday January 08, 2020 @05:19PM (#21996382)
C-a is the worst default keybinding ever, since like, going to the beginning of a line is one of the most common operations.
Re:How to Exit Vim by e12e on Wednesday January 08, 2020 @05:30PM (#21996467)
Well, not with proper key bindings ;) (set -o vi)
Re:How to Exit Vim by ak217 on Wednesday January 08, 2020 @06:44PM (#21997013)
In the rest of the universe, going to the beginning/end of the line is mapped to the Home/End keys (fn+left/fn+right on Macs), and I do prefer it when my thing does things in ways that roughly correspond to how the rest of the universe does them if there's no compelling reason to do otherwise.
Re:How to Exit Vim by eitland on Thursday January 09, 2020 @12:31AM (#21998795)
> (fn+left/fn+right on Macs)

When I used Mac in 2009 to 2012 it depended on the application you were using:

Some used fn+left/fn+right, some used CMD+left/CMD+right and I think ctrl and/or alt + arrow keys were an option too.

ctrl a/ctrl e would work everywhere I think but I didn't use those as they didn't work with shift to select to the start or end of the line.

As a keyboard type of person this was a major part of what drove me away from Mac despite its many advantages :-(

Re:How to Exit Vim by samatman on Wednesday January 08, 2020 @12:32PM (#21993661)
Caps lock isn't shift lock though.

I know, because I have triple-shift-press mapped to shift lock on my Ergodox. It's... usually better, but sometimes I type a @#$%@#$% swear word when I mean to enter a number.

Re:How to Exit Vim by yason on Thursday January 09, 2020 @06:47AM (#22000387)
I have remapped capslock to be an additional ctrl so I hit C-z easily with my pinky + ring fingers.

C-a (like in screen) would be even better but as others have pointed out it masks going to the beginning of line which is very common.

C-z is very rarely needed. C-q/C-s would be good candidates also as I don't think I've ever needed flow control in this century nor the last one, for that matter.

Re:How to Exit Vim by JadeNB on Wednesday January 08, 2020 @12:39PM (#21993738)
> And you say z is close to control - does that mean you use emacs without shift lock as control?! (I mean sure, still closer than b...).

Presuming Shift Lock means Caps Lock, that and Control are both close to Z on my (Apple) keyboard.

Re:How to Exit Vim by earenndil on Wednesday January 08, 2020 @04:28PM (#21995989)
I use ctrl-a quite a lot on the command line, though.
Re:How to Exit Vim by dan_hawkins on Wednesday January 08, 2020 @07:10AM (#21990654)
'screen' uses C-a as a prefix shortcut so developers of 'tmux' decided to use the next available key to avoid clash.
Re:How to Exit Vim by shawnlower2 on Wednesday January 08, 2020 @07:41AM (#21990857)
I don't understand the logic there. In what non-contrived scenario would you run both simultaneously, such that they would conflict?

C-a does annoyingly conflict with readline's "move to start of line", though.

Re:How to Exit Vim by andrewla on Wednesday January 08, 2020 @11:11AM (#21992657)
My understanding of the history is that the developers of tmux were using screen to develop tmux, because tmux didn't exist yet, so they needed a non-conflicting keystroke.

Obviously they could have switched before a general release, but I guess they had gotten used to it.

Re:How to Exit Vim by Nacraile on Wednesday January 08, 2020 @08:32AM (#21991228)
1. Outer tmux on local/primary machine, for your usual daily use-case (i.e. managing multiple terminal sessions).

2. In outer tmux, ssh to some other machine you need to administrate.

3. screen because you need multiple terminal sessions on that machine, or need detachability/reconnectability for some long-running process.

Re:How to Exit Vim by jethro_tell on Wednesday January 08, 2020 @02:16PM (#21994723)
Also, many older production machines don't have tmux, so nesting a screen session happens. This is starting to not be a thing, but it was a thing for the trailing 10 years.
Re:How to Exit Vim by justwalt on Wednesday January 08, 2020 @06:28PM (#21996916)
At work, my desktop has tmux, but the servers we deploy on only have screen.
Re:How to Exit Vim by jimktrains2 on Wednesday January 08, 2020 @07:50AM (#21990910)
Hitting C-a twice sends it to the terminal.
Re:How to Exit Vim by syncsynchalt on Wednesday January 08, 2020 @07:33PM (#21997337)
Close... "C-a a" sends a real "C-a", while "C-a C-a" swaps with your most recent window (it's fast and convenient to type).
Re:How to Exit Vim by wffurr on Wednesday January 08, 2020 @07:04AM (#21990621)
How do you exit, then, if you never learned :q?
Re:How to Exit Vim by worble on Wednesday January 08, 2020 @07:10AM (#21990656)
He never did, some say he's still in vi to this day.
Re:How to Exit Vim by DarkWiiPlayer on Wednesday January 08, 2020 @07:46AM (#21990877)
The story of every 2 out of 3 vim users
Re:How to Exit Vim by exikyut on Wednesday January 08, 2020 @08:48PM (#21997744)
4 out of 3* FTFY

Or perhaps it's 5, or 6.

Re:How to Exit Vim by dan-robertson on Wednesday January 08, 2020 @05:00PM (#21996254)
Switch to a different terminal, log in, find the process, kill it.
Re:How to Exit Vim by SAI_Peregrinus on Wednesday January 08, 2020 @02:56PM (#21995104)
ctrl-z to background it. Then `kill` it.
Re:How to Exit Vim by vidarh on Thursday January 09, 2020 @06:09AM (#22000192)
That was how I'd exit vi for a long time. Often "killall vi" because any other vi instances running would in any case be by accident.

I once caused a near rebellion of vi users when I was running an ISP and symlinked vi to emacs on our shell server because I was sick and tired of it...

Re:How to Exit Vim by Tcepsa on Thursday January 09, 2020 @03:26PM (#22005274)
Had the same issue with C-x C-c; I remapped mine to C-x C-c C-t because it worked for me as a mnemonic (assuming a "soft c"): "ex-s-t" => "eckst" => "exit"). Major productivity boost!
Re:How to Exit Vim by shiloa on Wednesday January 08, 2020 @09:12AM (#21991557)
Nice.

I did something similar w/ tmux: map the prefix key to C-a and map CapsLock key to Ctrl (never found real use for it). So Ctrl-a (actually CapsLock-a) is very ergonomically pleasant.

Re:How to Exit Vim by smabie on Wednesday January 08, 2020 @05:21PM (#21996395)
What about moving to the beginning of a line?
Re:How to Exit Vim by jlgaddis on Thursday January 09, 2020 @04:01AM (#21999607)
I did the same thing but I also mapped Ctrl-\ to send the "prefix" (helpful for neated tmux sessions), so I just hit Ctrl-\ for beginning of line.

(Although this seems to have broken in recent tmux releases on Debian (3.x?) and I haven't looked into yet.)

Re:How to Exit Vim by shiloa on Thursday January 09, 2020 @06:17AM (#22000226)
Ctrl-a + Ctrl-a, works like a charm :)
Re:How to Exit Vim by jessant on Wednesday January 08, 2020 @01:00PM (#21993957)
command wq <nop> command w <nop> command q <nop>
Re:How to Exit Vim by tynorf on Wednesday January 08, 2020 @01:35PM (#21994343)
Unfortunately:

  E183: User defined commands must start with an uppercase letter
Re:How to Exit Vim by jessant on Thursday January 09, 2020 @03:37PM (#22005414)
command W <nop>

cabbrev w <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'W' : 'w')<CR>

cabbrev q <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'W' : 'q')<CR>

cabbrev q! <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'W' : 'q!')<CR>

cabbrev wq <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'W' : 'wq')<CR>