telescope.nvim - Config

前回は、ほぼ新月の時期にtelescope.nvimをメイクアップ 🌙

気づけばもうすっかり Snow Moon (満月) です🌕 ムーンプリズム・パワーがハンパないです❗

...な〜んてオープニングに時間をかけていると朝になってしまうので、早速いきましょう❗

Previous...

ページを跨いだのでもう一回載っけときます。

extensions/telescope.lua

local telescope = require 'telescope'

telescope.setup {
  defaults = {
    mappings = {
      i = {
        ['<C-h>'] = 'which_key',
      },
    },
    winblend = 20,
  },
}
telescope.load_extension 'fzf'

local builtin = require 'telescope.builtin'

vim.keymap.set('n', '<leader>ff', builtin.find_files)
vim.keymap.set('n', '<leader>fg', builtin.live_grep)
vim.keymap.set('n', '<leader>fb', builtin.buffers)
vim.keymap.set('n', '<leader>fh', builtin.help_tags)

これがtelescopeの基本形ですね。

で、いつも通りこれだけでいってもいいんですが...、

ちょ〜っち寄り道して、先にわたしのおすすめ設定を紹介しちゃいます😆

help_tags ✨My recommendation✨

こんなのを入れてみてください。

extensions/telescope.lua

local themes = require 'telescope.themes'

-- ...

vim.keymap.set('n', '<leader>h', function()
  builtin.help_tags(themes.get_ivy())
end)

そしたら、leaderhとしてみましょう。 telescope-help_tags

一目で分かるすっごいやつ...❗

:h help_tags

builtin.help_tags({opts})                   telescope.builtin.help_tags()
  Lists available help tags and opens a new window with the relevant help info on `<cr>`

  利用可能なヘルプタグをリストアップし、`<cr>`で新しいウィンドウにヘルプ情報を表示します。

  Parameters:
      {opts} (table)  options to pass to the picker

  Options:
      {lang}     (string)   specify language (default: vim.o.helplang)
      {fallback} (boolean)  fallback to en if language isn't installed
                            (default: true)

文字列で絞り込んで...🧐 telescope-help_tags

returnで開く。 telescope-help_tags

デフォルトであってもおかしくない...っていうか、なんでないの⁉️ ってぐらいの機能が実現してます🤗

themesについてはまた後で触れます。おたのしみはとっときましょ😉

setup

それじゃあ、ここからはいつも通りでいきましょう🐰

defaults

このサイトでは、defaultsオプションのみを扱います。

mappings

:h telescope.mappings

telescope.mappings is used to configure the keybindings within a telescope picker. These key binds are only local to the picker window and will be cleared once you exit the picker.

telescope.mappings はテレスコープピッカー内のキーバインドを設定するために使用されます。 これらのキーバインドはピッカー ウィンドウ内でのみ有効で、ピッカーを終了するとクリアされます。

We provide multiple configuration options to make it easy for you to adjust telescope's default key bindings and create your own custom key binds.

複数の設定オプションが用意されており、telescope のデフォルトのキーバインドを調整したり、 独自のキーバインドを作成したりすることが簡単にできます。

To see many of the builtin actions that you can use as values for this table, see telescope.actions

このテーブルの値として使用できるビルトインアクションの多くは、 telescope.actions を参照してください。

Tip

このサイトでは、今後もhelpへの参照を:h表記で統一しますが、もはやtelescope.help_tagsを使うほうが便利ですね😤

積極的に使っていきましょう❗

こっちも「もはや」って感じですが、iInsert ModenNormal Modeです。 それぞれにキーマッピングを設定できます。

Insert Mode

telescopeの検索バーにいる時もInsert ModeNormal Modeっていう概念は持っていて、 telescopeを開いた段階ではInsert Modeになっています。

EscをすればNormal Modeに切り替わりますが、「え😮 Normal Mode要る❓」とか思っちゃう場合はこんなのもアリです。

extensions/telescope.lua

    mappings = {
      i = {
--      ['<C-h>'] = 'which_key',
        ['<esc>'] = require('telescope.actions').close,
      },
    },

こうしておくとEsctelescopeからそのまま抜けます☺️

Note

Ctrl-[派の人も<esc>を指定しておけばOKです。

which_key

telescopeウィンドウを開いた状態でCtrl-hとすると操作一覧が現れます。

telescope.actions.which_key()

actions.which_key({prompt_bufnr})
    Display the keymaps of registered actions similar to which-key.nvim.

    which-key.nvimと同様に、登録されたアクションのキーマップを表示します。
telescope-installation

以下のようにコードを加えるとNormal Modeでも操作一覧を出すことができるんですね。

extensions/telescope.lua

    mappings = {
      i = {
        ['<C-h>'] = 'which_key',
      },
      n = {
        ['<C-h>'] = 'which_key',
      }
    },
telescope-installation

なんていうか、すっごい行き届いてますよね☺️

winblend

「これがtelescopeの基本形ですね〜」とか言っておきながら、winblendはわたしが勝手に入れてるやつでした🐱

:h winblend

'winblend' 'winbl'                          number	(default 0)
                                            local to window

Enables pseudo-transparency for a floating window. Valid values are in
the range of 0 for fully opaque window (disabled) to 100 for fully
transparent background. Values between 0-30 are typically most useful.

フローティングウィンドウの擬似透過を有効にする。
有効な値は、完全に不透明なウィンドウ(無効)のための 0 から完全に透明な背景のための 100 の範囲である。
一般的に 0-30 の間の値が最も有用。

UI-dependent. Works best with RGB colors. 'termguicolors'

これは UI に依存する。`termguicolors`が有効である場合に最も機能する。

winblendNeovimwindowオプションです。

Tip

...なので、とにかくスケスケが好きなら、options.luaあたりにこんなんするのも良いと思います。

vim.api.nvim_win_set_option(0, 'winblend', 20)
winblend

ほらね。telescopeに限らずpackerなんかも、もれなくスケスケです☺️ えへへ。

load_extension

:h telescope.load_extension()

telescope.load_extension({name})
  Load an extension.
  拡張機能を読み込む。

  - Notes:
    - Loading triggers ext setup via the config passed in `telescope.setup`
      ロードすると、`telescope.setup` で渡された設定により、拡張機能のセットアップが行われます。

  Parameters:
      {name} (string)  Name of the extension

このサイトではtelescope-fzf-native.nvimのロードに使用しています😌

fzf-native is a c port of fzf. It only covers the algorithm and implements few functions to support calculating the score. This means that the fzf syntax is supported:

fzf-native は fzf の c 版です。これはアルゴリズムのみをカバーし、スコア計算をサポートするいくつかの関数を実装しています。 これは、fzf構文がサポートされていることを意味します。

もしカスタマイズが必要であれば Telescope Setup and Configuration で方法が示されています。

builtin

これはもうtelescope.nvimがオフィシャルに機能を一覧してくれているので、これだけ示します。

Built-in functions. Ready to be bound to any key you like.

これを見るだけでもかなり多機能なのがわかります...。😮

わたしがさらっと確認した限りで言うと、

Note

多分なんですが、ctagsはこのサイトでは扱いません。

わたしもインストールはしてあるけど、「乗りこなせていない」というのが正直なところ😅

この辺り以外は、もうここまでの内容だけでも全部動くんじゃないかな🤔

一応使う方法だけ書いておくと、キーマップに登録するのが一番簡単です。例えば、

FunctionsDescription
builtin.find_filesLists files in your current working directory, respects .gitignore

...ってなってるのを、

vim.keymap.set('n', '<leader>ff', builtin.find_files)

...ってしていくだけですね。全部このフォーマットでいけるはずです❗

Note

もちろん、キーバインドは他のと被らないようにね😉

themes

...ってことで、ようやくthemesに辿り着きました☺️

これはさっきのhelp_tagsのコードです。

local themes = require 'telescope.themes'

vim.keymap.set('n', '<leader>h', function()
  builtin.help_tags(themes.get_ivy())
end)

Common groups of settings can be set up to allow for themes. We have some built in themes but are looking for more cool options.

共通の設定グループを設定することで、テーマを設定することができます。 我々はいくつかのビルトインテーマを持っていますが、よりクールなオプションを探しています。

これはもうイメージで見たほうが早いと思うので、help_tagsをそれぞれのthemesで呼んでみます。

ThemesImage
(not param)telescope-theme-none
get_dropdowntelescope-theme-dropdown
get_cursortelescope-theme-cursor
get_ivytelescope-theme-ivy

もう言葉なんて入りませんね❗

Recipes

このサイトで紹介した内容も含めて、 お役立ち Tips はもう既にtelescope.nvimwikiにたくさんまとまっているので、試してみると面白いです😆

A place for the community to share configurations and custom pickers that dont fit into core or an extension

コアやエクステンションにない設定やカスタムピッカーをコミュニティで共有する場です。

Wrap Up

このサイトに書いてあることなんて、ほんと表面だけです。 telescope.nvimは、ほんとにもう目が回る😵‍💫 ぐらい多機能なんで❗

...で、なんですけど😮

わたしもつい最近知った便利なtipがあるので、次回はそんな新星のおはなしです✨

Fly me to the moon

And let me play among the stars

ねえ わたしを月までいかせて

あの星たちに囲まれて 遊んでみたいの

Let me see what spring is like

On jupiter and mars

ねえ 木星と火星の春って

どんなものなんだろう 見てみたいの

Assemble

さぁ〜て、この次も❗サービス、サービスぅ💕