A short while back, after exporting my blog from WordPress to Hugo I noticed that there are some weird ^M character in some files as shown in the following screenshot in blue.

screenshot of text with ^M character

This is a special character, CTRL+M and can be removed using sed or vim. Normally, in vim we can reaplace a text with the following command:


So we should be able to replace ^M, by typing CTRL+V then CTRL+M with empty space with:


Since I have lots of random files containing ^M, it’d be easier to use sed from the command line as the following:

❯❯❯ sed -i 's/^M//g' *.md
  • -i or --in-plac edit files in places

Thanks to the tutorial found in the reference.