0

I am attempting to create a vimrc function that will be used in an autocmd. The function must simply call a python script and pass the file name as an argument.

.vimrc

fu! Test(filename)
    let filename = expand("%:t")
    "echom filename
    !test.py filename

example.py

#!usr/bin/python
import sys

print sys.argv[1]

If I uncomment the echo line, example.py is echo'd correctly. If I try to execute as it is displayed above, however, the string filename is passed literally.

Is there any way around this?

0

2 Answers 2

1

Sure, you can use the execute command to execute a string, which is built from the command you want and the variable concatenated together:

fu! Test()
    let filename = expand("%:t")
    execute "!test.py " . l:filename
endfunction

I've omitted the filename argument in your Test function because it doesn't seem to be used

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

Comments

1

You have two options either you pass the filename directly as an argument or pass it as a local variable:

fu! Test(filename)
    "echom a:filename
    execute "!test.py ".a:filename

or

fu! Test()
    let l:filename = expand("%:t")
    "echom filename
    execute "!test.py ". l:filename

Comments

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.