您的位置:首页 > 运维架构 > Linux

CentOS6 下Vim安装和配置

2015-08-03 11:30 309 查看
1.系统只安装了vim-minimal,执行以下命令安装另外两个组件

yum install vim-common
yum install vim-enhanced


2.安装ctags

yum install ctags


下载linux-2.6.32.27内核源码并解压到~/arm/linux-2.6.32.27,进入该目录,生成索引文件

ctags -R *


3.安装插件(基本上就是解压到~/.vim目录):taglist/nerdcommenter/omnicppcomplete/echofunc/bufexplorer/winmanager

4.配置文件

" 关闭vi的键盘模式
set nocompatible
" 关闭备份
set nobackup
" 禁止生成临时文件
set noswapfile

" 允许使用鼠标定位和选择
set mouse=a
set selection=exclusive
set selectmode=mouse,key

" 显示行号
set number
" 禁止折行
set nowrap

" 突出显示当前行
"set cursorline cursorcolumn

" 切换文件时自动保存当前改动文件
set autowrite

" 设置状态栏显示的内容
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
" 设置总是显示状态栏
"set laststatus=2

" 光标移动到顶部和底部时保持3行距离
set scrolloff=3

" 检测文件类型
filetype on
filetype plugin on

" 设置编码
set encoding=utf-8
set termencoding=utf-8
set fileencodings=ucs-bom,utf-8,gbk,gb2312,cp936
set fileencoding=utf-8

" 设置语言
set langmenu=zh_CN.UTF-8
set helplang=cn

" 设置tab
set noexpandtab  " 不将tab扩展成空格
set tabstop=2    " 一个tab显示出来是多少个空格
set shiftwidth=2 " 每一级缩进多少个空格
set smarttab     " 根据文件中其他地方的缩进空格个数来确定一个tab是多少个空格

" 设置缩进
set nocindent     " 关闭cindent缩进方式
"set cindent       " 开启C/C++语言的缩进方式
"set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s " 设置C/C++语言的具体缩进方式
set noautoindent  " 关闭autoindent缩进方式
set nosmartindent " 关闭smartindent缩进方式

if has("autocmd")
filetype plugin indent on

autocmd FileType text setlocal textwidth=78
autocmd FileType text set nocindent
autocmd FileType html set formatoptions+=tl
autocmd FileType css set smartindent
autocmd FileType c,cpp,slang,esqlc set cindent
endif

" 语法高亮
syntax enable
syntax on

" 设置配色
colorscheme desert
"colorscheme darkblue
"colorscheme peachpuff

" 搜索忽略大小写
set ignorecase
" 如果搜索模式包含大写字母则忽略'ignorecase'选项
set smartcase
" 搜索逐字符高亮
set hlsearch
set incsearch

" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1

" --ctags settings--
map <F12> :!ctags -R --c++-kinds=+p --fields=+ialS --extra=+q .<CR><CR> :TlistUpdate<CR>
imap <F12> <ESC>:!ctags -R -c++kinds=+p --fields=+ialS --extra=+q .<CR><CR> :TlistUpdate<CR>
set tags=tags
set tags+=~/arm/linux-2.6.32.27/tags " add the linux kernel source's tags file
set tags+=./tags " add current directory's generated tags file

" --OmniCppComplete settings--
imap<F3> <C-X><C-O>
set completeopt=menu,menuone   " 关闭智能补全时的预览窗口
let OmniCpp_MayCompleteDot=1   " autocomplete with .
let OmniCpp_MayCompleteArrow=1 " autocomplete with ->
let OmniCpp_MayCompleteScope=1 " autocomplete with ::
let OmniCpp_SelectFirstItem=2  " select first item, but don't insert
let OmniCpp_NamespaceSearch=2  " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr=1 " show function prototype in popup window
let OmniCpp_GlobalScopeSearch=1 " enable the global scope search
let OmniCpp_DisplayMode=1       " class scope completion mode: always show all members
"let OmniCpp_DefaultNamespaces=["std"]
let OmniCpp_ShowScopeInAbbr=1   " show scope in abbreviation and remove the last column
let OmniCpp_ShowAccess=1

" --Taglist settings--
let Tlist_Ctags_Cmd='ctags'
let Tlist_Use_Right_Window=1
let Tlist_Show_One_File=0        " 允许同时显示多个文件的函数列表
let Tlist_File_Fold_Auto_Close=1 " 非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1      " 当Taglist是最后一个分割窗口时,自动退出vim
let Tlist_Process_File_Always=1  " 实时更新tags
let Tlist_Inc_Winwidth=0
let Tlist_WinWidth=40
"nmap tl :Tlist<CR>

" --BufExplorer settings--
let g:bufExplorerDefaultHelp=0      " Do not show default help.
let g:bufExplorerShowRelativePath=1 " Show relative paths.
let g:bufExplorerSortBy='mru'       " Sort by most recently used.

" --WinManager setting--
let g:winManagerWindowLayout='BufExplorer|FileExplorer' " 设置我们要管理的插件
let g:persistentBehaviour=0 " 如果所有编辑文件都关闭了,退出vi
let g:winManagerWidth=30
nmap wm :TlistToggle<CR> :WMToggle<CR>

" --QuickFix settings--
"map <F7> :make<CR> :copen<CR>
"map <F8> :cp<CR>
"map <F9> :cn<CR>
"imap <F7> <ESC>:make<CR> :copen<CR>
"imap <F8> <ESC>:cp<CR>
"imap <F9> <ESC>:cn<CR>

" --Fold settings--
function! ToggleFold()
if foldlevel('.')==0
normal! l
else
if foldclosed('.')<0
. foldclose!
else
. foldopen!
endif
endif
" clear status line
echo
endfunction

noremap <space> :call ToggleFold()<CR>

function FoldBrace()
if getline(v:lnum+1)[0]=='{'
return 1
endif
if getline(v:lnum)=~'{'
return 1
endif
if getline(v:lnum)[0]=~'}'
return '<1'
endif
return -1
endfunction

if has("autocmd")
autocmd BufReadPost *.h,*.hh,*.c,*.ec,*.cpp,*.hpp,*.ecpp,*.pc set foldexpr=FoldBrace()
autocmd BufReadPost *.h,*.hh,*.c,*.ec,*.cpp,*.hpp,*.ecpp,*.pc set foldmethod=expr
autocmd BufReadPost *.h,*.hh,*.c,*.ec,*.cpp,*.hpp,*.ecpp,*.pc set foldenable
endif

" --Terminal color settings--
hi Folded term=standout cterm=bold ctermfg=DarkGreen ctermbg=NONE
hi IncSearch term=bold ctermfg=red ctermbg=black
hi Search term=bold ctermfg=red ctermbg=black
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: