1
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】ファイルをプレビュー付きで検索する方法

Last updated at Posted at 2025-01-03

ドットファイル以外を検索

televisionをインストール

以下のコマンドを実行してtelevisionをインストールします。

brew install television

タスクを追加する

tasks.jsonに以下の記述を追加します。

tasks.json
    {
      "label": "File Finder",
      "command": "zed \"$(tv files)\"",
      "hide": "always",
      "allow_concurrent_runs": true,
      "use_new_terminal": true
    },

キーバインドを追加する

キーバインドで先ほどのタスクを実行できるようにするためにkeymap.jsonに以下を追記します。

keymap.json
    "bindings": {
      "cmd-p": [
        "task::Spawn",
        { "task_name": "File Finder", "reveal_target": "center" }
      ]
    }

参考

ドットファイルを含めて検索

televisionをインストール

以下のコマンドを実行してtelevisionをインストールします。

brew install television

ripgrepをインストール

以下のコマンドを実行してripgrepをインストールします。

brew install ripgrep

batをインストール

以下のコマンドを実行してbatをインストールします。

brew install bat

タスクを追加する

tasks.jsonに以下の記述を追加します。

tasks.json
    {
      "label": "File Finder",
      "command": "zed \"$(rg --files -uu --ignore-file='.zed/.ignore' 2> /dev/null | tv --preview 'bat -n -f -r:100 \"{0}\"')\"",
      "hide": "always",
      "allow_concurrent_runs": true,
      "use_new_terminal": true
    },

.ignoreを作成する

検索に含めたくないファイルを無視するために.zed/.ignoreファイルを作成します。

.ignore
.git
.DS_Store
node_modules

キーバインドを追加する

キーバインドで先ほどのタスクを実行できるようにするためにkeymap.jsonに以下を追記します。

keymap.json
    // contextは任意の値
    "bindings": {
      "cmd-p": [
        "task::Spawn",
        { "task_name": "File Finder", "reveal_target": "center" }
      ]
    }

televisionの代わりにfzfを使う

televisionではなくfzfを使用しても同様の機能を実現できます。

fzfをインストールします。

brew install fzf

fzfを使用する場合はタスクは以下のようになります。

tasks.json
    {
      "label": "File Finder",
      "command": "zed \"$(rg --files -uu --ignore-file='.zed/.ignore' 2> /dev/null | fzf --preview='bat -n -f -r:100 {}')\"",
      "hide": "always",
      "allow_concurrent_runs": true,
      "use_new_terminal": true
    },

他はtelevisionを使用する場合と同様です。

ripgrepの代わりにfdを使用する

ripgrepではなく、fdを使用する場合には以下のようになります。

fdをインストールします。

brew install fd

タスクを以下のように変更します。

tasks.json
    {
      "label": "File Finder",
      "command": "zed \"$(fd -t f -u --ignore-file '.zed/.ignore' | fzf --preview='bat -n -f -r:100 {}')\"",
      "hide": "always",
      "allow_concurrent_runs": true,
      "use_new_terminal": true
    },
1
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
1
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?