There have been a few threads lately where people are asking which wires to keep and which wires to change when swapping in a 4.0 so I typed up my wiring notes from when I swapped out my '87 4.2 for a '95 XJ 4.0. I'm not sure if someone else has already done this, but from the number of questions I've seen lately I figured it couldn't hurt to share what I did as clearly as possible.
As most have figured out, all wires in the right side of the bulkhead connector feed front lights, horn, etc., and do not need to be touched. This list will only deal with the left side of the connector.
"(12 - BLK/RED)" means black 12 gauge wire with red tracer
"(18 - YEL/)" means yellow 18 gauge wire with tracer (usually black or white)
"(18 - VIO)" means violet 18 gauge wire (no tracer)
1987 YJ Wires That I Kept in the Bulkhead Connector
C6 (18 - YEL/): Provides power to the backup light switch.
F4 (14 - ORN/): Connects to heater blower motor.
C5 (18 - GRN/): Connects to negative side of ignition coil for tachometer signal.
F5 (18 - LT GRN): Connects to oil pressure gauge sending unit.
C4 (18 - VIO): Connects to temperature gauge sending unit.
A4 (20 - GRY/): Connects to low brake pressure switch near master cylinder.
B6 (18 - GRY/): Also connects to low brake pressure switch.
H6 (18 - BLK/): Connects to 4WD indicator switch.
G6 (18 - BRN/): Takes power from backup light switch for backup lights.
E5 (16 - PINK/): Provides power for under hood lamp.
"XJ E4 to YJ D4" means I removed the wire from cavity E4 on the XJ bulkhead connector, and inserted it into cavity D4 on the YJ bulkhead connector.
"PDC" means Power Distribution Center (engine bay fuse/relay panel from XJ).
1995 XJ Engine Harness Wires I Connected to YJ Bulkhead Connector
XJ E4 to YJ D4 (12 - RED): Always hot, provides power from PDC fuse 6 (labeled 'Ignition System') to ignition switch.
XJ H2 to YJ G5 (18 - YEL): Hot in start, provides power from ignition switch to PDC starter relay.
XJ D2 to YJ G4 (12 - BLK/RED): Always hot, provides power from PDC fuse 7 (labeled 'Heated Window') to interior 'Rear Defroster' fuse.
XJ C4 to YJ B4 (14 - DRK GRN/TAN): Provides power from PDC relay B (labeled 'Fuel Pump') to the (you guessed it) fuel pump. Of course you'll have to add a fuel pump, but the wiring is already back there for one.
XJ B6 to YJ D5 (12 - DRK BLU/YEL): Hot in run and start, provides power from ignition switch to PDC fuse 11 (labeled 'Ignition').
XJ D1 to YJ E4 (12 - RED/WHT): Always hot, provides power from PDC fuse 5 (labeled 'Headlamps') to interior Headlamp, Dimmer Switch, and Parking Lamp fuses.
XJ G4 to YJ B5 (12 - BLK): Provides grounding from engine compartment to instrument panel.
Additional Wires I Ran
From ECM pin 32 (20 - BLK/PNK) to dash for Check Engine Light.
From ECM pin 36 (20 - DRK GRN/YEL) to dash for Check Gauges Light.
From ECM pin 54 (20 - ORN/BLK) to dash for Up-Shift Light.
From PDC 'Radiator Fan' relay (16 - LT GRN) to my electric cooling fan.
It seems like a lot of people fear the wiring for these swaps the most, but after I spent some time mapping out the diagrams it didn't seem half bad. This is how I have mine set up and it started right up on the first try, and everything inside and out works 100%. Hopefully this info helps out others working on similar swaps.