Vim编辑
[TOC]
一、配置文件的位置
在目录 /etc/ 下面,有个名为vimrc的文件,这是系统中公共的vim配置文件,对所有用户都有效。而在每个用户的主目录下,都可以自己建立私有的配置文件,命名为:“.vimrc”。例如,/root目录下,通常已经存在一个.vimrc文件。常用系统的配置文件信息如下:
- 在Ubuntu中vim的配置文件存放在/etc/vim目录中,配置文件名为.vimrc
- 在Fedora中vim的配置文件存放在/etc目录中,配置文件名为vimrc
- 在Red Hat Linux 中vim的配置文件存放在/etc目录中,配置文件名为vimrc
- 在Mac os 系统下,用户根目录下,配置文件名为.vimrc
二、设置内容
-
set nocompatible "去掉有关vi一致性模式,避免以前版本的bug和局限
-
set nu "显示行号
-
set guifont=Luxi/ Mono/ 9 " 设置字体,字体名称和字号
-
filetype on "检测文件的类型
-
set history=1000 "记录历史的行数
-
set background=dark "背景使用黑色
-
syntax on "语法高亮度显示
-
set autoindent "vim使用自动对齐,也就是把当前行的对齐格式应用到下一行(自动缩进)
-
set cindent "(cindent是特别针对 C语言语法自动缩进)
-
set smartindent "依据上面的对齐格式,智能的选择对齐方式,对于类似C语言编写上有用
-
set tabstop=4 "设置tab键为4个空格,
-
set shiftwidth =4 "设置当行之间交错时使用4个空格
-
set ai! " 设置自动缩进
-
set showmatch "设置匹配模式,类似当输入一个左括号时会匹配相应的右括号
-
set guioptions-=T "去除vim的GUI版本中得toolbar
-
set vb t_vb= "当vim进行编辑时,如果命令错误,会发出警报,该设置去掉警报
-
set ruler "在编辑过程中,在右下角显示光标位置的状态行
-
set nohls "默认情况下,寻找匹配是高亮度显示,该设置关闭高亮显示
-
set incsearch "在程序中查询一单词,自动匹配单词的位置;如查询desk单词,当输到/d时,会自动找到第一个d开头的单词,当输入到/de时,会自动找到第一个以ds开头的单词,以此类推,进行查找;当找到要匹配的单词时,别忘记回车
-
set backspace=2 " 设置退格键可用
-
修改一个文件后,自动进行备份,备份的文件名为原文件名加“~”后缀
if has("vms") set nobackup else set backup endif
-
set mouse=a "鼠标可用"
如果设置完成后,发现功能没有起作用,检查一下系统下是否安装了vim-enhanced包,查询命令为:
$rpm -q vim-enhanced
注意:如果设置好以上设置后,VIM没有作出相应的动作,那么请你把你的VIM升级到最新版,一般只要在终端输入以下命令即可:sudo apt-get install vim
三、文字颜色的设置
请参考此文档
四、乱码解决方案
打开vimrc文件后,只需要在文件最后添加以下代码就可以了:
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8
set fileformats=unix
set encoding=prc
更多设置,here
阿里云vim配置
1 if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
2 set fileencodings=ucs-bom,utf-8,latin1
3 endif
4 set nu
5 set nocompatible " Use Vim defaults (much better!)
6 set bs=indent,eol,start " allow backspacing over everything in insert mode
7 "set ai " always set autoindenting on
8 "set backup " keep a backup file
9 set viminfo='20,\"50 " read/write a .viminfo file, don't store more
10 " than 50 lines of registers
11 set history=50 " keep 50 lines of command line history
12 set ruler " show the cursor position all the time
13
14 " Only do this part when compiled with support for autocommands
15 if has("autocmd")
16 augroup redhat
17 autocmd!
18 " In text files, always limit the width of text to 78 characters
19 " autocmd BufRead *.txt set tw=78
20 " When editing a file, always jump to the last cursor position
21 autocmd BufReadPost *
22 \ if line("'\"") > 0 && line ("'\"") <= line("$") |
23 \ exe "normal! g'\"" |
24 \ endif
25 " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
26 autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
27 " start with spec file template
28 autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
29 augroup END
31endif
32 if has("cscope") && filereadable("/usr/bin/cscope")
33 set csprg=/usr/bin/cscope
34 set csto=0
35 set cst
36 set nocsverb
37 " add any database in current directory
38 if filereadable("cscope.out")
39 cs add $PWD/cscope.out
40 " else add database pointed to by environment
41 elseif $CSCOPE_DB != ""
42 cs add $CSCOPE_DB
43 endif
44 set csverb
45 endif
46
47 " Switch syntax highlighting on, when the terminal has colors
48 " Also switch on highlighting the last used search pattern.
49 if &t_Co > 2 || has("gui_running")
50 syntax on
51 set hlsearch
52 endif
53
54 filetype plugin on
55
56 if &term=="xterm"
57 set t_Co=8
58 set t_Sb=^[[4%dm
59 set t_Sf=^[[3%dm
60 endif
61
62 " Don't wake up system with blinking cursor:
63 " http://www.linuxpowertop.org/known.php
64 let &guicursor = &guicursor . ",a:blinkon0"
网友评论