我的Vim配置文件

My Vim Runconfig

Posted by Scalpel on March 28, 2016

配置Clang complete实现自动补全

let g:clang_library_path="/usr/lib/llvm-3.8/lib"
let g:clang_auto_select=1 "select first entry in popup menu but don't insert in code
let g:clang_complete_auto=1 "auto complete after -> . and ::
let g:clang_complete_copen=1
set completeopt=menu,longest
"let g:clang_periodic_quickfix=1
"let g:clang_complete_hl_errors=1 "highlight errors and warnings
let g:clang_snippets=1
let g:clang_close_preview=1
let g:clang_use_library=1
let g:clang_trailing_placeholder=1 "add trailing placeholder after function
let g:clang_user_options='-std=c++14 -IIncludePath'
let g:neocomplcache_enable_at_startup = 1

taglist配置

set tags=工作文件夹/tags    "设置tags
let Tlist_Show_One_File=1    "开启taglist
let Tlist_Exit_OnlyWindow=1
let g:winManagerWindowLayout='FileExplorer|TagList'   "WinManager
nmap wm :WMToggle<cr>

括号自动补全

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>
function! ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endfunction

复制

" 映射全选+复制 Ctrl+A  
map <C-A> ggVG  
map! <C-A> <Esc>ggVG  
map <F12> gg=G  
" 选中状态下 Ctrl+C 复制  
vmap <C-c> "+y  
map <C-v> "+p 

编译及调试

map <F5> :call CR()<CR>
func! CR()
exec "w"
exec "!g++ -std=c++11 -Wall -Wextra % -o %<"
exec "!./%<"
endfunc
  
map <F6> :call Rungdb()<CR>  
func! Rungdb()  
    exec "w"  
    exec "!g++ -std=c++11 -Wall -Wextra % -g -o %<"  
    exec "!gdb ./%<"  
endfunc

其他配置

filetype on
set shortmess=atI 
colorscheme  molokai     "配色方案
set background=dark      
set fencs=utf-8,gbk,cp936,ucs-bom  "检测编码,解决中文乱码
set termencoding=utf-8,gbk,cp936,ucs-bom
set encoding=gbk
set fileencodings=utf-8,gbk,cp936,ucs-bom
set fileencoding=utf-8
"let g:rehash256 = 1
set guifont=Consolas:h11     "字体与字号
set tabstop=4                " 设置tab键的宽度
set shiftwidth=4             " 换行时行间交错使用4个空格
set autoindent               " 自动对齐
set softtabstop=4
set backspace=indent,eol,start   " 设置退格键可用
set cindent shiftwidth=4     " 自动缩进4空格
set expandtab                "空格代替tab
set smartindent              " 智能自动缩进
set ai!                      " 设置自动缩进
set cin!                     "设置C缩进  
set showmatch                " 高亮显示匹配的括号
set number                   " 显示行号
set mouse=a                  " 启用鼠标
set ruler                    " 右下角显示光标位置的状态行
set incsearch                " 查找book时,当输入/b时会自动找到
set hlsearch                 " 开启高亮显示结果
set incsearch                " 开启实时搜索功能
set nowrapscan               " 搜索到文件两端时不重新搜索
set nocompatible             " 关闭兼容模式
set vb t_vb=                 " 关闭提示音
set hidden                   " 允许在有未保存的修改时切换缓冲区
"set list                    " 显示Tab符,使用一高亮竖线代替
set listchars=tab:\|\ ,
set nobackup                 " 取消备份
set lines=35 columns=90     " 设定窗口大小
winpos 350 10                " 设定窗口位置
"set go=                     " 不要图形按钮
set guioptions-=T            " 隐藏工具栏
"set guioptions-=m           " 隐藏菜单栏
set foldenable               " 允许折叠  
set foldmethod=manual        " 手动折叠
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}   "状态行显示的内容  
"set laststatus=2            " 启动显示状态行(1),总是显示状态行(2) 
set completeopt=preview,menu " 代码补全 
set clipboard+=unnamed       " 共享剪贴板 
set cursorline               " 突出显示当前行
set guioptions-=T            " 隐藏工具栏
"set guioptions-=m           " 隐藏菜单栏
map <silent> <F3> :if &guioptions =~# 'T' <Bar>
        \set guioptions-=T <Bar>
    \else <Bar>
        \set guioptions+=T <Bar>
    \endif
set scrolloff=3              " 光标移动到buffer的顶部和底部时保持3行距离
set autochdir                " 设置当前打开文件所在目录为工作目录
"set linespace=1
syntax enable                " 打开语法高亮
syntax on                    " 开启文件类型侦测
filetype indent on           " 针对不同的文件类型采用不同的缩进格式
filetype plugin on           " 针对不同的文件类型加载对应的插件
filetype plugin indent on    " 启用自动补全

gvimrc

set linespace=-3
set lines=33 columns=90
:winpos 200 20
"Toggle Menu and Toolbar
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
        \set guioptions-=T <Bar>
        \set guioptions-=m <bar>
    \else <Bar>
        \set guioptions+=T <Bar>
        \set guioptions+=m <Bar>
    \endif