0

So I have made about 10/12 substitutions in my current file using %s/longpatternN//g. Unfortunately I have to apply these same substitutions in 10 or more of my files. I can access my last commands via up arrow. So I am trying to copy my last command pattern, build a sed command and put them in a shell script to automate this boring stuff. But it looks like my Git Bash not letting me select and copy these substitution command texts via my mouse in vim. So where can I access all history of my all recent vim commands? Can we access any files may be vim storing these commands into?

  • 2
    FWIW, I wouldn't bother writing a shell script that calls sed. You can just copy/write the commands directly into a commands.vim file and then run it on a file with vim -s commands.vim file.txt. Or put them in a function that you can call from within Vim. – Rich Feb 9 '18 at 9:27
1

You have a couple of options here. I thing Vim inside Git Bash can access the windows clipboard, so you can try the following: q: to enter to history 'edit' mode, then k many times as needed or search for your pattern with ?, and then 0v$ "+y Here + is the register for the clipboard. After the previos commands you can paste on the bash prompt without problem

And the other option is (on command prompt): cat $HOME/.viminfo | grep ':s'

Since $HOME/.viminfo contains information about your vim sessions, including commands.

But I also recommend to take a look on :h :bufdo and :h :argdo

  • 1
    I Just saw it would suffice with grep '%s' $HOME/.viminfo – rbernabe Feb 8 '18 at 20:41
  • 1
    Worth noting :& and & as well, i think – D. Ben Knoble Feb 9 '18 at 8:45

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.