LoginSignup
10
4

More than 3 years have passed since last update.

VSCodeでテキスト選択(ctrl+shift+〇)のキーバインド登録方法

Last updated at Posted at 2017-08-05

概要

自分は環境は macOS High Sierra です。
mac で ctrl+p で上矢印 ctrl+f で右矢印などのショートカットを使用している人は多いのではないでしょうか。
もともとは Emacs のキーバインドらしいのですが、 macOS では基本的にどのアプリでも使用でき大変便利です。
このコマンドに似せてテキスト選択をキーボードだけで、操作したいと思ったので、その方法を書きます。

ちなみに経緯は kobito (Markdownエディタ)ではこのキーバインドが動作したので、自分のメインエディタである VSCode でも使用できるようにしたかったというものです。

VScodeでショートカットを登録

VSCodeのバージョンは 1.28.1 での操作です。
今回の件に限らず VSCode では下記の方法で好きなキーバインドを登録することができます。
メニューバーから
File->Preferences->Keyboard Shortcuts
日本語だと
ファイル->基本設定->キーボードショートカット
キーボードショートカットという画面になりますのでその中から
keybindings.json を開きます。

あるいは コマンドパレット [Command + Shift + P] で keybind などと検索してもこのファイルにだどりつけるかと思います。

keyboard shotcut という項目に辿りつくかと思います。
ここの一番右のアイコンをクリックすると keybindings.json が開きます。

image.png

keybindings.json に下記をコピペします。


[
  {
    "key": "ctrl+shift+n",
    "command": "cursorDownSelect",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+shift+p",
    "command": "cursorUpSelect",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+shift+f",
    "command": "cursorRightSelect",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+shift+b",
    "command": "cursorLeftSelect",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+shift+a",
    "command": "cursorHomeSelect",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+shift+e",
    "command": "cursorEndSelect",
    "when": "editorTextFocus"
  }
]

他にも default keybindingsを参考にいろいろ作れそうですね。
以上です。

10
4
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
10
4