Improved-search.nvim

December 21, 2023 ยท View on GitHub

It's a Neovim plugin that improves the search experience.

It provides:

  • stable jump to next / previous search pattern (regardless of the last search direction)
  • search the word under the cursor without moving (like * or #)
  • search operator:
    • search text selected in visual mode (visual selection + operator)
    • search text provided by a motion (operator + motion)
    • it all works for a multiline search.

Preview

Search selected text

Current word search in place

Stable next / previous


Configuration example

local search = require("improved-search")

-- Search next / previous.
vim.keymap.set({"n", "x", "o"}, "n", search.stable_next)
vim.keymap.set({"n", "x", "o"}, "N", search.stable_previous)

-- Search current word without moving.
vim.keymap.set("n", "!", search.current_word)

-- Search selected text in visual mode
vim.keymap.set("x", "!", search.in_place) -- search selection without moving
vim.keymap.set("x", "*", search.forward)  -- search selection forward
vim.keymap.set("x", "#", search.backward) -- search selection backward

-- Search by motion in place
vim.keymap.set("n", "|", search.in_place)
-- You can also use search.forward / search.backward for motion selection.

Functions and operators

function / operatormodesdescription
stable_nextn, x, oSearch next pattern (regardless of a previous search direction)
stable_previousn, x, oSearch previous pattern (regardless of a previous search direction)
current_word[_strict]nSearch current word in-place
in_place[_strict]n, x, oIn-place search operator
forward[_strict]n, x, oForward search operator
backward[_strict]n, x, oBackward search operator
  • _strict postfix means that a search operator / function uses a pattern with word boundaries. In other words, the pattern is encapsulated with \< and \>.

Limitations:

  • Search text that is selected by visual block mode isn't work as expected.