gpt4 book ai didi

vim - 如何让 vim 将 BOM 显示为

转载 作者:行者123 更新时间:2023-12-04 19:02:15 31 4
gpt4 key购买 nike

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

<feff>sku;qty
productsku;1

当我下载文件并用 vi 打开它时,我看不到 <feff>
当我这样做时 :e ++bin我可以看到 <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

会关闭它,但是编码检测也被破坏了!根据我的实验,显式编码设置(通过 :edit ++enc=ucs2-le )也设置了 'bomb'并删除 <feff>标记。所以,这条大道无路可走。

备择方案
  • 正如您所发现的那样,以二进制模式进行编辑。我不会推荐它,因为它有缺点。
  • 包括状态行中的指示。您必须查看其他地方,但它始终可见,而不仅仅是在文档的开头。强烈推荐作为 Vim 中的正确方式™。也很容易实现:

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

    关于vim - 如何让 vim 将 BOM 显示为 <feff>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35226828/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com