2
2

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.

[R] Visual Studio Codeで%>%のショートカット

Last updated at Posted at 2020-04-09

はじめに

RstudioではCtrl+Shift+Mでパイプ演算子%>%を挿入できます。
Visual Studio Codeでも同じショートカットキーで%>%を挿入できるように設定します。

keybindings.jsonを開く

Ctrl+Shift+Pでコマンドパレットを開きます。
keyと入力すると Preferences: Open Keyboard Shortcuts (JSON)が出てくるのでクリックします。

%>%を登録する

JSONに下記のキーバインディングを追記します。

  {
    "key": "ctrl+shift+m",
    "command": "type",
    "args": {
      "text": "%>%"
    },
    "when": "editorTextFocus && editorLangId == 'r'"
  },

以下はkeybindings.jsonの中身です。

// 既定値を上書きするには、このファイル内にキー バインドを挿入しますauto[]
[
  {
    "key": "ctrl+shift+m",
    "command": "type",
    "args": {
      "text": "%>%"
    },
    "when": "editorTextFocus && editorLangId == 'r'"
  },
  {
    "key": "ctrl+shift+enter",
    "command": "workbench.action.terminal.runSelectedText"
  },
  {
    "key": "shift+enter",
    "command": "-python.execSelectionInTerminal",
    "when": "editorTextFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
  },
  {
    "key": "ctrl+meta+enter",
    "command": "python.datascience.execSelectionInteractive",
    "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
  },
  {
    "key": "shift+enter",
    "command": "-python.datascience.execSelectionInteractive",
    "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
  },
  {
    "key": "ctrl+shift+capslock ctrl+shift+alt+m",
    "command": "workbench.actions.view.problems"
  },
  {
    "key": "ctrl+shift+m",
    "command": "-workbench.actions.view.problems"
  },
  {
    "key": "ctrl+shift+enter",
    "command": "-r.runSourcewithEcho",
    "when": "editorTextFocus && editorLangId == 'r'"
  },
  {
    "key": "ctrl+shift+enter",
    "command": "-editor.action.insertLineBefore",
    "when": "editorTextFocus && !editorReadonly"
  },
  {
    "key": "ctrl+enter",
    "command": "-r.runSelection",
    "when": "editorTextFocus && editorLangId == 'r'"
  },
  {
    "key": "ctrl+enter",
    "command": "-r.runSelection",
    "when": "editorTextFocus && editorLangId == 'rmd'"
  }
]

以上です。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?