Skip to content

Instantly share code, notes, and snippets.

@yarakos95
Created December 15, 2021 19:15
Show Gist options
  • Save yarakos95/42c50abd350000efc3ae702512a97c0c to your computer and use it in GitHub Desktop.
Save yarakos95/42c50abd350000efc3ae702512a97c0c to your computer and use it in GitHub Desktop.
VSCode のToggle Quotes で簡単に“クオーテーション”を変換

Simple "quotes" conversion by Toggle Quotes in VSCode

ダブルクォート" からシングルクォート' にトグルで変換したいと思うこともあるだろう.

これを実現させる拡張機能がある. Toggle Quotes である.

britesnow.vscode-toggle-quotes - VSCode Marketplace ver.0.3.5 2021/12/15

Repository: BriteSnow/vscode-toggle-quotes: Simple quote toggler that cycle through " ' and `

Languages supported by default

以下の7つの言語をデフォルトでサポートしている. これらの言語では,"'` → (loop) となる.

  • Go
  • JavaScript
  • JavaScriptReact
  • Markdown
  • Svelte
  • TypeScript
  • TypeScriptReact

これ以外の言語では"' → (loop) となる.

個別に外の言語を設定するにはこの節を参照.

Usage

サポートされている言語のファイル上の"' で囲まれている文字列内でCtrl+^ する. これだけ.

test sample

Correspond other language

VSCode は基本的にsettings.json から設定を行うが,Toggle Quotes は少し勝手を変えた方が良さそうである.

Toggle Quotes では,言語ごとに"togglequotes.chars" から指定することでトグルする記号を変更することが出来る. しかしながら,パッケージから指定することのできる言語ごとの設定は配列を受け入れてくれないらしい. そのために,VSCode から警告を受ける.

syntax warning

Editor configuration setting unknown · Issue #6 · BriteSnow/vscode-toggle-quotes

これを回避するために,Toggle Quotes のpackage.json を編集してしまおう. Toggle Quotes のpackage.json は次のディレクトリに格納されている.

~\.vscode\extensions\britesnow.vscode-toggle-quotes-*.*.*\package.json

ここで,"configurationDefaults" 以下に言語ごとの設定を追加する. たとえば,LaTeX で括弧をトグルするように設定するには次のようにする. この例では{}[]() → (loop) するように設定している.

  "configurationDefaults": {
  // Another language settings
    "[latex]": {
      "togglequotes.chars": [
        ["{","}"],
        ["[","]"],
        ["(",")"]
      ]
    },
  }

変更した後にVSCode を再起動すると適用されるようになる. ちなみに,設定の構文に間違いがあるとVSCode に認識されないので注意が必要.

また,この拡張機能が更新される際にはpackage.json は新たなものに書き変わるので,再度書き直す必要がある. したがって,適当にバックアップファイルを残しておく必要がある.

Additional function

README のUpcoming にはバージョン0.3.5 時点でいくつか予告がなされていた.

BriteSnow/vscode-toggle-quotes - # Upcoming

また,次のようなIssue とプルリクも上がっていた.

Add/Remove quotes

現状ではクオーテーションをトグルするのみで,クオーテーションを削除することは出来ない. したがって,以下のようなIssue が立てられている.

Add/remove quotes - Issue #28 - BriteSnow/vscode-toggle-quotes

また,これを解決するようなプルリクも作成されているようだ. 場合によってはマージされるかも.

support empty case by Shuraken007 - Pull Request #40 - BriteSnow/vscode-toggle-quotes

トグルせずに,単にクオーテーションを削除するだけのコマンドではダメなのだろうかと思ったり云々.

Similar extension

クオーテーションや括弧をトグルで変換するような拡張機能は次のようなものを見つけることが出来た.

pustelto.bracketeer - VSCode Marketplace

Repository Pustelto/Bracketeer: VS Code extension for easy and quick manipulation with brackets and quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment