How to remove "^[[m" and "^[[32" characters in vim

Viewed 246

I want to get the list of the names of my merged branches into a file.

$ git branch --merged
  fix-typo
* master
  update-readme

However, when I write this output into a file and I open it with Vim, I find some unexpected characters:

$ git branch --merged > test
$ vim test
  fix-typo^[[m
* ^[[32mmaster^[[m
  update-readme^[[m

What are they and how can I remove the ^[[m and ^[[32 characters?

1 Answers

TL;DR; Use --no-color flag

git branch --no-color --merged 

Weird characters you see there are ASCI escape codes for coloring the terminal output. https://en.wikipedia.org/wiki/ANSI_escape_code#Colors The best way to get rid of them is to ask git to not produce them by using the --no-color flag. You will get plain text output then.

Also git should automatically resign from coloring output when it is redirected. At least it works as such in my case. (fish)

Related