linux下vim问题

  1. 乱码问题
    locale -a 来显示当前Linux系统支持的所有的语言环境
    export LANG=zh_CN.UTF8

vim ~/.vimrc //如果.vimrc文件不存在则先创建
将以下内容写入.vimrc文件并保存退出即可:
set fencs=ucs-bom,utf-8,gbk,gb18030,utf-16,big5
set fenc=cp936
set encoding=utf-8
.vimrc中配置项解释:
fencs: 全称fileencodings,指vim尝试以何种编码方式打开目标文件。fencs可以同时设置多个
编码试,一般情况下把严格的编码放在前,宽松的编码方式放在后面。
fenc: 全称fileencoding,Vim在保存新建文件时会根据fileencoding的设置编码来保存。如果是打开已有文件,
Vim会根据打开文件时所识别的编码来保存,除非在保存时重新设置fileencoding。
enc: 全称encoding,是vim内部使用的字符编码方式。当我们设置了encoding之后,vim 内部所有的 buffer,
寄存器,脚本中的字符串等,全都使用这个编码。
vim 在工作的时候,如果编码方式与它的内部编码不一致,它会先把编码转换成内部编码。
如果工作用的编码中含有无法转换为内部编码的字符,在这些字符就会丢失。因此,
在选择 Vim 的内部编码的时候,一定要使用一种表现能力足够强的编码,
以免影响正常工作。
由于encoding选项涉及到 Vim 中所有字符的内部表示,
因此只能在 Vim 启动的时候设置一次。
在 vim 工作过程中修改encoding会造成非常多的问题。
如果没有特别的理由,
请始终将encoding设置为utf-8。
tenc: 全称termencoding,在终端环境下使用vim时,通过termencoding项来告诉vim终端所使用的编码。
对于图形界面下的gvim,它的显示不依赖TERM,因此termencoding对于它没有意义.

  1. 操作中断问题
    在linux下用vi或vim打开Test.java文件时
E325: ATTENTION  
  Found a swap file by the name ".Test.java.swp"  
    
       owned by: root   dated: Wed Dec  7 13:52:56 2011  
       file name: /var/tmp/Test.java  
       modified: YES  
       user name: root   host name: localhost  
       process ID: 26153 (still running)  
  While opening file "Test.java"  
         dated: Wed Dec  7 14:00:46 2011  
      NEWER than swap file!  
    
  (1) Another program may be editing the same file.  
    If this is the case, be careful not to end up with two  
    different instances of the same file when making changes.  
    Quit, or continue with caution.  
    
  (2) An edit session for this file crashed.  
    If this is the case, use ":recover" or "vim -r Test.java"  
    to recover the changes (see ":help recovery").  
    If you did this already, delete the swap file ".Test.java.swp"  
    to avoid this message.  
  "Test.java" 11L, 237C  
  Press ENTER or type command to continue

原因是在此次vi或vim操作前有过一次使用vi或vim 操作Test.java文件时出现了异常中断,所以在当前目录下产生了一个.Test.java.swp文件,这个文件使用ls命令查看不能发现,使用ls -a命令查看可以知道Test.java.swp是一个隐藏文件。
把该文件删除即可:

rm -rf .Test.java.swp

你可能感兴趣的:(linux下vim问题)