Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let vim show BOM as <feff>

Tags:

vim

When I look at a file on one of our servers I see something like this:

<feff>sku;qty
productsku;1

When I download the file and open it with vi I don't see the <feff>

When I do :e ++bin I can see the <feff> but I also see ^M now

<feff>sku;qty^M
productsku;1^M

But I don't want to set the ^M. I just want to see the <feff>. Another example is <80> which I had in another file.

How can I set up vim to show me those special chars?

~ EDIT ~

The command vi --version tells me the following:

VIM - Vi IMproved 7.0 (2006 May 7, compiled Aug  4 2010 07:21:08)

It also says that the system-vimrc-file is /etc/vimrc which has the following content:

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=utf-8,latin1
endif

set term=builtin_ansi
set nocompatible    " Use Vim defaults (much better!)
set bs=indent,eol,start     " allow backspacing over everything in insert mode
"set ai         " always set autoindenting on
"set backup     " keep a backup file
set viminfo='20,\"50    " read/write a .viminfo file, don't store more
            " than 50 lines of registers
set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time

" Only do this part when compiled with support for autocommands
if has("autocmd")
  augroup redhat
    " In text files, always limit the width of text to 78 characters
    autocmd BufRead *.txt set tw=78
    " When editing a file, always jump to the last cursor position
    autocmd BufReadPost *
    \ if line("'\"") > 0 && line ("'\"") <= line("$") |
    \   exe "normal! g'\"" |
    \ endif
  augroup END
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != "" 
      cs add $CSCOPE_DB
   endif
   set csverb
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on 
  set hlsearch
endif

if &term=="xterm"
     set t_Co=8
     set t_Sb=^[[4%dm
     set t_Sf=^[[3%dm
endif

I copied this and added it to my ~/.vimrc but none of these changes does what I want. A few things are in if cases so I might have to play around with these too.

Does anyone know if there are other files than the one stated in vi --version that will be read when editing a file?

like image 458
Eydamos Avatar asked Feb 05 '16 14:02

Eydamos


1 Answers

:help 'bomb' explains Vim's behavior:

When Vim reads a file and 'fileencodings' starts with "ucs-bom", a check for the presence of the BOM is done and 'bomb' set accordingly. Unless 'binary' is set, it is removed from the first line, so that you don't see it when editing.

So,

:set fencs-=ucs-bom

would turn this off, but then the encoding detection is broken, too! According to my experiments, explicit encoding setting (via :edit ++enc=ucs2-le) also sets 'bomb' and removes the <feff> mark. So, this avenue leads nowhere.

Alternatives

  • Editing in binary mode, as you've found out. I wouldn't recommend it, since it has drawbacks.
  • Including the indication in the statusline. You have to look somewhere else, but it's always visible, not just at the beginning of the document. Highly recommended as the right way™ in Vim. And easy to achieve, too:
set statusline+=\ %{&bomb?'BOM':''}
like image 136
Ingo Karkat Avatar answered Nov 29 '22 14:11

Ingo Karkat