I know that I can open a file through a pipe with vim with the following command:
cat myfile.txt | vim -
I also know that I can edit files on vim directly from the command line as the following:
vim -e myfile.txt -c ':%s/^/newstring-/g | x'
The last command will open a file, execute a Vim command and close it. I'd like to mix these two things together, editing a file through a pipe and passing the file content to a bash variable. Something like the following:
var=$(cat myfile.txt | vim - -e -c ':%s/^/newstring-/g | x')
Well, this last command doesn't work at all. It's just an example to represent the idea. Is it possible to do something like this with vim? Or I better off just write the content of my changes on a new file and then accessing that new file from the shell as the following:
vim -e myfile.txt -c ':execute "%s/^/newstring-/g | normal :wq! newfile.txt\<Enter>"'
This last command works fine... But I'd like to know if there's a more direct way of storing inside a variable the changes that I make with vim.