— is there a way to copy up to a search term, _including_ the term?

 ̄綄美尐妖づ 提交于 2019-12-10 15:33:43

问题


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<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.


回答1:


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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3295278/is-there-a-way-to-copy-up-to-a-search-term-including-the-term

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!