Copy string to vim register from terminal command line

I am trying to write a script that will open a file in vim and copy a specific line into it in one of the vim registers. When you run the script again, it decides to open the file again, and then reinsert the values ​​into the vim registers. In fact, the script should switch the value each time it is run.

For example, suppose I would like to switch the word "foo" to "bar" when I run the script, and then return to "foo" again if I run the script again. I can go to the word foo by doing:

vim '+/foo' myfilename 

And I know that when I'm inside vim, I can load 'foo' into the 'q' register by doing

 "qyy 

But when checking my registers, the following command does not work: reg

 vim '+/foo' '+"qyy' myfilename 

What am I doing wrong? Thanks!

+4
source share
1 answer

You are trying to execute normal mode commands in command line mode (this is what the + argument means). The correct command line that will do what you want is:

 vim '+/foo' '+normal "qyy' myfilename 

See :help +cmd for a detailed explanation of such arguments.

+6
source

All Articles