1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| "============================ " windows下解决乱码问题(linux下不需要) "============================ set encoding=utf-8 set fileencodings=utf-8,chinese,latin-1 if has("win32") set fileencoding=chinese else set fileencoding=utf-8 endif "解决菜单乱码 source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim "解决consle输出乱码 language messages zh_CN.utf-
"============================ " 基本设置 "============================ syntax enable "开启语法高亮 syntax on "开启语法高亮
filetype on "检测文件类型 filetype plugin on "针对不同文件采取不同缩进方式 filetype indent on "允许插件 filetype plugin indent on "启动自动补全
set number "显示行号 set ruler "显示当前行号 set showmode "显示当前Vim模式 set showcmd "显示正在输入的命令 set tabstop=4 "设置tab宽度 set shiftwidth=4 "设置自动对齐空格数 set smarttab "设置backspace删去tab" set mouse=a "允许鼠标操作 set nobackup "取消备份 set noswapfile "取消临时文件 set encoding=utf-8 "设置编码方式 set helplang=cn "中文帮助 set completeopt=longest,menu "自动补全配置 set wildmenu "增强命令行自动完成操作
"pathogen 插件管理 execute pathogen#infect()
"============================ " TagList插件设置 "============================ autocmd FileType cpp set tags+=~/.vim/tags/cpp_src/tags "设置tags文件包含 let Tlist_Show_One_File=1 " 只展示一个文件的taglist let Tlist_Exit_OnlyWindow=1 " 当taglist是最后一个窗口时自动退出 let Tlist_Use_Right_Window=1 " 在右边显示taglist窗口 let Tlist_Sort_Type="name" " tag按名字排序
"============================ " 补全插件设置 "============================ autocmd FileType css set omnifunc=csscomplete#CompleteCSS autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags autocmd FileType php set omnifunc=phpcomplete#CompletePHP autocmd FileType ruby set omnifunc=rubycomplete#Complete autocmd FileType perl set omnifunc=perlcomplete#Complete
"============================ " C++ 补全插件设置 "============================ autocmd Filetype c setlocal omnifunc=cppcomplete#Complete autocmd Filetype cpp setlocal omnifunc=cppcomplete#Complete " search namespaces in the current buffer and in included files let OmniCpp_NamespaceSearch = 2 let OmniCpp_ShowPrototypeInAbbr = 1 " 显示函数参数列表 let OmniCpp_MayCompleteScope = 1 " 输入 :: 后自动补全 let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"] let OmniCpp_DisplayMode = 1 "always show all members
"============================ " Python 补全插件设置 "============================ autocmd Filetype python setlocal omnifunc=pythoncomplete#Complete let g:pydiction_location='~/.vim/tools/pydiction/complete-dict'
"============================ " Java 补全插件设置 "============================ autocmd Filetype java setlocal omnifunc=javacomplete#Complete autocmd FileType java set omnifunc=javacomplete#Complete autocmd FileType java set completefunc=javacomplete#CompleteParamsInf autocmd FileType java inoremap <buffer> . .<C-X><C-O><C-P>
"============================ " 自动添加文件头 "============================ "新建.c,.h,.sh,.java文件,自动插入文件头 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()" ""定义函数SetTitle,自动插入文件头 func SetTitle() "如果文件类型为.sh文件 if &filetype == 'sh' call setline(1,"\#!/bin/bash") call append(line("."), "") elseif &filetype == 'python' call setline(1,"#!/usr/bin/env python") call append(line("."),"# coding=utf-8") call append(line(".")+1, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: DHD") call append(line(".")+2, " > Mail: ") 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 &filetype == '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 if &filetype == 'java' call append(line(".")+6,"public class ".expand("%:r")) call append(line(".")+7,"") endif "新建文件后,自动定位到文件末尾 endfunc autocmd BufNewFile * normal G
"============================ " 快捷键设置 "============================ "Ctrl + n 打开目录树 map <C-n> :NERDTree<CR> "Ctrl + t 打开 taglist map <F8> :Tlist<CR> "ctags 生成 cpp 文件的 tags map <F12> :call CreateTags()<CR> "<F5> 编译运行 map <F5> :call ComplieAndRun() <CR> "<C-F5> 调试 map <C-F5> :call Rungdb() <CR>
"============================ " 函数定义 "============================ "编译 func! ComplieAndRun() exec "w" if &filetype == 'c' exec "!g++ % -o %<" exec "!time ./%<" elseif &filetype == 'cpp' exec "!g++ % -std=c++11 -o %<" exec "!time ./%<" elseif &filetype == 'java' exec "!javac %" exec "!time java %<" elseif &filetype == 'sh' :!time bash % elseif &filetype == 'python' "exec "!time python2.7 %" exec "!time python3.6 %" elseif &filetype == 'html' exec "!google-chrome % &" endif endfunc
"调试 func! Rungdb() exec "w" exec "!g++ % -std=c++11 -g -o %<" exec "!gdb ./%<" endfunc
"生成tags文件 func! CreateTags() if &filetype == 'c' exec "!ctags *.c *.h --c-kinds=+p --fields=+iaS --extra=+fq " elseif &filetype == 'cpp' exec "!ctags *.cpp *.h *.hpp *.c --c++-kinds=+px --fields=+iaS --extra=+fq " elseif &filetype == 'java' exec "!ctags *.java --java-kinds=+p --fields=+iaS --extra=+fq " elseif &filetype == 'python' exec "!ctags *.py --python-kinds --fields=+iaS --extra=+f " elseif &filetype == 'html' exec "!ctags *.html --html-kinds=+p --fields=+iaS --extra=+f " endif endfunc
|