7 ms·
Of all the z’s my favorite by far is Ctrl-z, which send the current application to sleep and drops you back to the terminal, where you can do whatever you need
by imron 4y ago
Of all the z’s my favorite by far is Ctrl-z, which send the current application to sleep and drops you back to the terminal, where you can do whatever you need before using ‘fg’ to return the slept process to the foreground.
It works with everything but I use it with vi most of all.
You can even sleep as many processes as you like and choose which one to return to the foreground as needed.
- caymanjim 4y agoI almost never suspend vim, because I run it exclusively inside tmux, and it's a lot easier to just open a new window/pane, run something, and close it when done.
- Lapsa 4y agoyap... same here
- kagevf 4y agoIt's useful running vim in git bash on Windows. I'll switch, though, if I ever figure out how to install tmux in that environment then I'll switch.
- caymanjim 4y agoThere's no good reason to run git bash on Windows anymore either, since you can use WSL!
- kagevf 4y agoActually, when I tried to use git on Win10 it worked at first but then at some point stopped functioning. Now that I'm on Win11, I definitely need to revisit that - thanks for the reminder! The only downside, though, is the clipboard won't be as easily accessible. I'm thinking of things like piping text to clip.
- cerved 4y agoWSL has absolute dogshit I/O so that's not true
- kagevf 4y agoI think that's what I ran into ... but not at first, only later, which was weird ...
- daveguy 4y agoIf you need to run tmux in git bash, this worked for me: 1. Installs msys2 (which includes pacman package manager) # can be done separately from your git installation 2. pacman -S tmux # install tmux to msys2 within msys2 3. Copy tmux.exe and msys-event-2-1-7*.dll from msys2 to C:\Program Files\Git\usr\bin # may be a different version msys-event 4. Uninstall msys2! This was important to me because I found edge cases where msys2 did not honor directory links as "not msys files" and it borked things. YMMV
- matsemann 4y agoIt's also a footgun for new terminal users, hehe. Wan't to undo something, instead you think you've suddenly nuked your program and lost all progress. So start a new one instead.
- raverbashing 4y agoHah, not really, the real foot gun is Ctrl-s on a session (Ctrl-q to unlock it)
- jstanley 4y agoOr whatever the key shortcut is that puts gnome-terminal in "read only" mode, that I kept doing by accident for years, before I found out how to undo it (right-click, toggle "read only"), thinking it was an obscure gnome-terminal bug.
- eMPee584 4y agoBothered me enough to turn it off once and for all with a /etc/profile.d/stty-flow.sh: #!/bin/sh # turn off stupid flow control and shut up. stty -ixon -ixoff 2>/dev/null
- xigoi 4y agoUnfortunately, many modern shells like Nushell or Elvish don't implement this feature for some reason.
- dotancohen 4y agoI'm glad I've never heard of them. What do they offer?
- hnlmorg 4y agoMy shell, https://GitHub.com/lmorg/murex https://GitHub.com/lmorg/murex does. It’s not a trivial thing to support though. ‘jobs’, ‘bg’ and ‘fg’ need to be shell builtins. Other shell builtins might not work if they’re not POSIX fork()s and you need to handle STDIN a little more carefully. It’s a lot of work for a feature that many alt shell users might not even be aware of.
- jacknews 4y agoExcept when you forget all about this ancient single-tasking terminal convenience, and accidentally enter ctrl-z, and can't remember how to get back again (nope, not ctrl-d).
- juliushuijnk 4y agoYes you need to remember 'fg', but the argument 'you have a big problem if you forget how to do this' could be said for half of how Vim works.
- jacknews 4y agoLOL, true. I still sometimes blow everything up or activate some weird corner of functionality with a slip of the finger.
- ComputerGuru 4y agoSorry, remembering fg isn’t that hard. The real issue is when you do ctrl-z from muscle memory on Windows while running nvim from cmd (through wsl runner but not from an actual shell) and then it just disappears and takes your data with it.
- jstanley 4y agoI use ":sh" for this purpose, but it has the problems that: - you get a new shell, so your history is lost - if you have a "stack" of vim's you have to return to them in stack order - I develop a habit of typing Ctrl-d when I want to get back to vim, which means I accidentally log out of SSH sessions all the time if I actually haven't still got vim open I think getting in the habit of using Ctrl-z instead would be a big improvement.
- UI_at_80x24 4y ago> - you get a new shell, so your history is lost To prevent that from happening you can add this to your .bashrc #write to history file at each shell prompt export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
- cerved 4y agoNote that this can slow down your shell. Also it mingles histories from different sessions. Stop doing this myself for these reasons
- UI_at_80x24 4y agoYes, these are good points but I've found the benefit outweighs the annoyance. fzf for a history searcher really helps. BUT not being able to 'up arrow' the previous command is annoying at times. So far it's a 6/10 Slightly better then not doing it. =)
- recuter 4y agoCtrl-z is useful to be sure but nowadays (n)vim has terminal emulators built-in. I use this plugin: https://github.com/akinsho/toggleterm.nvim https://github.com/akinsho/toggleterm.nvim Nvim also has a new --listen flag (if you ever tried nvr this is now built in). So no matter where you are the file will open in your main nvim instance. No need to exit.
- calvinmorrison 4y agoIts not exiting, its suspended. But yeah
- artificialLimbs 4y agoYo dawg, I heard you like terminals...
- behnamoh 4y agoIf you're using zsh with plugins, then your shell startup time is already high. Ctrl+z drops you back to an existing shell, but toggleterm spawns a new shell which can be annoying.
- recuter 4y agoI do but this plugin is a vim one. Both my vim and zsh start instantly (<100ms).
- qu4z-2 4y agoWhy on earth would I want to open a terminal emulator in vim when I'm already in a terminal emulator?
- cerved 4y agoto use visual mode on the terminal, yank, paste etc.
- fortran77 4y agoThat’s an OG unix command, not a vi command.
- chasil 4y agoShell job control actually originated in Bill Joy's csh as part of BSD (as did vi). It was adopted by the Korn shell, then codified into the POSIX shell. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/jobs.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/j...
- imron 4y agoYep I know, but it’s a core part of my vim workflow.
- michaelmior 4y agoI have the following in my .zshrc that I'm sure I copied from somewhere. It allows the use of Ctrl-z to also resume programs runnings in the background instead of manually typing fg. # Allow Ctrl-z to toggle between suspend and resume function Resume { fg zle push-input BUFFER="" zle accept-line } zle -N Resume bindkey "^Z" Resume
- mtlmtlmtlmtl 4y agoThis is really neat! Threw it in my .zshrc right away. Thank you sir.
- _huayra_ 4y agos/fg/bg/ ?
- michaelmior 4y agoNo. When a program is running in the shell, the default behavior is for Ctrl-z to suspend the program. Nothing needs to be done for that to happen. This snippet runs `fg` when you're back in the shell and press Ctrl-z. That said, if you wanted to continue running in the background with `bg`, you could make that substitution to allow you to double tap Ctrl-z to do so.
- _huayra_ 4y agoOh wow I totally misunderstood this snippet; I thought it was in fact the opposite (i.e. a shortcut to send a job to the background). Toggling back to the foreground is even better with the same shortcut! Neat!
- jopython 4y agoSolution for bash anyone? Saw this in the internets if [[ $- == i ]]; then stty susp undef bind '"\C-z":" fg\015"' fi
- michaelmior 4y agoFWIW, after a quick Google search, I think this may have been the original source. https://www.reddit.com/r/vim/comments/9bm3x0/ctrlz_binding/ https://www.reddit.com/r/vim/comments/9bm3x0/ctrlz_binding/
- whartung 4y agoHeh, don’t get me started. I personally rarely used ^Z, I simply banged out. However shelling out was intrinsic to my workflow. We didn’t have screen or any of the other common multi session terminal programs at the time. One day I decided to log out. I rarely logged out. If anything I was kicked off by a system restart. So to log out I started closing sessions. Turns out I was at least 30 deep. Some files were being edited more than once, I even had shells within shells (which typically did to play ENV shenanigans).
- anthomtb 4y agoIf you just need a single shell command you can do :!<command>. Example: :!ack "stupid_structure->who_wrote_this_crap.oooohhhhh\s+=" (and if you wonder what "ack" means: https://beyondgrep.com/ https://beyondgrep.com/)
- imron 4y agoAnd if you need the output of your shell command in your buffer you can do :r !<command>