"search.nvim is a Neovim plugin that enhances the functionality of the Telescope plugin by providing a tab-based search experience. It allows you to seamlessly switch between different search modes within the Telescope window using tabs" - ChatGPT
[!WARNING] this plugin is in early development and might have some bugs. You can also expect changes to the configuration api.
Install search.nvim using your preferred plugin manager. For example:
--- lazy nvim
{
"FabianWirth/search.nvim",
dependencies = { "nvim-telescope/telescope.nvim" }
}
the default tabs are:
they can be configured in the setup function.
To open the search.nvim window, use the following command:
require('search').open()
This will activate the default tab and open the Telescope window with the specified layout. it is also possible to provide a tab_id or tab_name to directly activate a specific tab (id takes precedence over name). Any tab collections defined can also be accessed via the collection key.
require('search').open({ tab_id = 2 })
require('search').open({ tab_name = 'Grep' }) -- if multiple tabs are named the same, the first is selected
require('search').open({ collection = 'git' }) -- Open the 'git' collection of pickers
Navigate between tabs using the <Tab>
and <S-Tab>
keys in normal and insert modes. This allows you to switch between different search modes conveniently.
You can customize the available tabs by modifying the tabs table in the plugin configuration. Each tab should be defined as a Lua table with the following properties:
local builtin = require('telescope.builtin')
require("search").setup({
mappings = { -- optional: configure the mappings for switching tabs (will be set in normal and insert mode(!))
next = "<Tab>",
prev = "<S-Tab>"
},
append_tabs = { -- append_tabs will add the provided tabs to the default ones
{
"Commits", -- or name = "Commits"
builtin.git_commits, -- or tele_func = require('telescope.builtin').git_commits
available = function() -- optional
return vim.fn.isdirectory(".git") == 1
end
}
},
-- its also possible to overwrite the default tabs using the tabs key instead of append_tabs
tabs = {
{
"Files",
function(opts)
opts = opts or {}
if vim.fn.isdirectory(".git") == 1 then
builtin.git_files(opts)
else
builtin.find_files(opts)
end
end
}
},
})
Simple rebind, will bind the the keys in both normal mode and insert mode.
mappings = {
next = "<Tab>",
prev = "<S-Tab>"
}
You can also bind keys in specific modes by supplying a list of key-mode pairs. The following would bind H and L to previous and next in normal mode in addition to binding tab and shift+tab like in the example above.
mappings = {
next = { { "L", "n" }, { "<Tab>", "n" }, { "<Tab>", "i" } },
prev = { { "H", "n" }, { "<S-Tab>", "n" }, { "<S-Tab>", "i" } }
}
If you want to group certain pickers together into separate search windows you can use the collections keyword:
local builtin = require('telescope.builtin')
require("search").setup({
initial_tab = 1,
tabs = { ... }, -- As shown above
collections = {
-- Here the "git" collection is defined. It follows the same configuraton layout as tabs.
git = {
initial_tab = 1, -- Git branches
tabs = {
{ name = "Branches", tele_func = builtin.git_branches },
{ name = "Commits", tele_func = builtin.git_commits },
{ name = "Stashes", tele_func = builtin.git_stash },
}
}
}
})
This plugin is licensed under the MIT License. See the LICENSE file for details.
Happy searching with search.nvim! 🚀