A direct search for the standard model Higgs boson, H, produced in association with a vector boson, V (W or Z), and decaying to a charm quark pair is presented. The search uses a data set of proton-proton collisions corresponding to an integrated luminosity of 35.9 fb−1, collected by the CMS experiment at the LHC in 2016, at a centre-of-mass energy of 13 TeV. The search is carried out in mutually exclusive channels targeting specific decays of the vector bosons: W → ℓν, Z → ℓℓ, and Z → νν, where ℓ is an electron or a muon. To fully exploit the topology of the H boson decay, two strategies are followed. In the first one, targeting lower vector boson transverse momentum, the H boson candidate is reconstructed via two resolved jets arising from the two charm quarks from the H boson decay. A second strategy identifies the case where the two charm quark jets from the H boson decay merge to form a single jet, which generally only occurs when the vector boson has higher transverse momentum. Both strategies make use of novel methods for charm jet identification, while jet substructure techniques are also exploited to suppress the background in the merged-jet topology. The two analyses are combined to yield a 95% confidence level observed (expected) upper limit on the cross section σ(VH)ℬ(H→cc¯) of 4.5 (2.4−0.7+1.0) pb, corresponding to 70 (37) times the standard model prediction.