Git 利用するエディターを指定・ファイル編集(コマンドライン)

VS codeコマンドラインから呼び出せるように設定

  1. VS code立ち上げる
  2. Shift + Command + P を押す
  3. 『shell』と入力
  4. 『シェルコマンド:PATH内に'code'コマンドをインストールします』をクリック

Gitで使用するエディターをVS Codeに指定する

$ git config --global core.editor "code --wait"

設定を確認

$ git config core.editor
code --wait

もしくは

$ git config --list
credential.helper=osxkeychain
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
user.name=xxxx
user.email=xxxxx
core.editor=code --wait
設定を削除したい時
$ git config --global --unset core.editor

ここまでを設定するとgitでコミットする際にVS codeが立ち上がるようになるはずが、 エラーが出た。

$ git commit
hint: Waiting for your editor to close the file... code --wait: code: command not found
error: There was a problem with the editor 'code --wait'.
Please supply the message using either -m or -F option.

エラー原因

VS Code内にてcodeコマンドを使用する設定ができていない為。

解決方法

VS codeで shift + command + p でコマンドパレットを開く 下記コマンドを実行

Shell Command: Install 'Code' command in path

パスワードを聞かれたら入力

もう一度、git commitしたら無事にVS codeが立ち上がりました。

###プロジェクトでファイル編集をするためにエディターを立ち上げる

$ code /Users/xxxx/Desktop/ichiyasaGitSample

プロジェクトのフォルダーごとエディターが立ち上がります。