kennedyl kennedyl - 1 year ago 97
Python Question

Using vimrc function to pass python arguments

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.


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

import sys

print sys.argv[1]

If I uncomment the echo line, "" 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?

Answer Source

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 "! " . l:filename

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download