0

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?

1

See :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.

| improve this answer | |
  • Thanks! Was a bit difficult to search for though ('read' came up in many places). Will accept the answer once I can in a few minutes. – Chris Stryczynski Apr 22 at 18:13
  • @ChrisStryczynski Agreed finding something specific can be overwhelming... :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. – filbranden Apr 22 at 18:34

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.