Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for selection in Vim

Check this Vim tip: Search for visually selected text

Or you can simply yank the selected text with y and go to search mode /, then you can paste the last yanked text with Ctrl+R 0


Answer

  1. Yank the text you want to search for
  2. q/p
  3. Enter

Explanation

q/ works similarly to vanilla search / except you're in command mode so p actually does "paste" instead of typing the character p. So the above will copy the text you're searching for and paste it into a search.

For more details type :help q/


Use q / instead of just /. (Same with q :). Now you can VIM-edit through your command and search history! (Try Ctrl-N and Ctrl-P sometime).


I just learned (through the excellent book Practical Vim) that there is a plugin for that. You can find the plugin on GitHub.

The plugin lets you search for a visual selection with * and #.