You shouldn't define a function inside of main(). Move "void PWM0 (void)" and its associated code outside of main() or remove all the declaration syntax.
When you configure your peripheral pin select, the PWM functionality is generated by one of the output compare modules, not an analog comparator. As such, you need to change your PPS configuration to RPOR15bits.RP30R =
18; so Output Compare module #1 is selected.
OC1RS is used to set the period of your PWM signal and OC1R is used for pulse width. Assuming edge aligned mode, at time=0, the output pin of OC1 is set high and OC1TMR begins to increment based on your clock selection. When OC1TMR matches the value in OC1R, the output pin is set low. OC1TMR continues to increment until it matches OC1RS. When those values match OC1TMR is reset to zero, the output pin is set high, and the process starts all over again.
In your case, you are running at Fosc=8MHz and want a 5KHz PWM signal. Since you selected Fcy as your clock source and Fosc/2=Fcy, that means your timer will increment 4,000,000 times a second. To get 5KHz as per the datasheet: OC1RS = (Fcy/Fpwm)-1 = (4,000,000/5000)-1 = 799. You can then load any value into OC1R from 0-799 to set the dutycycle. OC1R = 399 would be roughly a 50% dutycycle.
The compare modules in the PIC you are using have lots of extra configurations to allow for synchronization and triggering that you don't need to worry about at the moment but they still need to be set up correctly to get basic PWM functionality. Here is how I would configure your output pin for a 5KHz 50% dutycycle waveform
Code:
RPOR15bits.RP30R = 18; //OC1 Output to Pin RF2 PWM0
OC1CON1 = 0; // Clear registers
OC1CON2 = 0;
OC1RS = 799; //5000Hz PWM period
OC1R = 399; //50% initial duty cycle
OC1CON2bits.SYNCSEL = 0b11111; //synchronized by itself
OC1CON1bits.OCTSEL = 0b111; //Peripheral clock is the source for output Compare
OC1CON1bits.OCM = 0b110; // Edge-aligned PWM mode on OC
Unless you want to change frequency, there should be no reason to chance the OC1RS value while operating. Dutycycle changes can be made on the fly by updating the value stored in OC1R.