web-dev-qa-db-fra.com

Comment empêcher Sublime Text 2 d'avaler des crochets de fermeture, des guillemets et des parenthèses?

Sublime a ce comportement qui est vraiment ennuyeux parfois lorsque vous devez taper des constructions avec beaucoup de crochets. Lorsque vous tapez ( il ajoute () et place le curseur au milieu, très bien, si vous tapez cependant ) il avalera silencieusement le support de fermeture.

C'est vraiment ennuyeux lors de la frappe de longues expressions régulières, car les supports se déséquilibrent assez rapidement et cela me rend fou. Vous vous retrouvez donc avec des constructions comme (([a-z]).

La question est donc - existe-t-il un moyen de désactiver cela? Si je tape un crochet de fermeture, je veux qu'il reste, ne pas être avalé.

J'ai vérifié dans les configurations Sublime, googlé, mais personne ne semble s'occuper de ce comportement. Suis-je mal utilisé?

Mise à jour

Vous voudrez peut-être vérifier Sublime: sauter également des crochets correspondants raccourci.

Version complète qui vous permet de taper avec () mais n'avalera pas le symbole de fermeture si vous avez saisi du texte:

  { "keys": ["\""], "command": "insert", "args": {"characters": "\""}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\"", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[^\"]$", "match_all": true }
      ]
  },
  { "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[^(]$", "match_all": true }
      ]
  },
  { "keys": [")"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
      ]
  },
  { "keys": ["'"], "command": "insert", "args": {"characters": "'"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^'", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "'$", "match_all": true }
      ]
  },
  { "keys": ["]"],"command": "insert", "args": {"characters": "]"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[$", "match_all": true }
      ]
  },
  { "keys": ["}"], "command": "insert", "args": {"characters": "}"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "{$", "match_all": true }

      ]
  }
62
firedev

ajoutez ceci à votre fichier de raccourcis clavier

{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true }
    ]
}

il remplacera le raccourci clavier qui, au lieu d'insérer un crochet de fermeture, déplace simplement le curseur d'une position vers l'avant. il devrait donc faire exactement ce que vous voulez.

si vous souhaitez désactiver complètement ce comportement, pour toutes sortes de crochets et de guillemets, voici la partie complète des raccourcis clavier:

{ "keys": ["\""], "command": "insert", "args": {"characters": "\""}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\"", "match_all": true }
    ]
},
{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true }
    ]
},
{ "keys": ["'"], "command": "insert", "args": {"characters": "'"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^'", "match_all": true }
    ]
},
{ "keys": ["]"],"command": "insert", "args": {"characters": "]"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
    ]
},
{ "keys": ["}"], "command": "insert", "args": {"characters": "}"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
    ]
}

MODIFIER:

Si vous souhaitez ignorer le crochet de fermeture si le curseur se trouve juste après un crochet d'ouverture et l'imprimer dans tous les autres cas, vous pouvez diviser vos raccourcis clavier pour distinguer entre ces deux possibilités:

{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "[^(]$", "match_all": true }
    ]
},
{ "keys": [")"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
    ]
},

Le premier insère le caractère si le texte précédent ne se termine pas par un crochet ouvrant. Le second déplace le curseur d'une position vers l'avant s'il se termine par un crochet ouvrant. Si vous connaissez un peu les expressions régulières, vous pouvez faire de même pour tous les autres types de crochets et de guillemets.

50
basilikum

Redéfinissez le ) raccourci clavier:

{ "keys": [")"], "command": "insert", "args": {"characters": ")"} }

Edit: Une autre façon est d'activer/désactiver le auto_match_enabled paramètre (modifiant ainsi le comportement de couplage automatique), vous pouvez le basculer à volonté à l'aide d'un raccourci clavier:

{ "keys": ["alt+m"], "command": "toggle_setting", "args": {"setting": "auto_match_enabled"} }
7
dusan