2

I searched SO extensively and I can't get to fix this: I'm trying to code a pathogen friendly python plugin in windows. The setup would be:

In \vimfiles\bundle\plugin I have a myscript.vim with:

let s:path = fnamemodify(resolve(expand('<sfile>:p')), ':h')

function! Up()
    pyfile my_script.py
endfunction

command Up :call Up()

then in the same directory I have my_script.py:

import vim
vim.current.buffer.append("here I am")

This setup only works when/if I load myscript.vim in Vim and run :so %. I get an error 'No such file or directory my_script.py', but from then on the the script runs fine.

What i gather here is that the s:path line, wich sets the path for the python script call, in myscript.vim doesnt get processed when I call the function, but once the script is run I have that path available.

What I'm doing wrong, and how do I fix this? Ty all

1 Answer 1

2

The answer was here, in when using "pyfile s:pyscript" it seems vim doesn't interpret "s:pyscript" as a variable (kudos to https://stackoverflow.com/users/200291/icktoofay) but i didnt grasp it at first glance.

The idea is to build a string with both the command pyfile and the path (including the script name), and then execute it:

So, outside the function, call:

let s:path = fnamemodify(resolve(expand('<sfile>:p')), ':h') . '\my_script.py

and then inside the function:

execute 'pyfile ' . s:path

notice there is a space after pyfile, so you're in fact 'building' the full command by a string concatenation before actually executing it.

Sign up to request clarification or add additional context in comments.

1 Comment

For more information on how this works: stackoverflow.com/questions/4976776/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.