Reputation: 40553
I have the following Vim-function:
fu! Create_file_and_write_to_it(name, text)
new
execute "normal i" . a:text
execute "w! " + a:name
endfu
I call this function like so:
:call Create_file_and_write_to_it('c:\temp\foo.txt', "here is some text")
While it creates a new buffer and writes the desired text (ie: here is some text) into the buffer, it doesn't write the buffer to a file named c:\temp\foo.txt or any other name I could see. Neither do I get an error message.
Is there a reason for this behaviour, or am I doing something wrong, and how would I go about getting the desired functionality?
Upvotes: 0
Views: 125
Reputation: 32966
Unless a:text has some special sequences/mappings to be triggered, you could also have used put=a:text
Upvotes: 1
Reputation: 15896
Instead of
execute "w! " + a:name
do this:
exec "save! " . a:name
Worked for me
Upvotes: 1
Reputation: 40553
Never mind... I found it.
I should have written
execute "w! " . a:name
instead of
execute "w! " + a:name
Upvotes: 2