VS Code Terminal Won't Map Option Key to Meta - terminal

I am trying to enable the option/alt key as Meta in my terminal in VS Code. I set the "terminal.integrated.macOptionIsMeta": true in my settings.json but it is not working.
I made this same change to my system Terminal app and iTerm2.
iTerm is the only one that works. In iTerm the option key is mapped to Meta but not in the VS Code terminal or Terminal.
Does anyone know why this could be or how to correct it?
OS X 10.15.7
VS Code Version: 1.63.2
iTerm2 Build 3.4.12
Terminal Version 2.10 (433)
VS Code
iTerm2
Terminal

This appears to be an issue with how OS X handles tmux-keyboard integration, not VS Code.
The relationship between Option/Alt and Esc/Meta does not work well. Even if this feature is enabled in your terminal emulator. Consequently, when binding the Meta+ to an action in .tmux.conf the resulting behavior is not as expected.
bind -n M-j select-pane -L
bind -n M-k ​select-pane -R
Alt+j and Alt+k work as expected.
However, when binding the Meta+[DirectionKey]:
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
Alt+Left and Alt+Right do NOT work and you need to use Esc+Left and Esc+Right.

Related

Invalid options in tmux without custom configuration

I just installed tmux 3.1c on my Mac and have not created any custom configuration(neither ~/.tmux.conf nor ~/.config/tmux/tmux.conf exists)
When I run tmux in both native Terminal and in iTerm2 I am getting the following errors printed in the top of the screen
invalid option: pane-active-border-bg
invalid option: pane-border-bg
I am using zsh with oh-my-zsh plugin but have not found anything that could try to set those options.
Are there any ideas on how to fix that issue?
You can search the manual and you search for "pane-border-style", so the new way is like this:
set -g pane-border-style fg=red

System default voice doesn't change on `say` command within tmux sessions

Recently I've changed my default system voice via "System Preferences > Dictation & Speech > Text to Speech > System Voice". If I open a new Terminal window and use the say command, the correct voice is used. However, the previous voice is still used if I use the say command within a tmux session.
I've tried restarting, shutting down tmux completely, and opening an entirely new tmux session with tmux new-session -s foobar and still it doesn't pick up the new preferred voice.
This is really a minor issue, but it eats at me that I have no idea why it's happening. Any ideas?
I'm pretty sure this is the same root cause as that other issue: many tools that need to interact with the UI (graphics, sounds...) fail within a tmux session: say, pbcopy/pbpaste, nohup, launchctl export|getenv|setenv, subl (Sublime Text command line tool), Retina rendering of apps launched under tmux, tools trying to access KeyChain (curl, ssh...), etc.
I remember GNU screen used to have the same problem but Apple patched it and now it works fine, but tmux still has the problem.
Solution (2017-05)
Borrowing from answers in linked issue, for tmux you can do this if you have Homebrew:
brew install reattach-to-user-namespace
Then put the following in your ~/.tmux.conf:
set-option -g default-command "reattach-to-user-namespace -l $SHELL"
I reproduced your issue on macOS 10.11.4, and the above fixed it.
See here for more info on the nature of the problem, and its workaround (using undocumented macOS APIs)
Better solution soon?
As mentioned in comment, future versions of tmux might do this dance natively, at least it's being worked on, and current master has the fix.

tmux is not using screen-256color even it is set in the config file

I am trying to get tmux to use screen-256color instead of xterm-256color, as it is not recommended. But when I am not using tmux, I would like to keep it as xterm-256color
A little bit of my setup, I am currently using iTerm2 and ssh to my development linux box, which is using zsh.
In my ~/.zshrc, I have:
export TERM="xterm-256color"
In my ~/.tmux.conf, I have:
set -g default-terminal "screen-256color"
With this configuraiton, without tmux, echo $TERM returns xterm-256color (which is right) and with tmux, echo $TERM is still returning xterm-256color instead of screen-256color.
Is there anything else I need to set in order for this to work?
Thanks!
The reason this does not work as expected is, that the zsh session that is started inside tmux overwrites TERM.
You should not set TERM from within in your shell. TERM is the way the terminal informs the shell and other applications about its capabilities (number of colors, key sequences for special keys, etc.). If you change TERM inside the shell, you change the what features the shell and applications expect from the terminal without the terminal itself knowing about it. Oftentimes this may not be an actual issue, but it is better to change the terminal configuration and set the desired value there.
You already did so when setting screen-256color in the configuration of tmux, which is essentially a terminal emulator, too. To do it for iTerm2 (tested with version 3.0.10):
Open the Preferences dialog (in the Menu: iTerm2 → Preferences, or press ⌘+,).
In the dialog go to Profiles → Terminal.
There you can choose the desired value for TERM under Report Terminal Type.
You could modify your .zshrc file to check if you are running in tmux:
[ -z "$TMUX" ] && export TERM=xterm-256color

Cannot get delete key to work with tmux and OSX

On OSX with tmux installed through homebrew I cannot seem to get my 'delete' key to work. I am using iterm2 and have my delete mapped to ^H. Without tmux the 'delete' key works fine.
To fix backspace on Apple M1 Pro OSX 12.4, tmux 3.3a
I had to do the following
brew install ncurses
$(brew --prefix)/opt/ncurses/bin/infocmp tmux-256color > ~/tmux-256color.info
tic -xe tmux-256color ~/tmux-256color.info
#https://github.com/tmux/tmux/issues/1257#issuecomment-581378716
#https://gist.github.com/bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95
This might be some terminal emulation issue within your shell.
When you are in a tmux session, enter the following in the bash prompt and see if it works:
stty erase ^H
If this helps, check your terminal tty settings.
What worked for me is adding this to .tmux.conf.
# apps should know that this is 'screen' and not xterm. Slight compatibility
# reasons. tmux should be running in xterm-256colors, and set TERM so that
# applications within tmux see screen-256colors tmux does not support -bce
# (background color erase)
set -g default-terminal 'screen-256color'
I came across this and I found a solution for me.
Tmux uses ^? for delete. stty was not sending ^?.
I changed that using stty erase '^?' and then changed my preferences in iTerm2 for delete to send ^?
https://github.com/tmux/tmux/issues/335
I'm a few years late, but for me the problem was my $TERM setting ... changed it to screen-256color and that did the trick
Better solution here: https://gist.github.com/bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95

Multiple tabs with tmux / tmuxinator and iTerm2

I would like to open all my useful stuff like here in iTerm2:
Not like this:
I'm using tmuxinator I've defined some tabs. I wonder if it's possible to get the former behaviour at all.
I just tried with tmux 1.8. Not totally obvious, but it works.
Here's what you do:
Open iTerm2 (latest, be sure to have at least tmux 1.8 installed).
In iTerm2, run command tmux <your tmuxinator profile>. Then detach ^b d.
In iTerm2, run command tmux -CC attach -t <your session>. You will see your tabs open in different windows.
Open menu Shell->Tmux->Dashboard
Select and hide all the windows.
Select all the hidden windows, and click Open in Tabs.
I'd like to know how to avoid the part about hiding and opening in tabs.
Just wanted to add some comments onto what justingordon mentioned (1).
This all works great. But I found how to streamline step 4-6 so it happens automatically.
Go to iTerm2's Preferences, under General, you will see a section titled tmux. There's an option that says When attaching, open unrecognized windows in. If you change the current selection from Windows to Tabs.
Two extra tips.
If you want you could select the option Automatically hide the tmux client session after connection. This will minimize the iTerm2 window in which you typed
tmux -CC attach
I also enabled the option Focus follows mouse. You can find this option under Preferences then Pointer. It should be the first option on the bottom left.
To use tmuxinator with iterm2 panes, use the following configuration:
attach: false
in combination with
on_project_exit:
- tmux -CC attach -t way
It looks like an issue in the documentations as told here
This is an example that I normally use:
# ~/.tmuxinator/way.yml
name: way
root: ~/learn/ruby/ruby-way/
attach: false
on_project_exit:
- tmux -CC attach -t way
# Runs before everything. Use it to start daemons etc.
on_project_start:
- export EDITOR="emacsclient --server-file=way -c"
- export VISUAL=$EDITOR
- emacs --daemon=way --title=RUBY-WAY
- $EDITOR &
windows:
- console:
- echo "A currar"
- testing:
- echo "A testear"
I hope that this helps.
Add this to your tmuxinator config:
attach: false
post: tmux -CC attach
https://github.com/tmuxinator/tmuxinator/pull/293

Resources