If I have the following words
cat Oliver Louis
and the cursor is on "c", I can copy up to the beginning of Louis with y/Louis<开发者_C百科CR>
(where "CR" is the enter key), which will copy the string "cat Oliver ".
Is there a way to copy the search term, "Louis", as well, for a copied string of "cat Oliver Louis"? Thanks in advance.
Use the /e
modifier: y/Louis/e<CR>
. If you want to repeat the last search pattern, just leave it out: y//e<CR>
.
:help search-offset
Since the /
search is exclusive, it will select everything up to the match, but not including the match. (check :help exclusive
)
A more convenient way might be to use the inclusive f
and t
motion commands.
With the following line:
cat Oliver Louis
typing yfs
in normal mode will yank everything up to the letter "s", or in this case, cat Oliver Louis
Obviously, this isn't as convenient if the line is something like
cat Assassins Scissors
There are too many s's. In this case you might want to go into visual mode and either repeat the inclusive f
search motion by tapping ;
until you reach the last s. Or, as you suggested above, simply use w
preceded by the number of words you'd like to copy. In this case y3w
will work.
One way is to use look-behind assertions... but the syntax is rather ugly!
y/\(Louis\)\@<=
This doesn't look for Louis, but for a position preceded by the string Louis.
精彩评论