vim配置文件

来源:互联网 发布:海湾消防主机编程视频 编辑:程序博客网 时间:2024/05/22 07:58
"**********************************************************


syntax on
set go= " 不要图形按钮


" 启动的时候不显示那个援助索马里儿童的提示 
set shortmess=atI 


colorscheme darkblue         "配色方案
"set foldmethod=syntax       " 设置语法折叠 
"set foldenable              " 开始折叠  


set guifont=宋体\ Bold\ 10   " 设置字体


set nu                       " 显示行号 
set smartindent shiftwidth=4 "C语言自动缩进,缩进值为4个字符宽度


set tabstop=4                "tab为4个空格
"set shortmess=atI       " 启动的时候不显示那个援助乌干达儿童的提示  
"set lines=25 columns=70     " 设定窗口大小  
set lines=32 columns=100


set autoindent               "把当前行的对齐格式应用到下一行(自动缩进)


"set ruler                    "显示行号信息
set  ai!                     "设置自动缩进


set nocompatible              "去掉有关vi一致性模式,避免以前版本的bug和局限    
set history=100              "记录历史的行数


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


"set magic " 设置魔术
set nobackup                   "不生成临时文件




" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位) 
set mouse=a 
"set selection=exclusive 
"set selectmode=mouse,key 


" 与windows共享剪贴板 
set clipboard+=unnamed 


" 不要生成swap文件,当buffer被丢弃的时候隐藏它 
setlocal noswapfile 




"""""""""""""""""按键映射"""""""""""""""""


map <F2> gg=G              "整理代码


nnoremap <F3> :g/^\s*$/d<CR> "去空行  


map <C-s> :w!<CR>


nmap <leader>w :w!<cr>


"normal 模式下的按键映射
"nnoremap  <C-q> :q<cr>


nmap  <C-q> :q<cr>


" 映射全选+复制 ctrl+a
"map! <C-A>  <Esc>ggVGY


" 映射全选 
map! <C-A>  <Esc>ggVG
map! <C-z>  u


"vmap 是下visual模式下的按键映射
"选中状态下 Ctrl+c 复制
vmap <C-c>  "+y   "直接点击鼠标中键粘贴
vmap <C-v>  "+gP
vmap <C-c>  "+gx


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头 
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" 
""定义函数SetTitle,自动插入文件头 
func SetTitle() 
    "如果文件类型为.sh文件 
    if &filetype == 'sh' 
        call setline(1,"\###############################") 
        call append(line("."), "\# File Name: ".expand("%")) 
        call append(line(".")+1, "\# Author: gw") 
        call append(line(".")+2, "\# mail: 963353840@qq.com") 
        call append(line(".")+3, "\# Created Time: ".strftime("%c")) 
        call append(line(".")+4, "\####################################") 
        call append(line(".")+5, "\#!/bin/bash") 
        call append(line(".")+6, "") 
    else 
        call setline(1, "/*********************************************") 
        call append(line("."),   "    > File Name: ".expand("%")) 
        call append(line(".")+1, "    > Author:gw") 
        call append(line(".")+2, "    > Mail: 963353840@q.com ") 
        call append(line(".")+3, "    > Created Time: ".strftime("%c")) 
        call append(line(".")+4, " **************************************/") 
        call append(line(".")+5, " ")
     endif


       if expand("%:e") == 'cpp'
          call append(line(".")+6, " #include<iostream>   ")
          call append(line(".")+7, " using namespace std; ")
          call append(line(".")+8, " ")
       endif
       if expand("%:e") == 'c'
          call append(line(".")+6, "#include<stdio.h>")
          call append(line(".")+7, "")
        endif
       if expand("%:e") == 'h'
         call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
    call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
    call append(line(".")+8, "#endif")
     endif
    "新建文件后,自动定位到文件末尾
    
    autocmd BufNewFile * normal G
endfunc 




"######################################
"编译
map <F5> :call CompileRunGcc()<CR>


func! CompileRunGcc()
    if &filetype == 'c'
        !gcc % -o %.exe
    elseif &filetype == 'cpp'
        !g++ % -o %.exe
    elseif &filetype == 'java' 
        !javac %
    elseif &filetype == 'sh'
        :!./%
    endif
endfunc


"######################################
"运行
map <F6> :call Run()<CR>


func! Run()
    exec "w"
    if &filetype == 'c'
        exec "! ./%.exe<"
    elseif &filetype == 'cpp'
        exec "! ./%.exe<"
    elseif &filetype == 'java' 
        exec "!java %<"
    elseif &filetype == 'sh'
        :!./%
    endif


endfunc




"#########我的插件设置


" 侦测文件类型
filetype on
" 载入文件类型插件
filetype plugin on
" 为特定文件类型载入相关缩进文件
filetype indent on
"filetype plugin indent on 




"""""""""""""winmanager""""""""""""""""""""""""
let g:winManagerWindowLayout='TagList'
"let g:winManagerWindowLayout='FileExplorer|TagList'
map <C-w> :WMToggle<cr>




"""""""""""""powerline""""""""""""""""""""""
"set guifont=PowerlineSymbols\ for\ Powerline
set nocompatible
set t_Co=256
let g:Powerline_symbols = 'fancy'
set laststatus=1
set encoding=utf-8
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容 




""""""""""""NERD Comment"""""""""""""""""""




""""""""" Settings of taglist""""""""""""""
" increase the width of the taglist window
let Tlist_WinWidth=10
" automatically open the taglist window
let Tlist_Auto_Open=0
" exit wim when only the taglist window exist
let Tlist_Exit_OnlyWindow=1
" open tags with single click
let Tlist_Use_SingleClick=1
" close tag folds for inactive buffers
let Tlist_File_Fold_Auto_Close=1
" show the fold indicator column in the taglist window
let Tlist_Enable_Fold_Column=1
" Automatically update the taglist to include newly edited files
let Tlist_Auto_Update=1


let Tlist_Show_One_File=1  
let Tlist_Exit_OnlyWindow=1 




"""""""""" NERDtree settings"""""""""""""""
let NERDTreeWinPos='right'


"列出当前目录文件
map <C-e> :NERDTreeToggle<CR>


let g:nerdtree_tabs_open_on_console_startup=1       "设置打开vim的时候默认打开目录树
map <leader>n <plug>NERDTreeTabsToggle <CR>         "设置打开目录树的快捷键
"nerdtree
map <C-l> :tabn<cr>             "下一个tab
map <C-h> :tabp<cr>             "上一个tab
map <C-n> :tabnew<cr>           "新tab
"map <C-k> :bn<cr>               "下一个文件
"map <C-j> :bp<cr>               "上一个文件




""""""""""""ctags settings"""""""""""""""""
set tags+=~/.vim/cpptags
set tags+=~/.vim/systags


map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> 
let Tlist_Exist_OnlyWindow = 1  " 如果只有一个buffer,kill窗口也kill掉buffer
let Tlist_File_Fold_Auto_Close = 0  " 不要关闭其他文件的tags  
let Tlist_Enable_Fold_Column = 0    " 不要显示折叠树 


"按下"Ctrl+]", 光标会自动跳转到其定义处
"按<C-T>, 这样又跳回




""""""""""syntastic""""""""""""
let g:syntastic_check_on_open = 1
let g:syntastic_cpp_include_dirs = ['/usr/include/']
let g:syntastic_cpp_remove_include_errors = 1
let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++'
"whether to show balloons
let g:syntastic_enable_balloons = 1


let g:syntastic_auto_jump=1
"set error or warning signs
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚠'
let g:syntastic_auto_loc_list = 1
let g:syntastic_loc_list_height = 6
let g:syntastic_enable_highlighting = 0
 


""""""""""""YCM""""""""""""""""""""
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/mycpp/.ycm_extra_conf.py'
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0


" 自动补全配置
set completeopt=longest,menu    "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口
inoremap <expr> <CR>       pumvisible() ? '<C-y>' : '<CR>'  "回车即选中当前项
"上下左右键的行为 会显示其他信息
"inoremap <expr> <Down>     pumvisible() ? '<C-n>' : '<Down>'
"inoremap <expr> <Up>       pumvisible() ? '<C-p>' : '<Up>'
inoremap <expr> <PageDown> pumvisible() ? '<PageDown><C-p><C-n>' : '<PageDown>'
inoremap <expr> <PageUp>   pumvisible() ? '<PageUp><C-p><C-n>' : '<PageUp>'


"youcompleteme  默认tab  s-tab 和自动补全冲突
"let g:ycm_key_list_select_completion=['<c-n>']
let g:ycm_key_list_select_completion = ['<Down>']
"let g:ycm_key_list_previous_completion=['<c-p>']
let g:ycm_key_list_previous_completion = ['<Up>']
"let g:ycm_confirm_extra_conf=0              "关闭加载.ycm_extra_conf.py提示


let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎
let g:ycm_min_num_of_chars_for_completion=2   "从第2个键入字符就开始罗列匹配项
"let g:ycm_cache_omnifunc=0                   "禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_seed_identifiers_with_syntax=1      "语法关键字补全
"let g:ycm_min_num_identifier_candidate_chars = 0
let g:ycm_auto_trigger = 1
let g:ycm_complete_in_comments = 1           "在注释输入中也能补全
let g:ycm_complete_in_strings = 1             "在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0"注释和字符串中的文字也会被收入补全


nnoremap lo :lopen<CR>     "open locationlist
nnoremap lc :lclose<CR>    "close locationlist
inoremap <leader><leader> <C-x><C-o>


"F5 刷新错误/警告
nnoremap ff :YcmForceCompileAndDiagnostics<CR> 


" 跳转到定义处 find definition
nnoremap  f :YcmCompleter GoToDefinitionElseDeclaration<CR> 




""""""""""""""""vundle"""""""""""""""""""""
"************  插件管理 *******************
" 我的插件更新
set nocompatible               " be iMproved
filetype off                   " required!
 
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
 
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
 
" My Bundles here:
"
" original repos on github
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'tpope/vim-rails.git'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
" non github repos
"Bundle 'git://git.wincent.com/command-t.git'




Bundle 'taglist.vim'
Bundle 'https://github.com/Lokaltog/vim-powerline.git'
Bundle 'ctags.vim'
Bundle 'winmanager'
Bundle 'https://github.com/scrooloose/syntastic'
Bundle 'https://github.com/jistr/vim-nerdtree-tabs'
Bundle 'https://github.com/scrooloose/nerdtree'
Bundle 'Valloric/YouCompleteMe'
"添加注释
Bundle 'https://github.com/scrooloose/nerdcommenter' 
"快速输入
Bundle 'UltiSnips'          
Bundle 'grep.vim'


filetype plugin indent on     " required!
"
" Brief help  -- 此处后面都是vundle的使用命令
" :BundleList          - list configured bundles
" :BundleInstall(!)    - install(update) bundles
" :BundleSearch(!) foo - search(or refresh cache first) for foo
" :BundleClean(!)      - confirm(or auto-approve) removal of unused bundles
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Bundle command are not allowed..
"#########插件管理 endof
0 0