Search Over All Project Files in Telescope Live Grep


Here's how to search all project files using Telescope's Live Grep.

First, install telescope.nvim. With lazy.nvim, the parts of the configuration that we need for this particular effort could look like this:

return {
  "nvim-telescope/telescope.nvim",
  dependencies = {
    { "nvim-lua/plenary.nvim" },
  },
  keys = {
    { "<leader>fg", '<cmd>Telescope live_grep<cr>', desc = "Ripgrep", },
  },
  config = function()
    local telescope = require("telescope")
    local root_patterns = { ".git", "deps.edn" }
    local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1])
    telescope.setup({
      pickers = {
        live_grep = {
          file_ignore_patterns = { 'node_modules', '.git', '.cpcache', '.clj-kondo', '.lsp' },
          search_dirs = { root_dir },
        },
      },
    })
  end,
},

You'll probably also want to install ripgrep itself.

What's going on in this config? We're setting the key command to run Telescope live_grep with, namely fg.

Important to this particular effort, we set the search_dirs option. This says where grep should happen. In my experience, the default will search the current working directory. But instead, we want to search the entire project. We therefore have to find the directory that contains the entire project. That's usually indicated with some sort of project config file, such as deps.edn. As a more generic fallback, it contains the .git record. The root_patterns and root_dir values are tracking this location.

That's about all there is to it. To read more options to further customize the search, see :help telescope.builtin.live_grep().