Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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
7  
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
1  
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 Terminal.app on OS X will allow some customization under Terminal->Preferences->Keyboard. –  Matt Jul 13 at 21:13

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

# ALT+Z
"\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 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 at 18:55
    
And I have multiple Konsoles open. There's more than one way... –  Michael Hampton Jul 14 at 18:59

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