Context. We present a study of cyanoacetylene (HC 3 N) and cyanodiacetylene (HC 5 N) in Orion KL using observations from two line surveys performed with the IRAM 30-m telescope and the HIFI instrument onboard the Herschel telescope. The frequency ranges covered are 80−280 GHz and 480−1906 GHz. Aims. This study (divided by families of molecules) is part of a global analysis of the physical conditions of Orion KL and the molecular abundances in the different components of this cloud. Methods. We modeled the observed lines of HC 3 N, HC 5 N, their isotopologues (including DC 3 N), and vibrational modes using a non-local thermodynamic equilibrium (non-LTE) radiative transfer code. In addition, to investigate the chemical origin of HC 3 N and DC 3 N in Orion KL, we used a time-dependent chemical model. Results. We detect 40 lines of the ground vibrational state of HC 3 N and 68 lines of its 13 C isotopologues. We also detect 297 lines of six vibrational modes of this molecule (ν 7 , 2ν 7 , 3ν 7 , ν 6 , ν 5 , and ν 6 +ν 7 ) and 35 rotational lines of the ground vibrational state of HC 5 N. We report the first tentative detection of DC 3 N in a giant molecular cloud. We have obtained a DC 3 N/HC 3 N abundance ratio of 0.015 ± 0.009, similar to typical D/H ratios of cold dark clouds. We provide column densities for all species and derived isotopic and molecular abundances. We also made a 2 × 2 map around Orion IRc2 and present maps of the HC 3 N lines with energies from 34 to 154 K and of the HC 3 N vibrational modes ν 6 and ν 7 with energies between 354 and 872 K. In addition, a comparison of our results for HC 3 N with those in other clouds has allowed us to derive correlations between the column density, the FWHM, the mass, and the luminosity of the clouds. Conclusions. The high column densities of HC 3 N obtained in the hot core, in particular of the ground vibrational state and the vibrational mode ν 7 , make this molecule an excellent tracer of hot and dense gas. In addition, the wide frequency range covered reveals the need to consider a temperature and density gradient in the hot core to obtain better line fits. The high D/H ratio (similar to that obtained in cold clouds) that we derive suggests a deuterium enrichment. Our chemical models indicate that the possible deuterated HC 3 N in Orion KL is formed during the gas-phase. This fact provides new hints concerning the processes leading to deuteration.