LoginSignup
1
1

More than 3 years have passed since last update.

VSCodeで単語単位の選択の範囲を変更する

Posted at

htmlやcssで、id名やクラス名に、-(ハイフン)区切りで単語をつないだ名称を利用することが多いと思う。
VSCodeの初期設定では、ダブルクリックやcommand+D(Mac)で単語を選択するときに、-(ハイフン)区切りの単語は一括で選択できない。

-(ハイフン)区切りの単語を一括で選択したい時は、Word Separatorsの設定から「-」を削除すると、一括で選択できるようになる。

1.jpg

上記の方法では、VSCode全体の設定を変更する。

言語によって設定を変えたい時は、settings.jsonに以下のように記載すればよい。
以下の例では、html,css,jsは-(ハイフン)区切りの名称をよく利用するので、「-」を削除。
php,perlは変数名(\$testなど)を\$含めて選択したいので、「$」を削除。
php,perlでは->を利用するので、「-」は残したままにしている。

{
  "[html]": {
    "editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?"
  },
  "[css]": {
    "editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?"
  },
  "[javascript]": {
    "editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?"
  },
  "[perl]": {
    "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?"
  },
  "[php]": {
    "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?"
  }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1