我的Vim配置(自动补全/树形文件浏览)

时间:2021-01-21 21:32:07

配置文件的下载路径在这里  http://files.cnblogs.com/files/oloroso/vim.configure.xz.gz

这实际上是一个 xz 格式的文件,添加的 gz 文件后缀是因为博客园上传文件的限制

我的Vim配置(自动补全/树形文件浏览)

.vimrc文件的内容如下

"==========================================================================
"======================= 基本显示设置 ==================================
"========================================================================== "---------------------------------------------------------------------------
" 行号与标尺
set ruler " 右下角显示光标位置的状态行
set number " 显示行号
set cursorline " 突出显示当前行 "设置行号的颜色和背景(这在设置了colorscheme可能会无效)
if has("gui_running")
highlight LineNr guifg=red " gui模式下字体颜色设置
highlight LineNr guibg=white " gui模式下背景颜色设置
else
highlight LineNr ctermfg=yellow " 彩色终端下字体颜色设置
highlight LineNr ctermbg=blue " 彩色终端下背景颜色设置
endif "---------------------------------------------------------------------------
" 制表符(设置所有的tab和缩进为4个空格)
set tabstop= " 设置tab键的宽度
set shiftwidth= " 换行时行间交错使用4个空格
" set cindent shiftwidth=4 " 自动缩进4空格
set softtabstop=
" set expandtab " 使用空格来替换tab
set smarttab " 开启新行时使用智能 tab 缩进 " set list " 显示Tab符,
" set listchars=tab:\|\ , " 使用一高亮竖线代替 把符号显示为 |
" set listchars=tab:>-,trail:-
" set listchars=tab:\|\ ,nbsp:%,trail:- " match LeaderTab /\t/ " 匹配行首tab "---------------------------------------------------------------------------
" 缩进
set autoindent " 设置自动缩进(即每行的缩进值与上一行相等)
set smartindent " 设置智能缩进 set cindent " 使用 C/C++ 语言的自动缩进方式
set cinoptions={,1s,t0,n-,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式 "---------------------------------------------------------------------------
" 行控制
set linebreak " 英文单词在换行时不被截断
set nocompatible " 设置不兼容VI
"set textwidth=80 " 设置每行80个字符自动换行,加上换行符
set wrap " 设置自动折行
"set nowrap " 设置不自动折行 "---------------------------------------------------------------------------
" 命令行与状态行
set laststatus= " 开启状态栏信息
set cmdheight= " 命令行的高度,默认为1,这里设为2
set showcmd "状态栏显示当前输入命令
set showmode "命令行显示vim当前模式 " 状态行显示的内容 [包括系统平台、文件类型、坐标、所占比例、时间等]
" set statusline=%{fugitive#statusline()}\ %F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %y%r%m%*%=\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
" set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v]\ [%p%%]\ [LEN=%L] " line color
" now set it up to change the status line based on mode
if version >=
au InsertEnter * hi StatusLine term=reverse ctermbg= gui=undercurl guisp=Magenta
au InsertLeave * hi StatusLine term=reverse ctermfg= ctermbg= gui=bold,reverse
endif function! InsertStatuslineColor(mode)
if a:mode == 'i'
hi statusline guibg=magenta
elseif a:mode == 'r'
hi statusline guibg=blue
else
hi statusline guibg=red
endif
endfunction au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertChange * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline guibg=green "---------------------------------------------------------------------------
"括号配对
set showmatch " 显示括号配对情况
set iskeyword+=_,$,@,%,#,- " 带有如下符号的单词不要被换行分割
"set wildmenu "打开 wildmenu 选项,启动具有菜单项提示的命令行自动完成。
"set matchpairs=(:),{:},[:],<:>
"set whichwrap=b,s,<,>,[,] "---------------------------------------------------------------------------
" 配色方案
"colorscheme default " 配色方案 "==========================================================================
"======================= 基本使用增强设置 ===============================
"========================================================================== " 搜索
set hlsearch " 开启高亮显示结果
set incsearch " 开启实时搜索功能(输入字符串就跳到匹配位置)
"set noincsearch " 关闭显示查找匹配过程
"set magic " Set magic on, for regular expressions
"set showmatch " Show matching bracets when text indicator is over them
"set mat=2 " How many tenths of a second to blink
set ignorecase " 搜索时无视大小写
set nowrapscan " 搜索到文件两端时不重新搜索 "---------------------------------------------------------------------------
" 备份与缓存
set nobackup
set nowb
"set noswapfile
set writebackup " 设置无备份文件 "---------------------------------------------------------------------------
" 自动完成
set complete=.,w,b,k,t,i
set completeopt=longest,menu " 只在下拉菜单中显示匹配项目,并且会自动插入所有匹配项目的相同文本
set autoread " 当文件在外部被修改,自动更新该文件 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 backspace= " 设置退格键可用
if has('mouse')
set mouse=a " 鼠标可用
endif
set ve=block "光标可以定位在没有实际字符的地方
"set fullscreen " 启动后自动全屏 "---------------------------------------------------------------------------
" 工作目录和剪贴板
set nocompatible " 关闭vi兼容模式
set hidden " 允许在有未保存的修改时切换缓冲区
"set relativenumber " 行标跟随
set clipboard+=unnamed " 共享外部剪贴板
set autochdir " 设定文件浏览器目录为当前目录 set history= "保存80条历史记录 "让vim记忆文件上次编辑的位置
autocmd BufReadPost *
\ if line("'\"")>&&line("'\"")<=line("$") |
\ exe "normal g'\"" |
\ endif "==========================================================================
"======================= 文件相关配置 ==================================
"========================================================================== " 文件类型相关
filetype indent on " 针对不同的文件类型采用不同的缩进格式
filetype plugin on " 针对不同的文件类型加载对应的插件
filetype plugin indent on
filetype on " for taglist "---------------------------------------------------------------------------
" 默认为 UTF-8 编码
"---------------------------------------------------------------------------
if has("multi_byte") "判断是否支持多字节
set encoding=utf- "设置编码为utf-8
" English messages only
"language messages zh_CN.utf-8
set fillchars+=stl:\ ,stlnc:\ if has('win32') "windows下
language english
let &termencoding=&encoding " 处理consle输出乱码
endif set fencs=utf-,gbk,chinese,latin1
set formatoptions+=mM
set nobomb " 不使用 Unicode 签名 if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
set ambiwidth=double
endif
else
echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif "---------------------------------------------------------------------------
" 编码设置
"---------------------------------------------------------------------------
"set fileencoding=utf-8
set encoding=utf- "缓冲编码
set fileencodings=utf-,cp936,gb18030,big5,gbk,euc-jp,latin1
set fileencoding=utf-
set termencoding=utf- "编码转换
"set fileformats=unix "---------------------------------------------------------------------------
" 换行符设置(win/unix)
" 将指定文件的换行符转换成 UNIX 格式
autocmd FileType php,javascript,html,css,python,vim,vimwiki set ff=unix " 自动载入VIM配置文件
" autocmd! bufwritepost vimrc source $MYVIMRC "==========================================================================
"======================= 代码折叠与语法高亮 =============================
"========================================================================== " Floding 折叠
"set foldmethod=syntax " 选择代码折叠类型
"set foldlevel=100 " 禁止自动折叠
"
set foldenable " Enables folding.
" 折叠方法
" manual 手工折叠
" indent 使用缩进表示折叠
" expr 使用表达式定义折叠
" syntax 使用语法定义折叠
" diff 对没有更改的文本进行折叠
" marker 使用标记进行折叠, 默认标记是 {{{ 和 }}}
set foldmethod=manual " Set fold method to 'manual'.
""set fdc= " Show where folds start and end, when they are opened.
"nnoremap @=((foldclosed(line('.')) < 0 )? 'zc':'zo') set foldtext=MyFoldText()
function! MyFoldText()
let line = getline(v:foldstart)
let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
return v:folddashes . sub
endfunction "---------------------------------------------------------------------------
" 语法高亮
syntax enable " 打开语法高亮
syntax on " 开启文件类型侦测
autocmd BufRead,BufNewFile *.txt setlocal ft=txt
autocmd BufRead,BufNewFile *.tpl setlocal ft=smarty " 支持 Smarty
autocmd BufRead,BufNewFile *.as setlocal ft=actionscript " 支持 ActionScript
autocmd BufRead,BufNewFile *.mxml set filetype=mxml
autocmd BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
autocmd BufRead,BufNewFile *.txtfmt set filetype=txtfmt
autocmd BufRead,BufNewFile *.php set filetype=php
autocmd BufRead,BufNewFile *.c set filetype=c
autocmd BufRead,BufNewFile *.go set filetype=go
autocmd BufRead,BufNewFile *.md set filetype=markdown autocmd BufNewFile,BufRead,BufEnter,WinEnter,FileType *.m,*.h setf objc " 增加 Objective-C 语法支持
" 为qml文件添加语法高亮
autocmd BufNewFile,BufRead *.qml set filetype=JavaScript " fencview 自动编码识别 :FencView 查看文件编码和更改文件编码
let g:fencview_autodetect= " 高亮字典dict
" 后面对应的是字典文件的路径
autocmd FileType javascript set dictionary=~/.vim/dict/javascript.dict
autocmd FileType css set dictionary=~/.vim/dict/css.dict "==========================================================================
"======================= 快捷键设置 ====================================
"========================================================================== " 设置','为leader快捷键
" let mapleader = ","
" let g:mapleader = ","
"
" " Ctrl + S 保存文件
" map <C-s> <ESC>:w <CR>
" imap <C-s> <ESC>:w <CR>
" vmap <C-s> <ESC>:w <CR>
"
" " Ctrl + C 选中状态下复制
" vnoremap <C-c> "+y
"
" " Ctrl + V 粘贴剪切板中的内容
" map <C-v> "+p
" imap <C-v> <esc>"+pa
" vmap <C-v> d"+P
"
" " 内容全选快捷键
" map <C-a> gg0vG$<cr>
"
" " nmap <C-t> :tabnew<cr>
" " nmap <C-p> :tabprevious<cr>
" " nmap <C-n> :tabnext<cr>
" " nmap <C-k> :tabclose<cr>
" " nmap <C-Tab> :tabnext<cr>
"
" " 选中一段文字并全文搜索这段文字
" vnoremap * y/<C-h>=escape(@", '\\/.*$^~[]')<CR><CR>
" vnoremap # y?<C-h>=escape(@", '\\/.*$^~[]')<CR><CR>
"
" " 对齐字体
" nnoremap <leader>av :'<,'>Align =<cr>
" nnoremap <leader>al :'<,'>left<cr>
" nnoremap <leader>ac :'<,'>center<cr>
" nnoremap <leader>ar :'<,'>right<cr>
"
" " 设置快速保存和退出
" " 快速保存为,s
" " 快速退出(保存)为,w
" " 快速退出(不保存)为,q
" nmap <leader>s :w!<cr>
" nmap <leader>w :wq!<cr>
" nmap <leader>q :q!<cr>
"
" inoremap <expr> <leader>x "\<C-X><C-O>"
"
" " plugins: markdown index
" nnoremap <leader>m :TocdownToggle<cr>
"
" "切换buffer
" nmap bn :bn<cr>
" nmap bp :bp<cr> "==========================================================================
"==========================================================================
"\\\\\\\\\\\\\\\\\\\\\\\\ 插件相关的配置 ///////////////////////////////
"==========================================================================
"========================================================================== "==========================================================================
"======================= Powerline ====================================
"==========================================================================
"设置powerline状态栏主题
set guifont=PowerlineSymbols\ for\ Powerline
set nocompatible
set t_Co= "设置256色
let g:Powerline_symbols = 'fancy' "==========================================================================
"======================= TagList ======================================
"========================================================================== " TagList 键入:Tlist开启
" if MySys() == "windows" "设定windows系统中ctags程序的位置
" let Tlist_Ctags_Cmd = 'ctags'
" elseif MySys() == "linux" "设定windows系统中ctags程序的位置
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
" endif
map <F4> :TlistToggle<cr>
let Tlist_Show_One_File = "不同时显示多个文件的tag,只显示当前文件的
let Tlist_Compact_Format = " 使用小窗口.
let Tlist_Exit_OnlyWindow = "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Enable_Fold_Column = " 使taglist插件不显示左边的折叠行
let Tlist_Use_Right_Window = "在右侧窗口中显示taglist窗口
"let Tlist_Use_Left_Window = 1 " Split to the left side of the screen.
let Tlist_GainFocus_On_ToggleOpen =
let Tlist_Inc_Winwidth = " 防止taglist改变终端窗口的大小
let Tlist_WinWidth = " taglist窗口宽度
let Tlist_Sort_Type = 'name' " 排序 name. " ---------------------------------------------------------------------------
" Plugin:
"---------------------------------------------------------------------------
"==========================================================================
"======================= ctags 文件加载 ===============================
"========================================================================== set tags=tags
set tags+=./tags " 添加当前工作目录下的ctags
set tags+=/usr/include/c++/cpptags "这是在系统的include目录下生成的 set tags+=/usr/include/qt5/qt5tags "qt5的
set tags+=~/pragrom_files/Qt5.4.1/5.4/gcc_64/include " 按下F5重新生成tag文件,并更新taglist
map <F5> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR>
imap <F5> <ESC>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR> " ctags 生成c++ tags文件的命令
" ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f cpptags "==========================================================================
"======================= omnicppcomplete ==============================
"==========================================================================
" 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码
imap <F3> <C-X><C-O>
" 按下F2根据头文件内关键字补全
imap <F2> <C-X><C-I>
set completeopt=menu,menuone " 关掉智能补全时的预览窗口
let OmniCpp_MayCompleteDot = " 在'.'号后是否自动运行omnicppcomplete给出提示信息。0/1, 缺省为1
let OmniCpp_MayCompleteArrow = " 在"->"后是否自动运行omnicppcomplete给出提示信息。0/1, 缺省为1
let OmniCpp_MayCompleteScope = " 在域标识符"::"后是否自动运行omnicppcomplete给出提示信息。0/1, 缺省为0
let OmniCpp_SelectFirstItem = " 是否自动选择第一个匹配项。仅当"completeopt"不为"longest"时有效。
" 0 : 不选择第一项(缺省)
" 1 : 选择第一项并插入到光标位置
" 2 : 选择第一项但不插入光标位置
let OmniCpp_NamespaceSearch = " 命名空间查找控制。0 : 禁止查找命名空间
" 1 : 查找当前文件缓冲区内的命名空间(缺省)
" 2 : 查找当前文件缓冲区和包含文件中的命名空间
let OmniCpp_ShowPrototypeInAbbr = " 是否是补全提示缩略信息中显示函数原型。0 : 不显示(缺省) 1 : 显示原型
let OmniCpp_GlobalScopeSearch= " 全局查找控制。0:禁止;1:允许(缺省)
let OmniCpp_DisplayMode= " 类成员显示控制(是否显示全部公有(public)私有(private)保护(protected)成员)。 0 : 自动 1 : 显示所有成员
let OmniCpp_DefaultNamespaces=["std"] " 默认命名空间列表,项目间使用','隔开。
let OmniCpp_ShowScopeInAbbr= " 选项用来控制匹配项所在域的显示位置。缺省情况下,omni显示的补全提示菜单中总是将匹配项所在域信息显示在缩略信息最后一列。
" 0 : 信息缩略中不显示匹配项所在域(缺省)
" 1 : 显示匹配项所在域,并移除缩略信息中最后一列
let OmniCpp_ShowAccess= "是否显示访问控制信息('+', '-', '#')。0/1, 缺省为1(显示)
let OmniCpp_LocalSearchDecl= "使用Vim标准查找函数/本地(local)查找函数。
"Vim内部用来在函数中查找变量定义的函数需要函数括号位于文本的第一列,而本地查找函数并不需要。 " 提示类型加载
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete "==========================================================================
"======================= NERDTree =====================================
"========================================================================== " plugin - NERD_tree.vim 以树状方式浏览系统中的文件和目录
" :NERDtree 打开NERD_tree :NERDtreeClose 关闭NERD_tree
" o 打开关闭文件或者目录 t 在标签页中打开
" T 在后台标签页中打开 ! 执行此文件
" p 到上层目录 P 到根目录
" K 到第一个节点 J 到最后一个节点
" u 打开上层目录 m 显示文件系统菜单(添加、删除、移动操作)
" r 递归刷新当前目录 R 递归刷新当前根目录
"---------------------------------------------------------------------------
let NERDTreeShowBookmarks= " 一直显示书签
let loaded_netrwPlugin = " 不启动netrw
let NERDTreeCaseSensitiveSort= " 让文件排列更有序
let NERDTreeHijackNetrw = " 输入:e filename不再显示netrw,而是显示nerdtree
let NERDTreeChDirMode = " 改变tree目录的同时不改变工程的目录
let NERDTreeWinPos = 'left' " NERDTree显示位置在窗口右侧
let NERDTreeWinSize = " NERDTREE的大小
let NERDTreeIgnore = [ '^\.svn$','^\.git$','\~$' ] " 忽略.svn .git的显示
" F3 NERDTree 切换
map <F3> :NERDTreeToggle<CR>
imap <F3> <ESC>:NERDTreeToggle<CR> "---------------------------------------------------------------------------
" Plugin: miniBufExplorer 多个文件切换 可使用鼠标双击相应文件名进行切换
" 在 Bufe 内
" <Tab> 向前循环切换到每个buffer名上
" <S-Tab> 向后循环切换到每个buffer名上
" <Enter> 在打开光标所在的buffer
" d 删除光标所在的buffer
"---------------------------------------------------------------------------
" let g:miniBufExplorerMoreThanOne=0 " 只显示一个,否则多窗口容易出错
" let g:miniBufExplMapWindowNavVim = 1 " 允许 MinBuf 使用 ctrl-h,j,k,l 来上下左右选择窗口
let g:miniBufExplMapWindowNavArrows = " 允许 MinBuf 使用 C-箭头来切换上下左右窗口
let g:miniBufExplMapCTabSwitchBufs = " 允许 MiniBuf 使用 Ctrl-Tab 和 Ctrl-S-Tab来向前向后切换标签
" let g:miniBufExplModSelTarget = 1