I'd like to read the contents of a file, and put this into a variable - so I can later use it in a command.
How can I achieve this?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communitySee :help readfile()
:
Read file
{fname}
and return a |List|, each line of the file as an item. Lines are broken at NL characters. [...]
As general advice, try to get familiar with Vim's help system. In the beginning, it might be hard to find what you need in there, but once you get used to it, it's a very powerful way to quickly find what you need.
:helpgrep
can be helpful sometimes. Asking here is all good too! Just pointing out that Vim help system is one more resource you can use to find what you need.