RedBearAK / toshy

Keymapper config to make Linux work like a 'Tosh!
https://toshy.app
GNU General Public License v3.0
358 stars 17 forks source link

(Question) VSCode key_bindings for the terminal + TMUX #373

Closed raraz15 closed 2 months ago

raraz15 commented 2 months ago

Some of the key bindings in (https://github.com/RedBearAK/toshy/wiki/Embedded-terminal-in-VSCode-and-variants) do not work as intended. In general, my confusion is related to how the cmd and ctrl keys are changed with the recommended key binding. I would like to be able to use VSCode, its integrated terminal, and tmux in a linux machine with my apple keyboard as I was using them on my MacOS machine with the same keyboard.

I tried some of the recommendations and took notes on their behavior.

Working: cmd+b: toggles the sidebar after adding "terminal.integrated.commandsToSkipShell": [ "workbench.action.toggleSidebarVisibility" ]

Does not work:

// Send the Ctrl+C/SIGINT interrupt sequence in terminal with Ctrl+C Instead, the terminal tries to copy the text.

// Clear screen in terminal with Cmd+L Isn't this supposed to be "key": "meta+l",?

// Delete word left of cursor in terminal (Ctrl+W sequence) ctrl+w does not work but cmd+w works.

Also, when I use tmux inside the vscode's integrated terminal, ctrl+b prefix does not work. How can we change this?

RedBearAK commented 2 months ago

@raraz15

Unfortunately there is very little that can really be done to fix any embedded terminal in any non-terminal app in Linux. As the Wiki page explains, the keymapper only has two pieces of information about each window. The "application class" identifier, which is the same thing that "docks" use to group all the windows of the same "application" under a single icon. And the window title, which can change frequently and is not necessarily that useful in many cases.

In a non-terminal app, the keys are Super - Alt - Control_R. Therefore to get the usual Ctrl+C/SIGINT you have to remap the Super key that lives on the physical Ctrl key.

On the other hand, any app that is in the "terminals" list gets treated differently. They keys are Control_L - Alt - Control_R, and we can distinguish between left and right Ctrl, so it usually works out pretty well. But the whole application either needs to be a terminal or a "GUI" app (a non-terminal).

There is never going to be a perfect solution for a lot of this, simply because of the way the config has to move modifiers around to mimic macOS shortcuts.

You can pick another command prefix combo for tmux. But I would highly advise you to just use a separate terminal app to avoid all the redirecting of the remapped modifiers. The reason it isn't working is that Cmd+B is actually Ctrl+B, so that's now being captured by the change you made to get Cmd+B working. Undo that, and you'll have Ctrl+B back in the embedded terminal.

However I don't know why the Ctrl+C fix wouldn't be working. It's changing the Meta+C shortcut that results after Toshy remaps modifiers, back to being Ctrl+C. Works in my VSCode embedded terminal. As does the Cmd+Dot shortcut.

The "clear" shortcut should be on the virtualized Cmd+L, mimicking the macOS terminal. Using the physical Ctrl+L keys may need a new remap in the config file, to avoid the desktop environment invoking the screen locking. I'll have to take a closer look at that.

Cmd+W works in the embedded terminal for deleting words, simply because it is literally sending Ctrl+W to the app (due to the modifier remapping). On the other hand, physical Ctrl+W will send Meta+W, which gets caught by Plasma to show the application grid view. This could be fixable with a similar solution to the Meta+L situation. But I'll have to test that.

Unfortunately the keymappers Kinto and Toshy use (or any other Linux keymapper) can't do better in this situation because they just can't know you're in a "terminal" when you enter a terminal pane embedded in an app that is otherwise not a terminal. Things like AutoHotkey in Windows operate on a much wider variety of information about the focused window.

It's possible someone very clever could make an extension for VSCode that could change the window title based on when the focus was in the embedded terminal, then it might be possible to convert to treating the VSCode window like a terminal as long as the window title showed that the focus was in the terminal. But I'm not even sure if such an extension is possible, and depending on the window context solution the window title doesn't get updated until switching windows, so that would only be sort of half a solution. The Plasma window context is one that has this problem.

The suggestions in the Wiki article are the best I could come up with to fix just a few common shortcuts in the embedded terminal. If you're doing more complicated things in the terminal, I think you'll find it just won't be very usable. I even have trouble with some of the nano shortcuts in the embedded terminal, after all the redirecting. I do more complex tasks outside of VSCode, in a regular terminal window, where the modmapping strategy is different (physical Ctrl is still Ctrl).

raraz15 commented 2 months ago

I understand the issue. Thank you for the explanation! I decided to use VsCode for coding and I use the linux terminal next to it (where Toshy works like a charm)