I would like to give to you a bunch of tips about how to improve your work with console. If you are working remotely on Linux from Windows operating system then there it is hard to find a right solution. I will describe a few tweaks which make the work with Linux terminal on Windows a bit easier.
This post will manly focus on configuring a cmder terminal — a great tool for consoling on Windows. Also I will discuss screen which is nice application similar to tmux which allows you to have a bunch of virtual terminals open and ready for use.
As I have written above, Cmder is a great tool which is a virtual console. It can be configured with a bunch of different shells: git bash, cmd, PowerShell, bash over WSL, and more. However, if you already know the tool you know it is great. However, there is still some more room to improve it. For once, wouldn’t it be nice to have panel that could be splited? The feature is already available in the application but not enabled by default. Probably, you know this feature from Linux GUI terminal called Terminator. When you press Ctrl+Shift+E it splits the panel in two vertically. It is great to have to windows side by side. Also it allows you to split it horizontally with Ctrl+Shift+O. What is more you can move around from one panel to an another with shortcuts, like Alt+Arrow depending where you would like to move. This feature is available in Cmder and here it is how to configure it.
Click on the title bar and go to Settings -> Keys & Macro and in the search box type in split. You should see a similar window to the one below
Notice following descriptions for splinting the panel
- Split: Duplicate active ‘shell’ split to bottom: Split(0,0,50)
- Split: Duplicate active ‘shell’ split to right: Split(0,50,0)
These commands allow to split the screen horizontally and vertically. Also it is possible to move around — change panels. This can be done using Alt + arrow keys. This can be adjusted in the same window under Split: Put focus to nearest panel upward/downward/leftward/rightward.
However, one thing can be a bit frustrating. Whenever you hover your mouse over a panel it gets focused on. It can lead to typing in a wrong shell out of the blue. Fortunately, this can be disabled in configuration menu. An example was shown below.
You have to deactivate Activate split/panel on mouse hover and that’s that! No more accidental typing in a wrong shell.
This application can setup virtual terminals. This is particularly useful when you login to a server via SSH and want to have access to multiple shells. I will describe some tweaks which come in handy.
A new terminal is created by pressing Ctrl+a and then c (‘c’ for create). When you open multiple number of terminals you can switch between them with number keys preceded by Ctrl+a. To display a list of open shells just press Ctrl+a and “ (quotation mark). However, this is rather laborious and you have keep tabs on terminals. There are two ways of solving with this unfortunate problem:
- use key bindings to change shells instead of Ctrl+a and numeric key combination,
- split window and the use key bindings to jump from one view to an another.
Splitting window in screen
To split window vertically you can use Ctrl+a and then | (vertical line, pipe). To split window horizontally use Ctrl+a and S (capital s).
As you can see in above Figure the screen’s window has been divided into three panels. Now, to move around you would go with following shortcuts:
- Ctrl+a n for moving to the next windows,
- Ctrl+a p to move focus to the previous window.
This works but is not very efficient. It is better to configure key bindings in .screenrc file and use those. To do this enter following two lines in the mentioned file
# for shift up and down arrows bindkey ^[[1;2A focus bindkey ^[[1;2A focus
Above will link Shift + up/down arrow with changing focus forward/backward. It is much easier to jump through all open panels. Remember to reload the .screenrc file. This can be done with Ctrl+a and then type in :source /path/to/screenrc and press Enter.
Sometimes it is more efficient to switch panels in a window instead of having multiple windows open in screen terminal. To do this also a bit of editing of screen’s configuration file is needed.
# for shift right and left arrows bindkey ^[[1;2D prev bindkey ^[[1;2C next
Some useful screen shortcuts to move around screen windows and create or destroy new ones:
- Ctrl+a X (capital x) closes the panel that has focus,
- Ctrl+a d detaches screen from the TTY and put it in the background,
- Ctrl+a n and Ctrl+a p moves focus to the next and previous window,
- Ctrl+a “ (quotation mark) show list of available windows during this session.
As you can see there are multiple ways to work conveniently. Nothing stops you from combining these two solutions — Cmder and screen. Sometimes when you work with a remote server and have no access to Cmder a properly configure screen can still make the work easier. To sum up, not all features were covered by me feel free to tinker around and improve proposed solution.
If you would like to ask about something, feel free to leave a comment.