Context. Complex (iso-)nitrile molecules, such as CH 3 CN and HC 3 N, are relatively easily detected in our Galaxy and in other galaxies. Aims. We aim at constraining their chemistry through observations of two positions in the Horsehead edge: the photo-dissociation region (PDR) and the dense, cold, and UV-shielded core just behind it. Methods. We systematically searched for lines of CH 3 CN, HC 3 N, C 3 N, and some of their isomers in our sensitive unbiased line survey at 3, 2, and 1 mm. We stacked the lines of C 3 N to improve the detectability of this species. We derived column densities and abundances through Bayesian analysis using a large velocity gradient radiative transfer model. Results. We report the first clear detection of CH 3 NC at millimeter wavelength. We detected 17 lines of CH 3 CN at the PDR and 6 at the dense core position, and we resolved its hyperfine structure for 3 lines. We detected 4 lines of HC 3 N, and C 3 N is clearly detected at the PDR position. We computed new electron collisional rate coefficients for CH 3 CN, and we found that including electron excitation reduces the derived column density by 40% at the PDR position, where the electron density is 1-5 cm −3 . While CH 3 CN is 30 times more abundant in the PDR (2.5 × 10 −10 ) than in the dense core (8 × 10 −12 ), HC 3 N has similar abundance at both positions (8 × 10 −12 ). The isomeric ratio CH 3 NC/CH 3 CN is 0.15 ± 0.02. Conclusions. The significant amount of complex (iso-)nitrile molecule in the UV illuminated gas is puzzling as the photodissociation is expected to be efficient. This is all the more surprising in the case of CH 3 CN, which is 30 times more abundant in the PDR than in the dense core. In this case, pure gas phase chemistry cannot reproduce the amount of CH 3 CN observed in the UV-illuminated gas. We propose that CH 3 CN gas phase abundance is enhanced when ice mantles of grains are destroyed through photo-desorption or thermal-evaporation in PDRs, and through sputtering in shocks.