title: Why does the "script" command generate ^[ and ^M characters and how to remove them with vim search and replace?
body: <p>On linux, using the bash shell, when I use the script command, the generated file is called typescript. When I open that file with vim, each line contains the <strong>^M</strong> character, and several lines (due to my colored command prompt) contain a character <strong>^[</strong>. I would like to replace these characters with nothing, effectively removing them from the generated script.</p>
  
  <p>First, I tried <code>:%s/^[//gc</code>, <code>:%s/\^[//gc</code>, <code>:%s/\^\[//gc</code>, and a few other variants. None of them matched the <strong>^[</strong> character, so the search/replace didn't work.</p>
  
  <p>I also tried all these variants for the <strong>^M</strong> character with the same results. After some googling I discovered that the <strong>^M</strong> character is really the carriage return "\r". So then I tried <code>:%s/\\r//gc</code> and this worked for the <strong>^M</strong> character!</p>
  
  <p>I googled some more to try and figure out what the <strong>^[</strong> character is but have found nothing helpful.</p>
  
  <p><strong>2 questions</strong>:</p>
  
  <p>1) What is the <strong>^[</strong> character, and what is the appropriate regex to use in vim to search and replace it?</p>
  
  <p>2) Why, when using the script command on linux, does the generated script produce <strong>^M</strong> at the end of the line? This makes me think the linux script command is generating CRLF eol characters rather than just LF eol characters.</p>