Metal nanocomposites encapsulated in porous carbon have become a hot research that focus on electrocatalysis in energy conversion. The effective protection of carbon shell for the wrapped nanoparticles could allow them to avoid the dissolution and aggregation, and improve the durability of nanocomposites. In addition, the multi-heteroatom-doped carbon nanomaterials have unique electronic structure and lower local work function, which is conducive to the improvement of electrocatalytic performance in HER. Therefore, encapsulating transition metal sulfides within heteroatoms-doped carbon material is an efficient method to build electrocatalyst with high activity and long-term stability, in which all components can lead to an ideal activity due to the synergistic effects.