0

For my fortran ft I use

au BufWritePre <buffer> :silent %!fprettify --silent

in my ftplugin.

The fprettify is a python script with many command line options, using argparse.

Now, my question is, is it possible to set those option in vimrc and use the string using let in my ftplugin?

e.g. in .vimrc:

 fprettify_options = "--silent --strict-indent"

and in my ftplugin:

 let g:fprettify_options = get (g:, fprettify_options, "--strict")
 au BufWritePre <buffer> :silent %!fprettify g:fprettify_options

I am getting error:

directory g:fprettify_options does not exist!

This is probably because fprettify g:fprettify_options.

How can I pass the values to fprettify?

1

You should use :execute command to be able to construct command out of strings:

let g:fprettify_options = get (g:, fprettify_options, "--strict")
au BufWritePre <buffer> :execute 'silent %!fprettify ' . g:fprettify_options

Here I have just wrapped your example with :execute and a string concatenation.

'silent %!fprettify ' . g:fprettify_options would become 'silent %!fprettify --strict' and executed with execute.

| improve this answer | |

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.