0

I am trying to set up code auto-formatting with astyle. I have read many posts such as this one (see Derek's answer) about how to auto-format, but I'm stuck on the "install astyle" part. I downloaded the .zip from here. Now I don't know what to do to get a command like this

autocmd BufNewFile,BufRead *.cpp set formatprg=astyle\ -T4pb

to work in my .vimrc. All I'm getting is the error "'astyle' is not recognized as an internal or external command, operable program or batch file."

EDIT: I have tried adding Astyle.exe to the system path (maybe I did that wrong??) and it still does not work.

Community
  • 1
  • 1
nullromo
  • 2,165
  • 2
  • 18
  • 39
  • Does running `astyle` work from a Win cmd prompt? And then, from Vim, the command `:echo executable('astyle')` must return 1 (btw you can use that to put your `autocmd` in a conditional: `if executable('astyle') | autocmd ... | endif` ). – VanLaser Sep 01 '15 at 21:35
  • No, running astyle in command prompt gives the same error message that vim gave. Also that command returns 0. – nullromo Sep 02 '15 at 00:20
  • So yes, you didn't add astyle's folder correctly to the Windows path. – VanLaser Sep 02 '15 at 06:05
  • Yes okay thank you! I moved the file and added the new location to the PATH and it works now. I probably just had a typo before. Also I needed to restart the shell. – nullromo Sep 02 '15 at 07:23

1 Answers1

0

The question's comments should suffice, but here's a formal answer:

You need to add astyle.exe's folder (\Astyle\bin) to the Windows PATH environment variable in order to use it in shells.

To add it, go to Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables -> click on Path and click Edit... -> use a semi-colon to separate different locations (so add ;C:\...\Astyle\bin to the end of the path) and then press OK 3 times.

nullromo
  • 2,165
  • 2
  • 18
  • 39