"this line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
" debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
set nocompatible
" Vim5 and later versions support syntax highlighting. Uncommenting the
" following enables syntax highlighting by default.
if has("syntax")
syntax on " 语法高亮
endif
""set guifont=SimSun\ 10
colorscheme evening " elflord ron peachpuff default 设置配色方案,vim自带的配色方案保存在/usr/share/vim/vim72/colors目录下
" detect file type
filetype on
filetype plugin on
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
""set background=dark
set helplang=cn
"-------设置gvim菜单栏为中文----------
set langmenu=zh_CN.UTF-8
let $LANG = 'zh_CN.UTF-8'
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"have Vim load indentation rules and plugins according to the detected filetype
filetype plugin indent on
endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set ignorecase " 搜索模式里忽略大小写
"set smartcase " 如果搜索模式包含大写字符,不使用 'ignorecase' 选项。只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用。
set autowrite " 自动把内容写回文件: 如果文件被修改过,在每个 :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令时进行;用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令转到别的文件时亦然。
set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
set smartindent " 智能对齐方式
set tabstop=4 " 设置制表符(tab键)的宽度
set softtabstop=4 " 设置软制表符的宽度
set shiftwidth=4 " (自动) 缩进使用的4个空格
set cindent " 使用 C/C++ 语言的自动缩进方式
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式
"set backspace=2 " 设置退格键可用
set showmatch " 设置匹配模式,显示匹配的括号
"set linebreak " 整词换行
set whichwrap=b,s,<,>,[,] " 光标从行首和行末时可以跳到另一行去
"set hidden " Hide buffers when they are abandoned
set mouse=a "使用鼠标
set number "显示行号
"set previewwindow "标识预览窗口
set history=50 "历史记录50条
"----状态行设置--------
set laststatus=2
set ruler
set showcmd
set showmode
set incsearch
set hlsearch
"-----括号的设置--------
:inoremap ( ()<ESC>i
":inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
":inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
":inoremap ] <c-r>=ClosePair(']')<CR>
":inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function ClosePair(char)
if getline('.')[col('.')-1]==a:char
return "\<Right>"
else
return a:char
endif
endfunction
"=======================================================================
"------------- plugin setting ---------------------------
"=======================================================================
"-- ctags setting-------
" 按下F4重新生成tag文件,并更新taglist
map <F4> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR>
imap <F4> <ESC>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR>
set tags=tags;
set tags+=./tags "add current directory's generated tags file
set tags+=~/.vim/systags
"-- omnicppcomplete setting -----
" 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码
imap <F3> <C-X><C-O>
" 按下F2根据头文件内关键字补全
imap <F2> <C-X><C-N>
set completeopt=menu " 关掉智能补全时的预览窗口
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 0 " 是否自动选择第一个匹配项。当且仅当'completeopt'不为'longest'时候有效。0:不选第一项(缺省)。1:选择第一项并且插入到光标位置。2:选择第一项但是不插入到光标位子
let OmniCpp_NamespaceSearch = 2 " 命名空间查找控制。0:禁止查找命名空间。1:查找当前文件缓冲区的命名空间。2:查找当前文件缓冲区和包含文件中的命名空间
let OmniCpp_ShowPrototypeInAbbr = 1 " 是否显示补全提示缩略信息中显示函数原型
let OmniCpp_GlobalScopeSearch=1 "允许全局查找,0:禁止,1:允许(缺省)
let OmniCpp_DisplayMode=1 " 类成员显示控制(是否显示public,private,protected成员)。0:自动,1:显示所有成员
"let OmniCpp_DefaultNamespaces=["std"] "默认命名空间列表,项目用','隔开
let OmniCpp_ShowScopeInAbbr=1 " 选项用来控制匹配项所在域的显示位置。缺省下,omini显示的补全提示菜单总是将匹配项所在域信息显示在缩略信息最后一列。0:信息缩略中补显示匹配项所在域。1:显示匹配项所在域,并且移除缩略信息中最后一列.
let OmniCpp_ShowAccess=0 "是否显示访问控制信息('+','-','#')。1:显示。0:不显示。1:选择第一项并且插入到光标位子。2:选择第一项但是补插入光标位子。
"-- SuperTab--
let g:SuperTabRetainCompletionType=0
"0不记录上次补全方式,1记住,知道用其他补全命令改变,2记住,知道用ESC推出插入模式
let g:SuperTabDefaultCompletionType="<C-X><C-N>"
"设置按下【Tab】后的默认补全方式
"-- Taglist setting --
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=1 "实时更新tags
let Tlist_Inc_Winwidth=0
"-- WinManager setting --
let g:winManagerWindowLayout='FileExplorer|TagList' " 设置我们要管理的插件
""let g:persistentBehaviour=0 " 如果所有编辑文件都关闭了,退出vim
nmap wm :WMToggle<cr>
" -- MiniBufferExplorer --
let g:miniBufExplMapWindowNavVim = 1 " 按下Ctrl+h/j/k/l,可以切换到当前窗口的上下左右窗口
let g:miniBufExplMapWindowNavArrows = 1 " 按下Ctrl+箭头,可以切换到当前窗口的上下左右窗口
let g:miniBufExplMapCTabSwitchBufs = 1 " 启用以下两个功能:Ctrl+tab移到下一个buffer并在当前窗口打开;Ctrl+Shift+tab移到上一个buffer并在当前窗口打开;ubuntu好像不支持
"let g:miniBufExplMapCTabSwitchWindows = 1 " 启用以下两个功能:Ctrl+tab移到下一个窗口;Ctrl+Shift+tab移到上一个窗口;ubuntu好像不支持
let g:miniBufExplModSelTarget = 1 " 不要在不可编辑内容的窗口(如TagList窗口)中打开选中的buffer
"--fold setting--
" set foldmethod=syntax " 用语法高亮来定义折叠
" set foldlevel=100 " 启动vim时不要自动折叠代码
" set foldcolumn=5 " 设置折叠栏宽度
"-- QuickFix setting --
map <F1> :copen<CR><CR>
map <F5> :make<CR> :copen<CR><CR>
" 按下F5,执行make编译程序,并打开quickfix窗口,显示编译信息
map <F6> :cp<CR>
" 按下F6,光标移到上一个错误所在的行
map <F7> :cn<CR>
" 按下F7,光标移到下一个错误所在的行
map <F8> :make clean<CR><CR>
" 按下F8,执行make clean
" 以上的映射是使上面的快捷键在插入模式下也能用
imap <F1> <ESC>:copen<CR><CR>
imap <F5> <ESC>:make<CR> :copen<CR><CR>
imap <F6> <ESC>:cp<CR>
imap <F7> <ESC>:cn<CR>
imap <F8> <ESC>:make clean<CR><CR>
"-- Cscope setting --
if has("cscope")
set csprg=/usr/bin/cscope " 指定用来执行cscope的命令
set csto=0 " 设置cstag命令查找次序:0先找cscope数据库再找标签文件;1先找标签文件再找cscope数据库
set cst " 同时搜索cscope数据库和标签文件
set cscopequickfix=s-,c-,d-,i-,t-,e- " 使用QuickFix窗口来显示cscope查找结果
set nocsverb
if filereadable("cscope.out") " 若当前目录下存在cscope数据库,添加该数据库到vim
cs add cscope.out
elseif $CSCOPE_DB != "" " 否则只要环境变量CSCOPE_DB不为空,则添加其指定的数据库到vim
cs add $CSCOPE_DB
endif
set csverb
endif
""map <F4> :cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
""imap <F4> <ESC>:cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
" 将:cs find c等Cscope查找命令映射为<C-_>c等快捷键(按法是先按Ctrl+Shift+-, 然后很快再按下c)
nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-_>i :cs find i <C-R>=expand("<cfile>")<CR><CR> :copen<CR><CR>
" properly set to work with the Vim-related packages available in Debian.
" debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
set nocompatible
" Vim5 and later versions support syntax highlighting. Uncommenting the
" following enables syntax highlighting by default.
if has("syntax")
syntax on " 语法高亮
endif
""set guifont=SimSun\ 10
colorscheme evening " elflord ron peachpuff default 设置配色方案,vim自带的配色方案保存在/usr/share/vim/vim72/colors目录下
" detect file type
filetype on
filetype plugin on
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
""set background=dark
set helplang=cn
"-------设置gvim菜单栏为中文----------
set langmenu=zh_CN.UTF-8
let $LANG = 'zh_CN.UTF-8'
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"have Vim load indentation rules and plugins according to the detected filetype
filetype plugin indent on
endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set ignorecase " 搜索模式里忽略大小写
"set smartcase " 如果搜索模式包含大写字符,不使用 'ignorecase' 选项。只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用。
set autowrite " 自动把内容写回文件: 如果文件被修改过,在每个 :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令时进行;用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令转到别的文件时亦然。
set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
set smartindent " 智能对齐方式
set tabstop=4 " 设置制表符(tab键)的宽度
set softtabstop=4 " 设置软制表符的宽度
set shiftwidth=4 " (自动) 缩进使用的4个空格
set cindent " 使用 C/C++ 语言的自动缩进方式
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式
"set backspace=2 " 设置退格键可用
set showmatch " 设置匹配模式,显示匹配的括号
"set linebreak " 整词换行
set whichwrap=b,s,<,>,[,] " 光标从行首和行末时可以跳到另一行去
"set hidden " Hide buffers when they are abandoned
set mouse=a "使用鼠标
set number "显示行号
"set previewwindow "标识预览窗口
set history=50 "历史记录50条
"----状态行设置--------
set laststatus=2
set ruler
set showcmd
set showmode
set incsearch
set hlsearch
"-----括号的设置--------
:inoremap ( ()<ESC>i
":inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
":inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
":inoremap ] <c-r>=ClosePair(']')<CR>
":inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function ClosePair(char)
if getline('.')[col('.')-1]==a:char
return "\<Right>"
else
return a:char
endif
endfunction
"=======================================================================
"------------- plugin setting ---------------------------
"=======================================================================
"-- ctags setting-------
" 按下F4重新生成tag文件,并更新taglist
map <F4> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR>
imap <F4> <ESC>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR>
set tags=tags;
set tags+=./tags "add current directory's generated tags file
set tags+=~/.vim/systags
"-- omnicppcomplete setting -----
" 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码
imap <F3> <C-X><C-O>
" 按下F2根据头文件内关键字补全
imap <F2> <C-X><C-N>
set completeopt=menu " 关掉智能补全时的预览窗口
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 0 " 是否自动选择第一个匹配项。当且仅当'completeopt'不为'longest'时候有效。0:不选第一项(缺省)。1:选择第一项并且插入到光标位置。2:选择第一项但是不插入到光标位子
let OmniCpp_NamespaceSearch = 2 " 命名空间查找控制。0:禁止查找命名空间。1:查找当前文件缓冲区的命名空间。2:查找当前文件缓冲区和包含文件中的命名空间
let OmniCpp_ShowPrototypeInAbbr = 1 " 是否显示补全提示缩略信息中显示函数原型
let OmniCpp_GlobalScopeSearch=1 "允许全局查找,0:禁止,1:允许(缺省)
let OmniCpp_DisplayMode=1 " 类成员显示控制(是否显示public,private,protected成员)。0:自动,1:显示所有成员
"let OmniCpp_DefaultNamespaces=["std"] "默认命名空间列表,项目用','隔开
let OmniCpp_ShowScopeInAbbr=1 " 选项用来控制匹配项所在域的显示位置。缺省下,omini显示的补全提示菜单总是将匹配项所在域信息显示在缩略信息最后一列。0:信息缩略中补显示匹配项所在域。1:显示匹配项所在域,并且移除缩略信息中最后一列.
let OmniCpp_ShowAccess=0 "是否显示访问控制信息('+','-','#')。1:显示。0:不显示。1:选择第一项并且插入到光标位子。2:选择第一项但是补插入光标位子。
"-- SuperTab--
let g:SuperTabRetainCompletionType=0
"0不记录上次补全方式,1记住,知道用其他补全命令改变,2记住,知道用ESC推出插入模式
let g:SuperTabDefaultCompletionType="<C-X><C-N>"
"设置按下【Tab】后的默认补全方式
"-- Taglist setting --
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=1 "实时更新tags
let Tlist_Inc_Winwidth=0
"-- WinManager setting --
let g:winManagerWindowLayout='FileExplorer|TagList' " 设置我们要管理的插件
""let g:persistentBehaviour=0 " 如果所有编辑文件都关闭了,退出vim
nmap wm :WMToggle<cr>
" -- MiniBufferExplorer --
let g:miniBufExplMapWindowNavVim = 1 " 按下Ctrl+h/j/k/l,可以切换到当前窗口的上下左右窗口
let g:miniBufExplMapWindowNavArrows = 1 " 按下Ctrl+箭头,可以切换到当前窗口的上下左右窗口
let g:miniBufExplMapCTabSwitchBufs = 1 " 启用以下两个功能:Ctrl+tab移到下一个buffer并在当前窗口打开;Ctrl+Shift+tab移到上一个buffer并在当前窗口打开;ubuntu好像不支持
"let g:miniBufExplMapCTabSwitchWindows = 1 " 启用以下两个功能:Ctrl+tab移到下一个窗口;Ctrl+Shift+tab移到上一个窗口;ubuntu好像不支持
let g:miniBufExplModSelTarget = 1 " 不要在不可编辑内容的窗口(如TagList窗口)中打开选中的buffer
"--fold setting--
" set foldmethod=syntax " 用语法高亮来定义折叠
" set foldlevel=100 " 启动vim时不要自动折叠代码
" set foldcolumn=5 " 设置折叠栏宽度
"-- QuickFix setting --
map <F1> :copen<CR><CR>
map <F5> :make<CR> :copen<CR><CR>
" 按下F5,执行make编译程序,并打开quickfix窗口,显示编译信息
map <F6> :cp<CR>
" 按下F6,光标移到上一个错误所在的行
map <F7> :cn<CR>
" 按下F7,光标移到下一个错误所在的行
map <F8> :make clean<CR><CR>
" 按下F8,执行make clean
" 以上的映射是使上面的快捷键在插入模式下也能用
imap <F1> <ESC>:copen<CR><CR>
imap <F5> <ESC>:make<CR> :copen<CR><CR>
imap <F6> <ESC>:cp<CR>
imap <F7> <ESC>:cn<CR>
imap <F8> <ESC>:make clean<CR><CR>
"-- Cscope setting --
if has("cscope")
set csprg=/usr/bin/cscope " 指定用来执行cscope的命令
set csto=0 " 设置cstag命令查找次序:0先找cscope数据库再找标签文件;1先找标签文件再找cscope数据库
set cst " 同时搜索cscope数据库和标签文件
set cscopequickfix=s-,c-,d-,i-,t-,e- " 使用QuickFix窗口来显示cscope查找结果
set nocsverb
if filereadable("cscope.out") " 若当前目录下存在cscope数据库,添加该数据库到vim
cs add cscope.out
elseif $CSCOPE_DB != "" " 否则只要环境变量CSCOPE_DB不为空,则添加其指定的数据库到vim
cs add $CSCOPE_DB
endif
set csverb
endif
""map <F4> :cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
""imap <F4> <ESC>:cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
" 将:cs find c等Cscope查找命令映射为<C-_>c等快捷键(按法是先按Ctrl+Shift+-, 然后很快再按下c)
nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-_>i :cs find i <C-R>=expand("<cfile>")<CR><CR> :copen<CR><CR>