微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何让vim显示BOM为

当我查看我们其中一个服务器上的文件时,我看到如下内容

<feff>sku;qty
productsku;1

当我下载文件并用vi打开它时,我看不到< feff>

当我这样做时:我可以看到< feff>但我现在也看到了^ M.

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

但我不想设置^ M.我只是想看看< feff>.
一个例子是< 80>我在另一个文件中.

我怎样才能设置vim来向我展示那些特殊的字符?

〜编辑〜

命令vi –version告诉我以下内容

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

它还说system-vimrc-file是/ etc / vimrc,它有以下内容

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

我复制了它并将其添加到我的〜/ .vimrc中,但这些更改都没有达到我想要的效果.如果有一些情况,我可能不得不玩这些.

有没有人知道是否还有其他文件,而不是在编辑文件时会读取的vi –version中所述的文件

解决方法

:help’bomb’解释了Vim的行为:

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.

所以,

:set fencs-=ucs-bom

关闭它,但编码检测也会被打破!根据我的实验,显式编码设置(via:edit enc = ucs2-le)也设置’炸弹’并删除< feff>标记.所以,这条大道无处可去.

备择方案

>正如您所知,以二进制模式编辑.我不推荐它,因为它有缺点.
>在状态行中包含指示.你必须寻找其他地方,但它总是可见的,而不仅仅是在文档的开头.强烈推荐作为Vim中的正确方法™.也很容易实现:

set statusline+=\ %{&bomb?'BOM':''}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐