首先,在root用户下找到根目录下的/etc/,有一个vimrc的文件,这个文件就是我们要配置的文件。
#cd /etc/
打开vimrc文件:
#vim vimrc
以下是我完成的一个配置,可以按照个人需求来配置。
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
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
" 自动语法高亮
syntax on
" 检测文件类型
filetype on
" 检测文件类型插件
"filetype plugin on
" set whichwrap+=<,>,h,l
" 显示行号
set number
" 上下可视行数
set scrolloff=5
" replace tab with space
set expandtab
" 设定 tab 长度为 4
set tabstop=4
" 设置按BackSpace的时候可以一次删除掉4个空格
set softtabstop=4
" 设定 << 和 >> 命令移动时的宽度为 4
set shiftwidth=4
set smarttab
"set history=1024
" 不突出显示当前行
set nocursorline
" " 覆盖文件时不备份
set nobackup
" 自动切换当前目录为当前文件所在的目录
set autochdir
" 搜索时忽略大小写,但在有一个或以上大写字母时仍大小写敏感
" set ignorecase
" set smartcase
" " 搜索到文件两端时不重新搜索
set nowrapscan
" " 实时搜索
" set incsearch
" 搜索时高亮显示被找到的文本
set hlsearch
" " 关闭错误声音
set noerrorbells
set novisualbell
" 不自动换行
"set nowrap
" "How many tenths of a second to blink
" set mat=2
" " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
" set hidden
" 智能自动缩进
set smartindent
" 设定命令行的行数为 1
set cmdheight=1
" " 显示状态栏 (默认值为 1, 无法显示状态栏)
set laststatus=2
" "显示括号配对情况
set showmatch
" " 解决自动换行格式下,
" 如高度在折行之后超过窗口高度结果这一行看不到的问题
set display=lastline
" " 设定配色方案
colorscheme evening
" " 设置在状态行显示的信息
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\
"[%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %c:%l/%L%)
" 显示Tab符
set list
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
" "启动时不显示 捐赠提示
set shortmess=atl
"Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" 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
" don't write swapfile on most commonly used directories for NFS mounts or USB st icks
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/v ar/tmp,/tmp
" start with spec file template
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
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 $PWD/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
filetype plugin on
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif
" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"
最后保存该文件,就完成vim的配置了。