[问题]vim奇怪的乱码问题

Vim、Emacs配置和使用
回复
头像
Stupid kid
帖子: 417
注册时间: 2006-10-18 12:57
送出感谢: 0
接收感谢: 0

[问题]vim奇怪的乱码问题

#1

帖子 Stupid kid » 2007-07-11 21:32

症状

代码: 全选

用vim编辑文本(好像有中文的时候),可以正常显示乱码,但是在q或者wq后就会出现gnome-terminal显示乱码字符的现象,然后再打开刚才的那个文本,有时可以正常显示,有时却有失乱码
可能的原因

代码: 全选

确切的说,不知道;基本上我都没有动过什么配置,只是
在/etc/vim/vimrc里加了<br />
let &termencoding=&encoding<br />
set fileencodings=utf-8,gbk,ucs-bom,cp936<br />
.vimrc内容如下

if version >= 603
set helplang=cn
endif

set nu

" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2002 Sep 19
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp

" 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

" Only do this part when compiled with support for autocommands.
if has("autocmd")

" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!

" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78

" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif

augroup END

else

set autoindent " always set autoindenting on

endif " has("autocmd")

呵呵,不知道有没有其他人遇到这种情况,各位帮忙!
http://twitter.com/nothining
Mail: bjdfzster@gmail.com
南京的开源活动几乎是0,希望能有人组织下(也可以拉我入伙^_^)
最近在从零开始学习Linux程序设计,加油……
头像
aqua203
帖子: 283
注册时间: 2007-03-01 21:04
来自: 福建
送出感谢: 0
接收感谢: 0

#2

帖子 aqua203 » 2007-07-11 23:16

"字符编码,显示中文

代码: 全选

set encoding=UTF-8
set helplang=cn
let &termencoding=&encoding
set fileencodings=cp936,utf-8,ucs-bom,gb18030,gbk,gb2312
Feisty/Athlon1800+/512M/80G/MX440/SIS746
Linux 不是Windows
www.pendriverlinux.com
www.puppyos.com
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙
送出感谢: 4 次
接收感谢: 256 次

#3

帖子 eexpress » 2007-07-12 9:22

set fencs=utf-8,cp936,gb18030,gbk,gb2312
● 鸣学
xiechy
帖子: 1074
注册时间: 2006-01-18 15:01
送出感谢: 0
接收感谢: 1 次

#4

帖子 xiechy » 2007-07-12 11:42

楼上两位可能理解有点问题吧,其实这不是vim的毛病,例如说如果你用konsole就没问题。实际上这是gnome-terminal的问题。在sir上看到过,只要在gnome-terminal的

配置文件-->标题和命令-->标题

中把
“终端”
两字的前后各加一个英文空格即可。
头像
Stupid kid
帖子: 417
注册时间: 2006-10-18 12:57
送出感谢: 0
接收感谢: 0

#5

帖子 Stupid kid » 2007-07-12 15:05

xiechy 写了:楼上两位可能理解有点问题吧,其实这不是vim的毛病,例如说如果你用konsole就没问题。实际上这是gnome-terminal的问题。在sir上看到过,只要在gnome-terminal的

配置文件-->标题和命令-->标题

中把
“终端”
两字的前后各加一个英文空格即可。
呵呵,我的标题是 terminal



又发现了一些新的情况,或者说更详细的情况

出现这种乱码的情况都是我从ftp里下载了一些电视或者电影什么的,文件夹是以中文命名的,
我在文件家里写了文件readme,内容是中文的!

当我把文件夹名改为e文时,再用vim看readme就不会出现本帖所描述的问题,所以问题应该在下载的文件夹上,呵呵,谢谢各位热心的回复!
http://twitter.com/nothining
Mail: bjdfzster@gmail.com
南京的开源活动几乎是0,希望能有人组织下(也可以拉我入伙^_^)
最近在从零开始学习Linux程序设计,加油……
回复

回到 “Vim和Emacs”