I'm trying to write a command for adding a Python import line. The problem is that what's added it import a:name and not the module name.

Here's the code

func! PyImport(name)
    silent !isort -q -a a:name %
comm! -nargs=1 PyImport call PyImport(<f-args>)

I guess I need to someone expand a:name, couldn't find how to do it. Thanks!

1 Answer 1


Try it like this:

silent execute('!isort -q -a ' . a:name . ' ' . expand("%:p"))

This executes the given string. The expand("%:p") creates the fully qualified file name for the current file.

BTW: I would recommend to add set autoload before executing and set noautoload after it. That way the file will automatically be reloaded after execute. No need for e then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.