Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

ctrl-z is the short cut for bg,what's for fg?

Anyone knows this?

share|improve this question

closed as off-topic by Cristian Ciupitu, Ward, mdpc, kasperd, cole Jul 20 '15 at 23:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Cristian Ciupitu, Ward, mdpc, cole
If this question can be reworded to fit the rules in the help center, please edit the question.

crtl+z sends the suspend signal (SIGTSTP). It doesn't place the process in the background.

share|improve this answer
it works as bg while in vim,so I want another short cut to go back to vim instead of typing fg.. – linux Jun 24 '11 at 2:33
Nope, wrong again. Vim is being suspended; that is not the same as running in the background. A suspended job is just that, one that isn't running. bg runs the job, but stdin and stdout are no longer attached to the console. fg attaches a background or suspended job to the console again. – Chris S Jun 24 '11 at 2:34
is there a short cut to attach a suspended job to the console again? – linux Jun 24 '11 at 2:38
Not that I am aware of, though various distributions tend to do whatever they please. – Chris S Jun 24 '11 at 2:45
+1 to @ChrisS for this observation. Some distributions/versions of terminal applications will also allow the end user to set their own custom keyboard commands through a GUI or setting menu. For example on OS X will allow some customization under Terminal->Preferences->Keyboard. – Matt Jul 13 '15 at 21:13

You can define your own in $HOME/.inputrc...

"\M-z": "fg\n"

...or by adding bind -x's to your .profile/.bashrc.

bind -x '"\M-z"':"fg" # ALT+Z

For more information, see the READLINE section of the bash manpage.

share|improve this answer
just tried,seems not working. – linux Jun 24 '11 at 4:34
Which method did you try? Did you reload the relevant files? (e.g., logging out/back in; starting a new shell; running . .bashrc or . .profile; or pressing CTRL+x CTRL+r for .inputrc if default keybindings haven't been changed) If so, do you get any errors? – Kanji Jun 24 '11 at 20:36

The goal is, I suppose, to exit vim, do some shell stuff and reenter vim as fast as possible. I got quite fast by using crtl+z to exit vim and crtl+z again to reenter.

Exit works well without further ado.

To make the reentry work I undefed the standard crtl+z behaviour (susp) and mapped it to fg followed by the Enter key (\015).

These are the relevant lines from my .bashrc.

stty susp undef
bind '"\C-z":"fg\015"'

Works like a charm on OS X 10.10 and Ubuntu Linux 12.04 LTS. Probably should work on other Unices, too.

See also this Github Repo for a nice looking solution using iTerm2 and these vim productivity hints for a native zsh implementation (hint VII) and other general awesomeness.

share|improve this answer
Wait until you discover :!... – Michael Hampton Jul 13 '15 at 21:32
Yeah, I know about :!. It's just better suited to one off commands and not for longer sessions in the shell. Of course, one could also use a tmux split and a vim session side by side... – Dennis Wegner Jul 14 '15 at 18:55
And I have multiple Konsoles open. There's more than one way... – Michael Hampton Jul 14 '15 at 18:59
So I didn´t undef susp, and did bind -x '"\C-a":"fg"' and this works great. ctrl-a is now 'anti-ctrl-z', so I can quickly switch between terminal and vim, and only one arrow up to repeat last command to test the updated script or code. – xxor Oct 2 '15 at 8:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.