1

What to add to init.lua such that / set the CLI with:

  • / followed by the selected text if any
  • / otherwise
1
  • I took the freedom to reformulate your question. Feel free to discard my edition if I have misunderstood your demand :-) Commented Jun 10 at 5:00

1 Answer 1

0

I would do in Lua:

vim.api.nvim_set_keymap("v", "/", '"vy/<C-r>v', { noremap=true})

Or its equivalent in Vimscript (for init.vim):

vnoremap / "vy/<C-r>v

With this in Visual mode:

  • "vy yank the selection in the v register
  • / tiggers the search
  • <C-r>v paste the content of the v register into the command line

Plugin Suggestion:

You could be interested by the vim-visual-star-search plugin that extend the * search to the selected text.

In Vim if you hit * in Normal mode Vim searches for the next occurrence of the current word. With vim-visual-star-search if you hit * in Visual mode Vim searches for the next occurrence of the selected text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.