I am trying to write a script that will open a file in vim and copy a particular line in it into one of vim’s registers. When the script is run again, it will decide to open the file again and then paste the values in vim’s registers back in. Effectively, the script is supposed to toggle the value everytime it’s run.
For example, suppose I wanted to toggle the word “foo” into “bar” when I run the script, and then back to “foo” again if I run the script again. I can get to the word foo by doing:
vim '+/foo' myfilename
And I know that when I’m inside of vim, I can load ‘foo’ into the register ‘q’ by doing
"qyy
But the following command doesn’t work when checking my registers with :reg
vim '+/foo' '+"qyy' myfilename
What am I doing wrong? Thanks!
You’re trying to execute normal mode commands in command-line mode (this is what +arguments mean). The correct command-line to do what you want would be:
See
:help +cmdfor a detailed explanations of such arguments.