How to Install and Use Telescope Fuzzy Search Plugin for Neovim

In this tutorial, I will introduce you to a popular plugin for neo-vim called 'Telescope'. It has a variety of features, but I will focus on file search and live grep.

Share:

Apr 15, 2023 469 Words

Read Time: 3 Minutes

A screeshot of 'telescope' plugin's file finder feature in action in neovim.

Introduction

In this tutorial, I will introduce you to a popular plugin for nvim called telescope12. It has a variety of features, but I will focus on file search and live grep.

I will provide a brief gist to help you better understand how they work and how to use them effectively.

Global File Search with Telescope and Vim Key-Bindings

One of the most useful features of telescope is its ability to perform global file searches with the help of Vim key-bindings. This means that you can easily search for files across your entire project without leaving your editor.

To use this feature, simply type the following command:

:Telescope find_files

This will open a search window where you can enter the name of the file you want to find. You can use the arrow keys to navigate through the search results and press enter to open the selected file.

Live Grep with Telescope and Vim Key-Bindings

Another great feature of telescope is its ability to perform live grep searches. This means that you can search for a specific string within your project and see the results in real-time.

To use this feature, simply type the following command:

:Telescope live_grep

This will open a search window where you can enter the string you want to search for. You can use the arrow keys to navigate through the search results and press enter to open the selected file.

Setup and Installation

πŸ’» I’ve setup neo-vim in my macOS machine but the process should be more or less similar for any linux based operation system.

To use telescope, you can install it as a plugin using VIM.PLUG 3. You will need to add the following code to your ~/.config/nvim/init.vim file to install it:

let mapleader=","
nnoremap <Leader>ff :Telescope find_files<CR>
nnoremap <Leader>lg :Telescope live_grep<CR>

call plug#begin()
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
call plug#end()

Reloading and running :PlugInstall should install the telescope plugin. After installing the plugin, you can check if it works by entering the command:

:checkhealth Telescope

If the output shows that everything is installed properly, you can start using telescope by entering the commands :Telescope find_files and :Telescope live_grep.

As per above configuration, you can also use keymaps/hotkeys to do the same:

  • , + ff same as :Telescope find_files<CR>

  • , + lg same as :Telescope live_grep<CR>

✨ Keymaps or hotkeys make it super effective for a developer to spin up a file or grep finder.

πŸ“’ You might also have to install ripgrep 4 to ensure live grep feature can be used properly with telescope plugin.

Conclusion

I hope that this tutorial has been helpful in introducing you to the powerful features of telescope. With a little practice, you will be able to use it to streamline your workflow and improve your productivity.

References