TMUX borders are broken iTerm2 - vim

I am currently using iTerm2, AMIX Vim, and Tmuxline (which includes vim airline).
When Splitting panes, borders looks bad both horizontally and vertically (the borders only go half-way and are dashes). I have disabled the "Treat Ambiguous characters as double width", but that doesn't fix it.
My Tmux config:
# unbind some default keybindings
unbind C-b
# set prefix key to ctrl-g
set -g prefix C-g
# lower command delay
set -sg escape-time 1
# start first window and pane at 1, not zero
set -g base-index 1
set -g pane-base-index 1
# bind r to reloading the config file
bind r source-file ~/.tmux.conf \; display "Reloaded tmux config file."
# pass through a ctrl-a if you press it twice
bind C-a send-prefix
# better mnemonics for splitting panes!
bind \ split-window -h
bind - split-window -v
# vim / xmonad style bindings for pane movement
bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R
# vim / xmonad style bindings for window movement
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
# shift-movement keys will resize panes
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# disable mouse support (at least while we're learning)
setw -g mode-mouse off
set -g mouse-select-pane off
set -g mouse-resize-pane off
set -g mouse-select-window off
# turn on 256 color support in tmux
set -g default-terminal "screen-256color"
# fiddle with colors of status bar
set -g status-fg white
set -g status-bg colour234
# fiddle with colors of inactive windows
setw -g window-status-fg cyan
setw -g window-status-bg colour234
setw -g window-status-attr dim
# change color of active window
setw -g window-status-current-fg white
setw -g window-status-current-bg colour88
setw -g window-status-current-attr bright
# set color of regular and active panes
set -g pane-border-fg colour238
set -g pane-border-bg default
set -g pane-active-border-fg green
set -g pane-active-border-bg default
# set color of command line
set -g message-fg white
set -g message-bg colour22
set -g message-attr bright
# configure contents of status bar
set -g status-utf8 on
set -g status-left-length 40
set -g status-left "#[fg=green]\"#S\""
set -g status-right "#[fg=green] #h | %d %b %R"
set -g status-justify centre
setw -g monitor-activity on
set -g visual-activity on
# navigate using vim-style keys
setw -g mode-keys vi
# copy/paste using vim-style keys
bind Escape copy-mode
unbind p
bind p paste-buffer
bind -t vi-copy 'v' begin-selection
bind -t vi-copy 'y' copy-selection
# xclip support (commented as this often doesn't make sense on remote servers)
#bind C-c run "tmux save-buffer - / xclip -i -sel clipboard"
#bind C-v run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"
# set up aliases for temporarily maximizing panes
unbind Up
bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp
# set up alias for turning on logging
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"
#source-file .tmuxline.conf
My Tmuxline Config:
# This tmux statusbar config was created by tmuxline.vim
# on Fri, 12 Jun 2015
set -g status-bg "colour0"
set -g message-command-fg "colour10"
set -g status-justify "left"
set -g status-left-length "100"
set -g status "on"
set -g pane-active-border-fg "colour4"
set -g message-bg "colour8"
set -g status-right-length "100"
set -g status-right-attr "none"
set -g message-fg "colour10"
set -g message-command-bg "colour8"
set -g status-attr "none"
set -g status-utf8 "on"
set -g pane-border-fg "colour8"
set -g status-left-attr "none"
setw -g window-status-fg "colour12"
setw -g window-status-attr "none"
setw -g window-status-activity-bg "colour0"
setw -g window-status-activity-attr "none"
setw -g window-status-activity-fg "colour4"
setw -g window-status-separator ""
setw -g window-status-bg "colour0"
set -g status-left "#[fg=colour0,bg=colour4,bold] #S #[fg=colour4,bg=colour0,nobold,nounderscore,noitalics]"
set -g status-right "#[fg=colour8,bg=colour0,nobold,nounderscore,noitalics]#[fg=colour10,bg=colour8] %Y-%m-%d  %H:%M #[fg=colour4,bg=colour8,nobold,nounderscore,noitalics]#[fg=colour0,bg=colour4] #h "
setw -g window-status-format "#[fg=colour12,bg=colour0] #I #[fg=colour12,bg=colour0] #W "
setw -g window-status-current-format "#[fg=colour0,bg=colour8,nobold,nounderscore,noitalics]#[fg=colour10,bg=colour8] #I #[fg=colour10,bg=colour8] #W #[fg=colour8,bg=colour0,nobold,nounderscore,noitalics]"

The border going half way down is because it is rendering the top half with your pane-border-fg color. You might check your iterm2 settings to ensure that it is reporting the terminal type xterm-256color. You could also try changing your pane-border-fg color to be one of the standard colors.

Related

Tmux Stack based behaviour (like dwm)

Hi I use tmux at work on Windows Subsystem for Linux and have it set up to behave like a
stack based tiling window manager. i.e the main window is the leftmost vertical one, the first
new window I open does a vertical split pane, and each subsequent window I open is a horizontal
split in the 2nd vertical pane.
Here is my tmux.conf:
## Unbind some default keys
unbind-key C-b
## Set tmux options
# Replace with Ctrl+Space
set-option -g prefix C-Space
set-option -g default-command bash
# This fixes the weird prompt issue
set -g default-terminal "xterm-256color"
## Custom Keybinds
# C-j moves to next pane, C-k moves to prev pane
bind-key -n C-j select-pane -t :.+
bind-key -n C-k select-pane -t :.-
# TODO: Set h and l to increase and decrease length of pane
bind-key -n C-h resize-pane -L 5
bind-key -n C-l resize-pane -R 5
bind-key -n C-n split-window -b
# Swap current pane with currently active pane
bind-key -n C-s swap-pane -s "$TMUX_PANE" -t 0
## TO SHOW ALL TMUX KEYBINDS
# tmux list-keys
I also remote in a red hat linux machine, however when I use this tmux.conf on the linux
machine every new window is a vertical split.
Does anyone have any idea why this discrepancy exists and/or how I could remedy it?
(Note: I am using the tmux.deb from the official repos on the WSL machine, while I am using the latest appimage provided on the tmux/tmux github on the red hat linux server).

How do I add nvim to update-alternatives when using snap under Ubuntu

I'd like to add nvim (a snap) to update-alternatives. The problem is that snap seems to work in mysterious ways when determining which program to run:
$ sudo update-alternatives --install /usr/bin/vim vim /snap/bin/nvim 60
$ vim # works
$ vim hello.txt
error: unknown command "hello.txt", see 'snap help'.
If I look at /snap/bin/nvim it is a link to /usr/bin/snap:
$ ls -lah /snap/bin/nvim
lrwxrwxrwx 1 root root 13 Jan 25 15:02 /snap/bin/nvim -> /usr/bin/snap
But how does the snap executable determine it needs to run nvim
In order to use it like that you have to create a script that starts nvim like this:
#!/usr/bin/env bash
/usr/bin/snap run nvim ${#}
Lets say you call it nvim_start.sh. Now you can use this script in your update-alternatives commands (remember to enable the execution flag):
CUSTOM_NVIM_PATH=/usr/bin/nvim_start.sh
sudo chmod +x "${CUSTOM_NVIM_PATH}"
set -u
sudo update-alternatives --install /usr/bin/ex ex "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/vi vi "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/view view "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/vim vim "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/vimdiff vimdiff "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --set ex "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set vi "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set view "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set vim "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set vimdiff "${CUSTOM_NVIM_PATH}"
I'm not sure why using /snap/bin/nvim does not work, even when called from inside the script. At least the workaround works OK.

TMUX status line disappear while scrolling in VIM

Whenever I scroll in VIM, the tmux status line quickly disappear and reappear. What could I do to solve this issue? If I scroll fast outside of VIM or cat a big file, I don't have this issue.
My tmux.conf file:
# Nakrule TMUX configuration
###### PREFERENCES
## Lower the default tmux delay, this makes tmux more responsive.
set -s escape-time 1
# Enable mouse movements.
setw -g mouse on
# Make tmux use 256 colors. Required for VIM to work in 256 colors mode.
set -g default-terminal "screen-256color"
# Make tmux act like xterm to prevent Vim issues:
set -g terminal-overrides 'xterm*:smcup#:rmcup#'
# Only resize the screen size if the smaller screen user has their window
# active. This way my screen won't be resized to an incredibly small window
# unnecessarily.
setw -g aggressive-resize on
# Store a lot of history.
set -g history-limit 10000
# Automatically renumber tmux windows
set-option -g renumber-windows on
# Update status bar every minute
set-option -g status-interval 1
# Enable RGB colour if running in xterm(1)
set-option -sa terminal-overrides ",xterm*:Tc"
# Make pane index start with 1
set-option -g base-index 1
# The window (GUI) title of the terminal will be based on the curent tmux window
set-option -g set-titles on
set-option -g set-titles-string "#T - #W"
# No delay for ESC key
set-option -sg escape-time 0
# Window titles
set-window-option -g window-status-format "#I #W"
set-window-option -g window-status-current-format "#I #W"
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
set-window-option -g aggressive-resize on
# Make window index start with 1
set-window-option -g pane-base-index 1
## VIM mode
set-window-option -g mode-keys vi
############################### MAPPINGS ###############################
# PREFIX r: Instantly reload tmux's configuration file.
bind r source-file ~/.tmux.conf \; display "tmux has been reloaded!"
# PREFIX /: Create a new vertial pane in the same directory.
bind / split-window -h -c "#{pane_current_path}"
# PREFIX -: Create a new horizontal pane in the same directory.
bind - split-window -v -c "#{pane_current_path}"
# Use Vim movement key mappings for switching around between panes.
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Use Vim movement key mappings (uppercase) for resizing panes.
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# Can use 'v' and 'y' instead of Enter and Space to select and copy text after CTRL B + [ (like VIM)
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
##### macOS only, configure text selection and copy with the mouse.
# From this link (Linux solution available here as well):
# https://unix.stackexchange.com/questions/318281/how-to-copy-and-paste-with-a-mouse-with-tmux/318285#318285
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft='#{pane_in_mode}''send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow, once you release left click yellow text
# will disappear and will automatically be available in clibboard.
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"
### APPEARANCE
# Status update interval
set -g status-interval 1
# Basic status bar colors
set -g status-style bg=black,fg=yellow
# Left side of status bar
set -g status-left-style bg=black,fg=green
set -g status-left-length 40
set -g status-left "#S #[fg=white]» #[fg=yellow]#I #[fg=cyan]#P"
# Right side of status bar
set -g status-right-style bg=black,fg=cyan
set -g status-right-length 40
set -g status-right "#H #[fg=white]« #[fg=yellow]%H:%M:%S #[fg=green]%d-%b-%y"
# Window status
set -g window-status-format " #I:#W#F "
set -g window-status-current-format " #I:#W#F "
# Current window status
set -g window-status-current-style bg=red,fg=white
# Window with activity status
set -g window-status-activity-style bg=black,fg=yellow
# Window separator
set -g window-status-separator ""
# Window status alignment
set -g status-justify centre
# Pane border
set -g pane-border-style bg=default,fg=default
# Active pane border
set -g pane-active-border-style bg=default,fg=green
# Pane number indicator
set -g display-panes-colour default
set -g display-panes-active-colour default
# Clock mode
set -g clock-mode-colour red
set -g clock-mode-style 24
# Message
set -g message-style bg=default,fg=default
# Command message
set -g message-command-style bg=default,fg=default
# Mode
set -g mode-style bg=red,fg=default
The problem is from the following configuration:
# Make tmux act like xterm to prevent Vim issues:
set -g terminal-overrides 'xterm*:smcup#:rmcup#'
Deleting it solve it.

How to run python file inside tmux session?

I am trying to run python script inside tmux session. I wrote a command (tmux new-session -d -s my_session) which is running fine from crontab.
But when I am trying to run python or shell file with tmux new-session -d -s my_session 'python3 test.py or tmux new-session -d -s my_session 'sh test.sh
The script doesn't run. I used the reference from here.
Please help me with this.
Edit
You can separate tmux commands with \;, then use the send-keys command to send the command to the active window.
In your case you can use:
tmux new-session -d -s my_session \; send-keys "python3 test.py" Enter
tmux new-session -d -s my_session \; send-keys "sh test.sh" Enter
tmux new-session -d -s my_session \; send-keys "python3 -m http.server 8080" Enter
You can find more about send-keys options on the tmux manpages section for send-keys:
send-keys [-lMRX] [-N repeat-count] [-t target-pane] key ...
(alias: send)
Send a key or keys to a window. Each argument key is the name of the key (such as ‘C-a’ or ‘NPage’) to send; if the string is not recognised as a key, it is sent as a series of characters. The -l flag disables key name lookup and sends the keys literally. All arguments are sent sequentially from first to last. The -R flag causes the terminal state to be reset.
-M passes through a mouse event (only valid if bound to a mouse key binding, see MOUSE SUPPORT).
-X is used to send a command into copy mode - see the WINDOWS AND PANES section.
-N specifies a repeat count.
The send-keys syntax is described on the Key Bindings section of the tmux manpage. The key names used by send-keys are the same ones used by bind-key.
I usually work with different configuration files, on top of a base file.
Imagine that you've your tmux configuration in ~/.tmux.conf I then create different configuration files in my ~/.tmux/ folder. As an example I can have a python configuration file (use the attach if you want to enter in the session):
# To use this configuration launch tmux with the command:
# > tmux -f ~/.tmux/python.conf attach
#
# Load default tmux config
source-file ~/.tmux.conf
# Create session and launch python script
new-session -s python -n python -d -c ~/src/python/
send-keys "python test.py" Enter
This gives me the flexibility to create much more complex sessions.

"set-window-option -g mode-keys vi" doesn't work in .tmux.conf

I've been able to turn-on the vi-mode inside tmux successfully by pressing C-a : (I've changed default prefix) and then typing set-window-option mode-keys vi. However, I can't make it stick by adding into ~/.tmux.conf. Here is my config:
# Change default prefix key to C-a
unbind-key C-b
set -g prefix 'C-a'
bind-key 'C-a' send-prefix
# Configure Vim mode for navigating text and selection
set-window-option -g mode-keys vi
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
# Allow navigating panes with vi-like commands.
bind k selectp -U
bind j selectp -D
bind h selectp -L
bind l selectp -R
Notably, navigating panes using kjhl keys also doesn't work. Perhaps this is because tmux fails to execute set-window-option earlier in the script. What's wrong here?
Try using setw -g mode-keys vi
"set-window-option -g mode-keys vi" works in tmux 2.1 and above.
"setw -g mode-keys vi" works in tmux 1.8
Note that
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
will no longer work as of tmux 2.4. For the same functionality (using xclip for copying), instead use
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "xclip -in -selection clipboard"
from this blog post
Another thing that may affect this: tmux turns on vi keys for copy mode only if it finds 'vi' in $VISUAL or $EDITOR. I had changed both to use neovim remote tool (nvr -ls) and suddenly tmux copy keys I had bound in copy-mode-vi stopped working because it defaulted back to using emacs keybindings. Check that your $VISUAL and EDITOR contains some version of the string 'vi'.

Resources