I am trying search a part of some line which is yanked under visual mode.
What's the quickest way to do it in VIM? For exmaple,
Hello, #{1} world.
I press v enter visual mode and select llo, #{1} wor
at the line 1. Then I yanked the selected text by pressing y, and then, I am trying to search for the selected text by pressing /. That leads to the following questions:
A: How to past a yanked text when I am in search mode?
B: How to avoid the work of escaping characters for a search pattern?
Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.
To get into the Vim Visual Line mode, press “Shift+V” while you are in Vim's Normal mode.
A:
Ctrl-r 0.
B:
In addition to the Ctrl-r 0 trick, there's also Ctrl-r =, which lets you type in an expression to be evaluated and expands to the result.
/ (now the prompt looks like
/
)
Ctrl-R = (now the prompt looks like=
)escape(@0, '\^$*.~[')
Enter (now the prompt looks like/llo, #{1} wor
)
Enter
Note that @reg
means "the contents of register reg
", and register 0
is the the last yank or delete. I think that escapes all the characters which are special in vi regexps… in any case, you would probably prefer to make a mapping than to type that all in.
When you yank some text (and specify no register to yank it into), it goes to register 0. So, if you want to search for that yanked text, press ESC to get into normal mode and then
/CTRL-r0
(i.e. press /, then CTRL+r, then 0) to pull the content of register 0 into the search pattern.
Some notes:
:reg
and watch the register contents before deciding which register content to use for your search."2y
(:he v_y).X
) while in visual mode to search for that text.I've overriden the star command for the visual mode (NB: it requires one file from lh-vim-lib). It answers your need:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With