skip to Main Content

Here is my problem:
I want to use the Ctrl J shortcut to switch between editing a file and writing in the terminal.
I have this keybinding:

{
    "key": "ctrl+j",
    "command": "workbench.action.togglePanel",
},

I can indeed toggle the terminal when i am editing but when the focuse is on the terminal, the terminal just understands it as a command and skips to a new line.
However, when i click back on the editor and press Ctrl J, the termminal indeed disappears.
Any clue ?

i tried to add a new terminalfocuse property but it did not work.

2

Answers


  1. That issue has to do with the default bash shell bindings.

    Ctrl+J is bound to ‘accept-line’ which does the same thing as the Enter/Return key (so it will create a new line if nothing is typed).

    You can change how bash responds to keys using the bind keyword.

    To check which action is currently bound to Ctrl+J you can run:

    bind -P | grep '\C-j'
    

    The default output is:
    accept-line can be found on "C-j", "C-m".

    So, if you want your keybindings to work, you have to remove the ‘accept-line’ function from Ctrl+J.

    You can do so by running:

    bind '"C-j" none'
    

    And if you want this to happen every time you are in a bash shell, you can add the previous line to your ~/.bashrc.

    Login or Signup to reply.
  2. This is perplexing. This sounds like the terminal.integrated.commandsToSkipShell setting’s default value isn’t doing it’s job, which makes me wonder if you overrode it.

    The description of that setting reads as follows:

    A set of command IDs whose keybindings will not be sent to the shell but instead always be handled by VS Code. This allows keybindings that would normally be consumed by the shell to act instead the same as when the terminal is not focused, for example Ctrl+P to launch Quick Open.

    Many commands are skipped by default. To override a default and pass that command’s keybinding to the shell instead, add the command prefixed with the - character. For example add -workbench.action.quickOpen to allow Ctrl+P to reach the shell.

    The following list of default skipped commands is truncated when viewed in Settings Editor. To see the full list, open the default settings JSON and search for the first command from the list below.

    Default Skipped Commands:

    • […]
    • workbench.action.togglePanel

    So I would suggest that you check all your settings.json files (user-level settings.json, workspace .vscode/settings.json, and .code-workspace file if you are in a multi-root workspace) and see if you have something like the following in it anywhere:

    "terminal.integrated.commandsToSkipShell": [
        "-workbench.action.togglePanel",
    ],
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search