$shibayu36->blog;

クラスター株式会社のソフトウェアエンジニアです。エンジニアリングや読書などについて書いています。

今見ているファイル内をSearchしやすくするVSCode拡張を作りました

今見ているファイル内をSearchしやすくする「Search in Current File」というVSCode拡張を作ったので紹介です。

背景

Emacsにはhelm-occurという拡張があって、インクリメンタルサーチからスムーズにファイル内の検索結果一覧を見れる拡張がある。これが現在のファイルを探索するのに非常に便利で愛用していた。

VSCodeでも同じようなことが出来ないかなと思ったので、勉強がてら拡張を作ることにした。

使い方

Search in Current File - Visual Studio Marketplaceからインストールすると、「Search in Current File」というコマンドが追加される。これを実行するとFindからスムーズにSearchに移行し、現在カーソルのあるファイルのみのマッチ結果を出すことが出来る(Searchパネルのfiles to includeに自動で現在のファイルがフィルインされる)。

デモ

また以下のようなキーボードショートカットを設定しておくと便利。Find中にctrl-oを押すだけですぐさまSearchに移行する事ができる。もちろん別のキーボードショートカットを設定しておくことでFind中以外でも現在ファイルからSearch出来る(範囲選択していたらクエリに自動でフィルインされる)。

// Only type ctrl+o when using Find.
// the query in Find is filled into the query in Search.
{
  "key": "ctrl+o",
  "command": "search-in-current-file.searchInCurrentFile",
  "when": "editorFocus && findInputFocussed"
},
{
  "key": "ctrl+cmd+o",
  "command": "search-in-current-file.searchInCurrentFile",
  "when": "editorFocus"
}

技術的Tips

まとめ

今回は、今見ているファイル内をSearchしやすくするVSCode拡張を作ったので紹介しました。VSCode拡張の基本的な作り方が把握できたのが良かったです。

参考資料

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy