3

On Karabiner rules (https://pqrs.org/osx/karabiner/complex_modifications/), there is a rule for Exchange paren and square bracket but there is no rule for Exchange square bracket and curly braket.

[Q] How to exchange square bracket and curly bracket through Karabiner or any alternative?

Wanted exchange:

  • [ => { and { => [
  • ] => } and } => ]
alper
  • 2,919
  • 9
  • 53
  • 102

1 Answers1

2

This code works for me

{
  "description": "Swap {} and []",
  "manipulators": [
    {
      "type": "basic",
      "from": {
        "key_code": "open_bracket"
      },
      "to": [
        {
          "modifiers": ["left_shift"],
          "key_code": "open_bracket"
        }
      ]
    },
    {
      "type": "basic",
      "from": {
        "key_code": "open_bracket",
        "modifiers": {
          "mandatory": ["left_shift"]
        }
      },
      "to": [
        {
          "key_code": "open_bracket"
        }
      ]
    },
    {
      "type": "basic",
      "from": {
        "key_code": "close_bracket"
      },
      "to": [
        {
          "modifiers": ["left_shift"],
          "key_code": "close_bracket"
        }
      ]
    },
    {
      "type": "basic",
      "from": {
        "key_code": "close_bracket",
        "modifiers": {
          "mandatory": ["left_shift"]
        }
      },
      "to": [
        {
          "key_code": "close_bracket"
        }
      ]
    }
  ]
}

edit: also now in complex mod list https://pqrs.org/osx/karabiner/complex_modifications/#exchange_square_brackets_and_curly_brackets

Gene Sy
  • 1,325
  • 2
  • 10
  • 17
  • In which file should I paste this? – alper Feb 20 '20 at 07:42
  • This has been merged to the complex rules list. you can search it there now :) – Gene Sy Feb 20 '20 at 09:31
  • 1
    edited my answer to link to the new rule i submitted – Gene Sy Feb 20 '20 at 10:36
  • Thanks! I was wondering is it possible to use these rule only for `U.S.` keyboard, and disable them if another keyboard is selected? I can ask it under a different question. – alper Feb 20 '20 at 18:31
  • i think it's possible although i haven't tried it yet. go ahead and ask it and i'll do my best to figure it out – Gene Sy Feb 20 '20 at 20:58
  • Also is it possible to exchange dash and underscore as well? => https://stackoverflow.com/questions/60329484/how-to-exchange-dash-and-underscore-karabiner – alper Feb 20 '20 at 22:28
  • For my other question please see => https://stackoverflow.com/questions/60329520/is-it-possible-to-enable-rules-only-for-specific-keyboard-layout-karabiner – alper Feb 20 '20 at 22:31