1

I see

alt text http://files.getdropbox.com/u/175564/fileformat-problem.png

where I have ^M and ^[ at various places. The former seems to be enter, while the latter apparently the end/beginning of the line.

I would like to get the purple symbols out such that I can read the log -file better.

I run

:set fileformats=unix,dos,mac
:e

but I get the same output.

How can you get the encoding/fileformat right?

3 Answers3

3

^[ is another representation for Escape (pressing Ctrl-[ is the same as pressing the escape key - the carat represents the control key). These are the beginning of ANSI color sequences. I don't think vim is going to show those colors (unless there's a filter that processes them).

There is a plugin for vim called AnsiEsc that will display the results of ANSI color sequences in a file. In order to install that plugin, you'll need to install the Vimball plugin first. In order to take full advantage of AnsiEsc, you'll need to recompile vim with the patch described on the AnsiEsc page.

You have to set the fileformats before the file is loaded (or in your .vimrc file). It won't apply it to a file that's already loaded.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
1

Alternative you can run s/\^M//g and s/\^[//g in vi to remove the offending characters but doesn't resolve the issue with the file handling. Do you know what encoding the file is using? You can guess by using file and it will give you info such as: "ASCII text, with CRLF line terminators"

NOTE: To enter the "^M" as "CTRL-V CTRL-M"

Chealion
  • 5,733
  • 28
  • 29
  • @Chealion: I have tried to use only the `fileformat=unix`. The file is screenlog.0 so the file extension is .0. --- Your command gives me `screenlog.0: UTF-8 Unicode English text, with very long lines, with CRLF, CR line terminators, with escape sequences, with overstriking`. – Léo Léopold Hertz 준영 Jul 04 '09 at 18:14
  • @Chealion: note that the "fileformat" option is different from the "fileformats" (plural) option. The former affects file writing; the latter affects file reading. – Greg Hewgill Jul 05 '09 at 00:08
  • @Greg My bad. Cleaned up my answer without the unnecessary bits. – Chealion Jul 05 '09 at 05:46
0

if it is an option you could try dos2unix (and its partner in crime unix2dos)

rev
  • 113
  • 1
  • 8