1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VS Code の左右カーソル移動をWordPart移動に置き換える

Last updated at Posted at 2020-06-21

はじめに

VS Codeのキーバインドを左右キーで単語境界に移動させるように変更しました。
()や""を打ってしまうと真ん中に移動させづらくなるなど使いづらい事も多いのですが、プログラムを作成しているときは重宝しています。
だた、日本語の文章の場合は、役立たずではあります。

もう少し使いやすくしたExtensionを公開しました。
良ければご覧ください。
VSCode カーソル移動を向上させる自作 Extension の紹介

主要カーソル移動コマンド一覧

VS Codeには以下のようなカーソル移動コマンドがあります。

command default key description
cursorLeft(Select) Left(Shift+) 右へ移動する
cursorRight(Select) Right(Shift+) 左へ移動する
cursorWordEndLeft(Select) 左の WordEnd へ移動する
cursorWordEndRight(Select) Ctrl+Right(Shift+) 右の WordEnd へ移動する
cursorWordStartLeft(Select) Ctrl+Left(Shift+) 左の WordStart へ移動する
cursorWordStartRight(Select) 右の WordStart へ移動する
cursorWordLeft(Select) 左の WordStart へ移動する
cursorWordRight(Select) 右の WordEnd へ移動する
cursorWordPartLeft(Select) 左の WordPart(End or Start の近い方)へ移動する
cursorWordPartRight(Select) 右の WordPart(End or Start の近い方)へ移動する
cursorWordPartStartLeft(Select)

変更箇所

上記のコマンドを以下のように置き換えました。
Shift付きの選択するコマンドも同じように置き換えていますが省略しています。

command key
cursorLeft Ctrl+Left
cursorRight Ctrl+Right
cursorWordEndRight -
cursorStartLeft -
cursorWordPartLeft Left
cursorWordPartRight Right

keybindings.json

keybindings.json は以下のような記述になります。

keybindings.json
[
  {
    "key": "left",
    "command": "cursorWordPartLeft",
    "when": "textInputFocus"
  },
  {
    "key": "shift+left",
    "command": "cursorWordPartLeftSelect",
    "when": "textInputFocus"
  },
  {
    "key": "right",
    "command": "cursorWordPartRight",
    "when": "textInputFocus"
  },
  {
    "key": "shift+right",
    "command": "cursorWordPartRightSelect",
    "when": "textInputFocus"
  },
  {
    "key": "left",
    "command": "-cursorLeft",
    "when": "textInputFocus"
  },
  {
    "key": "shift+left",
    "command": "-cursorLeftSelect",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+left",
    "command": "cursorLeft",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+shift+left",
    "command": "cursorLeftSelect",
    "when": "textInputFocus"
  },
  {
    "key": "right",
    "command": "-cursorRight",
    "when": "textInputFocus"
  },
  {
    "key": "shift+right",
    "command": "-cursorRightSelect",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+right",
    "command": "cursorRight",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+shift+right",
    "command": "cursorRightSelect",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+left",
    "command": "-cursorWordStartLeft",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+shift+left",
    "command": "-cursorWordStartLeftSelect",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+right",
    "command": "-cursorWordEndRight",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+shift+right",
    "command": "-cursorWordEndRightSelect",
    "when": "textInputFocus"
  }
]
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?