2

I have this in a buffer:

aaa
bbb
ccc
ddd
eee

with the cursor on the first line. I do :execute 'normal! jV/ddd\<CR>y' which I expect should result in the middle three lines yanked. But what actually happens is it just ends up in visual mode on the second line with nothing yanked. What am I doing wrong?

5

The reason your command doesn't work is <cr> is not automatically expanded. Instead you need to use double quotes and a backslash.

execute "normal! jV/ddd\<CR>y"

Actually you don't really need to bother with visual mode here; what you want can be done using

2,/ddd/y

This means from second line, up till and including search for ddd, yank.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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