Fetching latest headlines…
Neovim Grepping and File Search Without Plugins
NORTH AMERICA
πŸ‡ΊπŸ‡Έ United Statesβ€’May 9, 2026

Neovim Grepping and File Search Without Plugins

0 views0 likes0 comments
Originally published byDev.to

Neovim already has powerful built-in tools for searching text and files.
You don't need Telescope or any plugin for basic workflow.

Grepping Text with :grep

Neovim can use any external search tool through :grep.

Check the current grep program:

:set grepprg?

Most setups will show something like:

grepprg=rg --vimgrep -uu

This means Neovim uses ripgrep (rg) for searching.

Better grepprg Configuration

A good default setup:

vim.opt.grepprg = "rg --vimgrep --smart-case --hidden"

What these flags do

Flag Description
--vimgrep Output format compatible with quickfix
--smart-case Ignore case unless uppercase is used
--hidden Search hidden files too

You can also exclude useless folders:

vim.opt.grepprg =
    "rg --vimgrep --smart-case --hidden " ..
    "--glob '!node_modules' " ..
    "--glob '!.git' " ..
    "--glob '!dist' " ..
    "--glob '!build'"

Using :grep

Basic usage:

:grep pattern

Example:

:grep useState

This searches inside the current working directory.

Results are added to the quickfix list.

Open it with:

:copen

Useful Quickfix Commands

Command Description
:copen Open quickfix list
:cclose Close quickfix
:cnext Next result
:cprev Previous result
:cfirst First result
:clast Last result

Filtering Results

You can filter quickfix entries:

:Cfilter keyword

Example:

:Cfilter test

Only entries containing test stay visible.

Replace Across Search Results

One of the best things about quickfix:

:cdo s/old/new/g | update

Example:

:cdo s/console.log/logger.info/g | update

This updates every matched file.

Better Grep Keymap

A clean keymap:

vim.keymap.set("n", "<leader>g", function()
    vim.cmd("silent grep! " .. vim.fn.input("Grep > "))
    vim.cmd("copen")
end)

Why this is better

  • asks for input
  • prevents jumping to first result
  • automatically opens quickfix
  • cleaner than command chaining

Usage:

<leader>g

Then type:

keymap

searching for text with :grep

qflist with results

You instantly get all matches.

Searching Files with :find

Neovim also has built-in file search.

Basic usage:

:find filename

Out of the box it's limited, so we improve it.

Configure Search Paths

Add recursive search:

vim.opt.path:append("**")

Now :find searches inside subdirectories.

Ignore Large Folders

Without ignores, search becomes slow.

vim.opt.wildignore:append({
    "*/node_modules/*",
    "*/dist/*",
    "*/build/*",
    "*/target/*",
    "*/.git/*",
})

Better Completion

Enable menu completion:

vim.opt.wildmenu = true
vim.opt.wildmode = "longest:full,full"

Now tab completion becomes much better.

Example:

:find keymaps

Neovim autocompletes matching files.

Searching with :find

Add File Extensions Automatically

Useful when working with specific languages:

vim.opt.suffixesadd:append({
    ".lua",
    ".ts",
    ".tsx",
    ".js",
})

Now you can do:

:find init

Instead of:

:find init.lua

Example Workflow

Search for text:

:grep TODO

Open results:

:copen

Replace text in all results:

:cdo s/TODO/DONE/g | update

Find a file:

:find config

Jump between results:

:cnext
:cprev

Full Minimal Config

-- grep
vim.opt.grepprg =
    "rg --vimgrep --smart-case --hidden " ..
    "--glob '!node_modules' " ..
    "--glob '!.git' " ..
    "--glob '!dist' " ..
    "--glob '!build'"

-- recursive file search
vim.opt.path:append("**")

-- ignored folders
vim.opt.wildignore:append({
    "*/node_modules/*",
    "*/dist/*",
    "*/build/*",
    "*/target/*",
    "*/.git/*",
})

-- better completion
vim.opt.wildmenu = true
vim.opt.wildmode = "longest:full,full"

-- auto extensions
vim.opt.suffixesadd:append({
    ".lua",
    ".ts",
    ".tsx",
    ".js",
})

-- grep keymap
vim.keymap.set("n", "<leader>g", function()
    vim.cmd("silent grep! " .. vim.fn.input("Grep > "))
    vim.cmd("copen")
end)

Comments (0)

Sign in to join the discussion

Be the first to comment!