Loading ...
Sorry, an error occurred while loading the content.

29110Feature request: Need a function to read a file into a variable

Expand Messages
  • Yegappan Lakshmanan
    Jun 27, 2002
      Hi all,

      Currently to read a file into a variable from a Vim function, we have to use
      either the following set of commands:

      :read /path/to/file
      :let var = @"

      or, we have to use

      let var = system("cat /path/to/file")

      As this one uses the 'cat' command, this will work only in Unix. We have to
      replace 'cat' with 'type' for MS-Windows.

      Both of the above approaches look kludgy to me. We need a readfile()
      function which returns the contents of the file, so that we can use

      let var = readfile("/path/to/file")

      Similary, we need a function to write the contents of a variable into
      a file:

      call writefile("/path/to/file", var)

      Currently to write the contents of a variable to a file, we have to use:

      :redir! > /path/to/file
      :silent echo var
      :redir END

      The above two functions will help in writing some good Vim plugins.

      - Yegappan

      Do You Yahoo!?
      Yahoo! - Official partner of 2002 FIFA World Cup
    • Show all 4 messages in this topic