Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help! Sourcing file in VIM

577 views
Skip to first unread message

Tom Bruhns

unread,
Mar 6, 2013, 12:48:27 AM3/6/13
to
I've used VIM for some years to do simple file creation and editing. Now I'm trying to get into VIM scripts. I can successfully enter ex commands directly in a VIM window, things like :echo and :let and even :function. However, when I put exactly the same command(s) into a file and :source that file, I'm consistently getting an error:
E471: Argument required

It's probably something really simple that I'm missing. Help!!?? Any ideas?

I get that even when the file I'm sourcing is simply

echo "Hello, World."

It appears that it's finding the file (:source "myfile.vim"), because if I give it an incorrect file name, I get a file-not-found error, as I'd expect.

Karel Miklav

unread,
Mar 6, 2013, 11:45:53 AM3/6/13
to Tom Bruhns

Tom Bruhns

unread,
Mar 6, 2013, 2:10:42 PM3/6/13
to Tom Bruhns
On Wednesday, March 6, 2013 8:45:53 AM UTC-8, Karel Miklav wrote:
> http://www.ibm.com/developerworks/library/l-vim-script-1/

OK, I figured out the problem. I thought that one of the ways I had tried was NOT putting quotes around the file name, but it was probably that I thought that there was no way it could work without quotes when there is a space in the complete path: C:\Program Files\... But I see now that it does! So the answer is to enter the full path to the file, but no quotes around it. Amazing how something this simple can have one running in circles and getting seriously frustrated! So in summary:
:source "file.vim" does not work.
:source "C:\program files\vim\file.vim" does not work
:source file.vim will work if you first set
the current directory with :cd <path-to-file>
:source C:\program files\vim\file.vim will work, assuming the file is there.

Perhaps that little synopsis will help some other fool that's stumbled across the same problem understanding what's going on.

Christian Brabandt

unread,
Mar 6, 2013, 2:36:44 PM3/6/13
to
On 2013-03-06, Tom Bruhns <k7...@msn.com> wrote:
> On Wednesday, March 6, 2013 8:45:53 AM UTC-8, Karel Miklav wrote:
>> http://www.ibm.com/developerworks/library/l-vim-script-1/
>
> OK, I figured out the problem. I thought that one of the ways I had tried was NOT putting quotes around the file name, but it was probably that I thought that there was no way it could work without quotes when there is a space in the complete path: C:\Program Files\... But I see now that it does! So the answer is to enter the full path to the file, but no quotes around it. Amazing how something this simple can have one running in circles and getting seriously frustrated! So in summary:
>:source "file.vim" does not work.
>:source "C:\program files\vim\file.vim" does not work
>:source file.vim will work if you first set
> the current directory with :cd <path-to-file>
>:source C:\program files\vim\file.vim will work, assuming the file is there.

Of course. The " is the comment char and so Vim is not seeing the file
argument you are providing.

Either use single quotes and don't escape the spaces or don't use quotes
and escape the path.

BTW, if you are interested in scripting, you might want to start reading
the vim_use mailinglist. It is incredibly interesting to get to know
advanced features of vim.

regards,
Christian

Bob Harris

unread,
Mar 7, 2013, 9:02:48 PM3/7/13
to
In article
<6cbace89-5bad-4821...@googlegroups.com>,
Within a "..." string, backslash \ is a magic character.

See: :help expr-string

So I'm thinking "C:\program files\vim\file.vim" turned into
"C:program filesvim<FormFeed>ile.vim"

Not exactly a Windows file path.

I think Vim would accept forward slash / as a path delimiter. Why
not give:

"C:/program files/vim/file.vim"

a try.

Tony Mechelynck

unread,
Mar 10, 2013, 4:59:54 PM3/10/13
to
I wouldn't have expected those paths-with-spaces to work, but I'm not on
Windows, I cannot test them on a Windows Vim.

I remember that when I was on Windows, I would use 8.3 names to avoid
problems with spaces, as in
:source C:\PROGRA~1\vim\file.vim
which works (and also works with / instead of \ separators), for your
last example above.

Here (on Linux),
:source ~/path\ with\ spaces/filename.ext
sources "path with spaces/filename.ext" under the current user's home
directory.


Best regards,
Tony.
--
BULLWINKLE: "You just leave that to my pal. He's the brains of the
outfit."
GENERAL: "What does that make YOU?"
BULLWINKLE: "What else? An executive..."
-- Jay Ward

0 new messages