29110Feature request: Need a function to read a file into a variable
- Jun 27, 2002Hi all,
Currently to read a file into a variable from a Vim function, we have to use
either the following set of commands:
: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
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
The above two functions will help in writing some good Vim plugins.
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
- Next post in topic >>