0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Zed】選択中のコードとコピーしたコードを比較する方法

0
Posted at

比較方法

  1. 比較したい一方のコードをコピー(cmd-c / ctrl-c)してクリップボードに入れる
  2. もう一方のコードをエディタ上で選択する
  3. コマンドパレット(cmd-shift-p / ctrl-shift-p)を開いて diff clipboard with selection を実行する

差分ビューが開き、追加・削除された行がハイライト表示されます。

具体例

たとえば、以下の 2 つの関数があるとします。

# 関数 A(クリップボードにコピー)
def calculate_discount(price, rate)
  discount = price * rate
  price - discount
end

# 関数 B(エディタ上で選択)
def calculate_tax(price, rate)
  tax = price * rate
  price + tax
end

関数 A をコピーして関数 B を選択した状態でコマンドを実行すると、差分ビューには discounttaxprice - discountprice + tax の部分だけが差分として表示されます。関数名と変数名だけが異なると一目で把握できます。

キーバインドを登録する

頻繁に使う場合は keymap.json にキーバインドを登録しておくと、コマンドパレットを開く手間を省けます。

{
  "context": "Editor",
  "bindings": {
    "cmd-alt-d": "editor::DiffClipboardWithSelection"
  }
}

contextEditor に限定しておくことで、エディタ以外の場所での誤作動を防げます。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?