Narrow centered single frame in tmux - tmux

Writing prose in a console environment I like to have my editor in a narrow centered pane. I can achieve this with this .screenrc:
focusminsize 75 25
split -v
focus
only
split -v
split -v
focus
caption string "%{= dd} "
sorendition "="
Then $screen emacs gives me the desired layout.
How do I achieve something similar in tmux 1.8?
Bonus: how to I bind toggling 'default layout' / 'narrow centered single pane' to a key?

Related

How to resize a pane to occupy a certain percentage of a whole tmux window?

I recently started to use tmux and likes it a lot. I'd like to know how to set the size of my panes using percentage. For example, there are 3 panels in a row, and I'd like to set the 1 pane to occupy 20% of the window width, and the other 2 panes each occupy 40% of the window width. But so far, I could only find commands below.
Ctrl+B Alt+Arrow
- Resize the active pane
resize-pane -R 20
- Resizes the pane right by 20 cells
Any better ways to do it?
There is no -p flag for resize-pane, which is what you are really after, although it has been on the todo list for a while. Instead you will need to use -x or -y and work out the sizes yourself, for example a shell script like:
W=$(tmux display -p '#{window_width}')
L=$(expr $W \* 2 / 10)
R=$(expr $W \* 4 / 10)
tmux resizep -t{left} -x $L
tmux resizep -t{right} -x $R
Another alternative would be to set up a layout like you want then get the layout string (you can see it in "tmux lsw"), then you can reapply it to a different window with the same number of panes using "tmux selectl ...").

how to move Tmux panes

I like to work with 3 tmux panes. one horizontal pane at the upper half of the screen and two more panes at the bottom half. These panes are split vertically.
There are cases where I would like to take the last pane and make it go from top to bottom. like this:
How can I achieve this? using [ctrl+b ctrl+o] and [ctrl+b space] did not reach the desired position and is cumbersome.
There is probably an easier way, but what you can do is arrange the panes manually in each of the two configurations, noting each layout in a variable with e.g.:
layout1=$(tmux list-windows -F '#{window_layout}')
This holds a string something like:
5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]
which you must not alter in any way as the first number is a checksum of the rest of the string.
Once you have the two strings you can set a binding to set that layout using select-layout, or by giving the command from the shell where you have the variables:
tmux select-layout "$layout1"
You might find it easier to write a small helper script, say mtmux to toggle between the layouts:
#!/usr/bin/bash
# https://stackoverflow.com/q/56343223/5008284
# toggle between 2 layouts, previously saved
layout1='5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]'
layout2='093c,80x23,0,0{39x23,0,0[39x11,0,0,0,39x11,0,12,4],40x23,40,0,3}'
layout="$(tmux list-windows -F '#{window_layout}')"
case "$layout" in
*80x11*) new=$layout2 ;;
*) new=$layout1 ;;
esac
tmux select-layout "$new"
tmux display-panes
exit 0
and have a binding, say control-L, to run this shell:
bind-key -n C-l run-shell 'mtmux'

clear terminal screen but keep visual spacing

When I want to provide a visual break after a long list of output lines from a command I normally run clear so that the terminal will clear the screen, put my prompt back at 0,0 while also keeping the history (vs reset).
The problem is that when I scroll up, the terminal is now back to the long lines of output, without any kind of break in history.
I had the idea of "echo'ing a screen's worth of empty lines" by doing yes '' | head -n $(tput lines), but then my cursor is at the bottom of the screen. So I try to run clear but it seems to remove the empty lines. I also tried tput cup 0 0 but that also removes the empty lines (I guess by "reverting" my screen's worth of empty lines).
I can force the empty lines by printing any character with yes instead of the empty string, or I can print some character/message at the end of the empty lines. But now I'm adding garbage.
The only thing I've been able to get to work is:
yes '' | head -n $(($(tput lines) * 2))
tput cup 0 0
Is there another way or is this my only option?
Essentially yes - you can express the script in various ways, but most terminals don't allow one aspect which could be used to improve your script: when scrolling up, they don't move blank lines into the scrollbar. So you can't (for example) do it like this:
tput cup $(tput lines)
tput indn $(($(tput lines) * 2))
tput cup 0 0
tput ed
since the blank lines that you would expect from indn (index) are ignored.

why the split line of tmux within putty shows different(xxxxx, qqqqqq)in these tow cases?

Why the split line of tmux within PuTTY shows different(xxxxx, qqqqqq)in these tow cases?
If I do not set PuTTY any thing(the default "Use font encoding"), the split line of pane shows like following:
But it can't show Chinese word correctly, so I set PuTTY's Window -> Translation -> Remote character set to UTF-8. Then the split line of pane become to like that:
Using “xxx qqqq” seems very ugly.
BTW: echo $LANG shows “zh_CN.UTF-8”
So, in this case, How to show Chinese word correctly with the first split line?
I had the same problem with Putty with character set set to UTF-8.
Launching tmux with -u option did the trick (tmux -u)
I was having the same issue except I was not trying to display Chinese characters. For the ugly line break ( xxxx qqqq), take a look at Tmux borders displayed as x q instead of lines?. For me, there are two version of tmux installed and switching to the newer version solves the problem. You may want to upgrade your tmux. Hope it helps.

tmux man-page search highlighting

When I search in, for example, man ls while in a tmux session, the search strings don't appear highlighted - the page jumps down so that the search string is on the top line of the buffer, as expected, but it's not highlighted.
Doing the same thing in the same shell while not in a tmux session results in highlighted search strings.
I have no idea where to start looking to solve this. Any hints are appreciated.
Based on Less Colors For Man Pages by Gen2ly, here is my man page and how to do it:
Preview
This is a shell, not a web page !
How to
(optional) I'm using Tomorrow theme for Konsole/Yakuake ;
Edit your ~/.bashrc ~/.zshrc, etc. to add :
# Colored man pages: http://linuxtidbits.wordpress.com/2009/03/23/less-colors-for-man-pages/
# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;016m\E[48;5;220m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
Reload your config and try a man page search :
. ~/.bashrc && man ls
Fixed it. The problem is to do with the way that the screen $TERM handles italics. From the tmux FAQ:
vim displays reverse video instead of italics, while less displays italics
(or just regular text) instead of reverse. What's wrong?
This matches my problem exactly. The $PAGER used by man is less by default - basically, man uses less to show the contents of the manual pages. In my case, less wasn't highlighting text, just showing regular text.
The reason for this happening:
Screen's terminfo description lacks italics mode and has standout mode in its
place, but using the same escape sequence that urxvt uses for italics. This
means applications (like vim) looking for italics will not find it and might
turn to reverse in its place, while applications (like less) asking for
standout will end up with italics instead of reverse.
The solution is to make a new terminfo file for tmux, which lets it know that italics are supported. The solution's outlined in the (at time of writing) very, very bottom of the tmux FAQ.
After creating the new terminfo file, in tmux: C-b :source-file /absolute/path/to/.tmux.conf (from this SuperUser question) - this should make tmux reload the .tmux.conf file. However, this didn't work for me, and the changes only applied after restarting the tmux server (close all tmux sessions, then re-open them).
This thread is a few years old but is still the one that comes up as the best search result, so I'm answering with what finally worked for me. This is based off of tmux FAQ.
...but the instructions aren't completely clear on when or where to substitute the -256color string. I use gnome-terminal (v 3.16.2) with tmux, and this worked for me:
$ mkdir $HOME/.terminfo/
$ screen_terminfo="screen-256color"
$ infocmp "$screen_terminfo" | sed \
-e 's/^screen[^|]*|[^,]*,/screen-256color|screen with italics support,/' \
-e 's/%?%p1%t;3%/%?%p1%t;7%/' \
-e 's/smso=[^,]*,/smso=\\E[7m,/' \
-e 's/rmso=[^,]*,/rmso=\\E[27m,/' \
-e '$s/$/ sitm=\\E[3m, ritm=\\E[23m,/' > /tmp/screen.terminfo
$ tic /tmp/screen.terminfo
And tell tmux to use it in ~/.tmux.conf:
set -g default-terminal "screen-256color"
Note: I tried it once without the -256color and since that didn't work (still seeing italics instead of highlighting), I had to delete everything under the .terminfo dir (another dir called 's') before the infocmp would work.

Resources