334

From vi, if you issue the command :sp, the screen splits into two "views", allowing you to edit more than one file from the same terminal.

Along those same lines, is there a way to have multiple shells open in the same terminal?

Justin Ethier
  • 16,806

10 Answers10

440

You can do it in screen the terminal multiplexer.

  • To split vertically: ctrla then |.
  • To split horizontally: ctrla then S (uppercase 's').
  • To unsplit: ctrla then Q (uppercase 'q').
  • To switch from one to the other: ctrla then tab

Note: After splitting, you need to go into the new region and start a new session via ctrla then c before you can use that area.

EDIT, basic screen usage:

  • New terminal: ctrla then c.
  • Next terminal: ctrla then space.
  • Previous terminal: ctrla then backspace.
  • N'th terminal ctrla then [n]. (works for n∈{0,1…9})
  • Switch between terminals using list: ctrla then " (useful when more than 10 terminals)
  • Send ctrla to the underlying terminal ctrla then a.
Bdoserror
  • 103
shellholic
  • 6,255
  • 19
    Tmux also does this, and many terminal programs have split views and tabs. – Shawn J. Goff Feb 15 '11 at 16:51
  • I'm having some trouble splitting my screen (either vertically or horizontally) under Centos 5 using zsh (under Virtual Box). When you refer to "uppercase one" for ctrlaS, do you mean that I should hold shift or use caps lock, as neither of these seem to be working. Apologies in advance if this is a noob question. OFF TOPIC - I'm not completely sure why my markup isn't working - I have already tried to follow the guidelines here http://meta.stackexchange.com/questions/1777/what-html-tags-are-allowed-on-stack-overflow-server-fault-and-super-user – Aaron Newton Dec 02 '11 at 13:26
  • 4
    @AaronNewton ctrl+a then release everything then shift+s (don't know for caps lock, mine is disabled) – shellholic Dec 05 '11 at 12:43
  • @shellholic - cheers. This takes a bit of coordination, but I just got it to work. – Aaron Newton Dec 05 '11 at 21:32
  • 6
    Ctrl A Shift S splits the screen, then Ctrl A Tab switches to the other split, and Ctrl A c creates a bash prompt. Is there anyway to have these commands run automatically when starting screen so we don't have to run the commands all the time. – Michael Butler Sep 19 '12 at 14:22
  • 2
    Which version of screen for the vertical split? The version I have installed is 4.00.03, which is the same as the latest available download from from all the mirrors I've checked. – Brian Vandenberg Oct 14 '13 at 20:53
  • According to the docs, you press escape, then press ctrl-a, then |. – Jacob Valenta Sep 12 '14 at 05:55
  • 1
    How do I make one of my vertical windows wider than the other? I want like a 30|30|40 split. – mpen Mar 18 '15 at 22:58
  • 1
    @BrianVandenberg: http://unix.stackexchange.com/questions/26685/how-to-split-window-vertically-in-gnu-screen - looks like it requires a patched version. – naught101 May 19 '16 at 00:16
  • @naught101 As of the most recent version I pulled from (sourceforge? github?), vertical splits are in standard releases now. – Brian Vandenberg Jul 21 '16 at 15:36
  • Using screen, is there a way to scroll up to see information which pushes off the top of the split when you do, say ls -al? – Peter Feb 14 '17 at 07:54
  • Vertical split doesn't work for me. I have this version Screen version 4.00.03 (FAU) 23-Oct-06 – thanos.a May 10 '17 at 09:10
  • 1
    @thanos.a your version is very outdated. Current version is in this git repo. – Ruslan Jul 27 '17 at 16:27
  • Can I do this programatically? I guess I can send some input with expect, but how to do Control and sequences? – Ondra Žižka Mar 02 '18 at 15:05
  • 1
    If you can not type the | character. You can still split using ctrl+a then : then split -v, as a command inside the screen. – user18099 Oct 13 '18 at 13:24
  • Does this work in ububntu? I have tried it but failed – Akhil Surapuram Sep 16 '19 at 04:24
  • After I detached, if I reattached, the layout is lost, how to get it back? – None Aug 12 '20 at 10:38
  • no command to see a manual page for the tool? – user1868607 Oct 05 '20 at 09:17
  • @Peter ctrl a and then Esc and then use arrow keys to scroll up to see info off the top. Hit Esc again to exit that scroll mode. – Michael Anderson Dec 15 '23 at 20:08
136

Try tmux (Terminal MUltipleXer):

tmux screenshot

And to understand the difference between session, window and pane: tmuxnestings

not2qubit
  • 1,666
  • 28
    Screen vs tmux? tmux is probably better for advanced usage and is more modern, but screen is installed everywhere and works just fine. – user606723 Apr 11 '13 at 21:31
  • 3
    Other great tmux help resources are: intro, config, primer and cheat-sheet. – not2qubit Dec 10 '17 at 10:49
  • 1
    @user606723 among other things the Tmux configuration is actually readable; not like a dog rolled over the keyboard. Of course you can make do with a wrapper like byobu (which wraps both terminal multiplexers), but Tmux seems to be superior in several aspects other than the configuration. And was already superior several years ago. Screen needed patches for splitting both directions and Tmux had it out of the box. last but not least the license may be an argument for Tmux or Screen, depending on where you stand. – 0xC0000022L May 07 '18 at 20:59
  • 1
    @user606723 as of 2019, this isn't true anymore. screen is missing from a relatively fresh install of Fedora 30, while tmux is present. – Sora. Jun 18 '19 at 11:15
  • Tmux is a great suggestion, this answer is missing an actual answer to the question though (just links to wiki and docs is not an answer). – Czechnology Apr 23 '20 at 09:39
  • @0xC0000022L The author of the article, https://opensource.com/article/17/3/introduction-gnu-screen, says that it is "included or available in nearly every Linux or UNIX distribution". The author goes on to say, "Screen is installed by default on some distributions, such as SuSE and Slackware." The author states that for other distributions like Fedora and Debian based distributions, screen is available through the "standard" package manager. Though screen is not installed by default, it is easily accessible on many systems. – Peter Bergman May 10 '23 at 15:53
  • @PeterBergman how does this relate to my comment? Did you mean to to comment on the very first comment, perhaps? I never contested that screen may be installed almost everywhere out of the box. In fact I have used screen to run prototypical "services" detached where tmux wasn't an option. However, in daily usage the readability and usability is a big deal, which is why byobu as a wrapper -- originally to screen (it's also in the name: byobu) -- was invented. And bare bones tmux wins in the UX department over screen any day for me ;) – 0xC0000022L May 10 '23 at 17:07
79

As mentioned in the comments, besides screen, another good terminal multiplexer is tmux. You can refer to the manual for a complete description and command reference. Some basic operations to get started are:

  • Split screen vertically: Ctrlb and Shift5
  • Split screen horizontally: Ctrlb and Shift"
  • Toggle between panes: Ctrlb and o
  • Close current pane: Ctrlb and x

You can achieve more complex layouts by splitting panes. You can also have multiple windows with panes and switch between them.

  • Create windows: Ctrlb and c
  • Switch to next window: Ctrlb and n
  • Switch to previous window: Ctrlb and p
  • Destroy current window: Ctrlb and Shift7
dkaragasidis
  • 1,906
23

If you want a program that just splits a terminal¹, there's splitvt. There are programs that split a terminal and do a lot of other stuff besides, such as Screen, Tmux, Emacs, …

¹ It's the terminal you're splitting, not the shell.

  • +1, good point about how the terminal is what is really being split. – Justin Ethier Feb 21 '11 at 14:37
  • Exactly what I needed. The link is dead, but this works https://manpages.ubuntu.com/manpages/xenial/man1/splitvt.1.html also apt install splitvt does the trick. Is there a way to split vertically? – ddofborg Nov 11 '22 at 13:15
21

Apart from the excellent suggestions on Screen and Tmux if you are using some sort of window manager you may be interested in Terminator you can split horizontally or vertically fashions, plus tabs and more... here's a list of features taken from the author's web site:

  • Arrange terminals in a grid
  • Tabs
  • Drag and drop re-ordering of terminals
  • Lots of keyboard shortcuts
  • Save multiple layouts and profiles via GUI preferences editor
  • Simultaneous typing to arbitrary groups of terminals

Have a look to the screenshots on the project site.

Most important you can combine Terminator with Screen/Tmux.

alemani
  • 413
  • 2
    Note that using Terminator splits will be less convenient when copypasting between two windows of your editor. – gb. Aug 07 '12 at 02:00
  • You can edit several panes at once after grouping the panes (or just selecting all at once), and you can edit the shortcuts for pane switching just as well. I have ctrl-shift-h/j/k/l for moving between panes, and ctrl-(shift)-tab for switching between tabs, it just works awesome. – sjas Feb 13 '16 at 19:57
  • 1
    good we can click on them to focus; but cant still find a way to evenly distribute the terminals in the grid, it is just a mess to be fixed by hand, also I need to dynamically add terminals, therefore get them updated in an evenly distributed grid, any idea? – Aquarius Power Apr 29 '16 at 22:24
  • Terminator is an X-windows program, not a command-line program like tmux and screen are. The OP specifically mentioned same terminal twice, so Terminator or tilix (as mentioned by @sjas) are not good suggestions. If you are in an ssh session to a remote server with no X server, you will not be able to even run these tools. – haridsv May 16 '19 at 11:39
11

Konsole for KDE has a built in function:

  • Ctrl+( to Split View Left/Right

  • Ctrl+) to Split View Top/Bottom

  • Shift+Tab will cycle through the split views

  • Shift+Left Arrow/Right Arrow will cycle the current view through the tabs/views

  • Ctrl+Shift+X to close the current view

MrUser
  • 527
9

Use terminator.

Should be available via your favourite package manager, if you use a mainstream distribution.

It is the only terminal multiplexer where copy-pasting works properly from within panes in your window.

Update: tilix is a terminator alternative which is almost completely on par with terminator (and where copypasting works properly, too). After evaluating it I still stick with terminator however due to nicer tab handling and easier configuration (from my POV).

sjas
  • 565
  • Terminator is technically not a multiplexer: "A terminal multiplexer is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session." (from Wikipedia) – erb Feb 13 '16 at 13:08
  • It is also not the only multiplexer where copy-pasting works properly from within panes, tmux does this just fine with the proper configuration. – erb Feb 13 '16 at 13:10
  • 1
    @erb - what exactly do have to configure if I dont want to select complete lines that span several terminals upon triple-clicking and why isnt that the sane default setting? – sjas Feb 13 '16 at 13:38
  • 1
    You can use copy-mode in tmux to do copying, if you want to use the mouse you should only need to enable mouse support, my config with it is here: https://github.com/ErikBjare/dotfiles/blob/master/home/.tmux/master.conf If you want to use the system clipboard with copy-mode see this: https://unix.stackexchange.com/questions/131011/use-system-clipboard-in-vi-copy-mode-in-tmux – erb Feb 13 '16 at 13:46
  • I already know about 'copy mode'... Honestly, it's not a viable option for serious work. – sjas Feb 13 '16 at 19:49
  • 2
    Huh? Why not? You can get it to work almost exactly (if not exactly) the same way as selecting in terminator. I used to be a terminator user for the same reason, once I got the config done I never looked back and can now save quite some RAM and other resources by switching to a more lightweight terminal emulator since the copying was the only thing annoying me. – erb Feb 14 '16 at 01:04
  • Terminator crashes many times to me – deFreitas Feb 01 '17 at 17:17
  • I use it exclusively, cannot confirm this problem with debian 8. – sjas Feb 02 '17 at 09:52
  • @erb: which were the tmux config options you needed to configure it to behave the same? – sjas Apr 04 '17 at 06:34
8

Guake + Byobu

Here I wrote a more complete answer.

I'm a happy user of Guake with Byobu inside it, which by default uses tmux (probably better than screen) as backend.

Three steps

  1. Install them (no PPAs needed on Ubuntu/Debian, check for other distros)

     sudo apt install guake byobu
    
  2. Add it to available shells (as told in this Guake Github issue):

     which byobu | sudo tee -a /etc/shells
    
  3. On Guake preferences (guake-prefs) choose Byobu as the default interpreter:

    screenshot

Optionals

  1. Guake

    1. Uncheck "Show tab bar", since you will use Byobu for that:
      image
    2. If a shortcut doesn't work try disabling Guake ones that might interfere (in my case was Ctrl+F2 for vertical split): screenshot
  2. Byobu

    1. Learn shortcuts with Shift+F1 or this excellent screencast.
    2. Learn available byobu terminal commands with apropos byobu
    3. To use Fn keys on Midnight Commander use Alt+ ,or Shift+F12 to disable byobu F-keys.

screenshot

  • For even more happiness use zsh with oh-my-zsh and
  • Test your terminal setup with this test drive (pretty bad for alacritty :( ).
  • I changed local byobu/tmux escape sequence (F9) to Ctrl + h so it doesn't interfere with tmux on a remote server.
Pablo A
  • 2,712
2

Vim can also be used as a rough terminal multiplexer:

:terminal opens a horizontial split terminal,
:vertical terminal opens a vertical split terminal.

As always the commands can be assigned to keyboard shortcuts.

Krackout
  • 2,642
  • 12
  • 26
2

Try Vertical Split for GNU Screen

This patch provides a vertical split feature for current releases of GNU Screen. The feature is designed to function in the same manner as screen's existing split command, but dividing the regions vertically instead of horizontally. Both forms of splits can be used together in any combination/quantity/order desired. Something similar is slated to appear in GNU Screen 4.1 soon, and is already available in CVS per this mailing list thread (and has been included in the Debian and Ubuntu screen packages starting with 4.0.3-10). Also, a recent project named ScreenWM is designed specifically to work with a vsplit-patched screen (check it out!).

Narga
  • 39
  • 2