"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
""实用设置 | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set sw=4 | |
set ts=4 | |
set et | |
set smarttab | |
set smartindent | |
set lbr | |
set fo+=mB | |
set sm | |
set selection=inclusive | |
set wildmenu | |
set mousemodel=popup | |
if has("autocmd") | |
autocmd BufReadPost * | |
\ if line("'\"") > 0 && line("'\"") <= line("$") | | |
\ exe "normal g`\"" | | |
\ endif | |
endif | |
" open NERDTree automatically when vim statup | |
autocmd vimenter * NERDTree | |
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif | |
" plugin settings | |
let g:ctrlp_match_window = 'order:ttb,max:20' | |
let g:NERDSpaceDelims=1 | |
let g:gitgutter_enabled = 0 | |
"当打开vim且没有文件时自动打开NERDTree | |
"autocmd vimenter * if !argc() | NERDTree | endif | |
" 只剩 NERDTree时自动关闭 | |
"autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif | |
" 设置当文件被改动时自动载入 | |
set autoread | |
" quickfix模式 | |
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr> | |
"代码补全 | |
set completeopt=preview,menu | |
"允许插件 | |
filetype plugin on | |
"共享剪贴板 | |
"set clipboard+=unnamed | |
"自动保存 | |
set autowrite | |
set ruler " 打开状态栏标尺 | |
set cursorline " 突出显示当前行 | |
set magic " 设置魔术 | |
set guioptions-=T " 隐藏工具栏 | |
set guioptions-=m " 隐藏菜单栏 | |
""set foldcolumn=0 | |
""set foldmethod=indent | |
""set foldlevel=3 | |
" 不要使用vi的键盘模式,而是vim自己的 | |
set nocompatible | |
" 去掉输入错误的提示声音 | |
set noeb | |
" 在处理未保存或只读文件的时候,弹出确认 | |
set confirm | |
"禁止生成临时文件 | |
set nobackup | |
set noswapfile | |
"搜索忽略大小写 | |
set ignorecase | |
set linespace=0 | |
" 增强模式中的命令行自动完成操作 | |
set wildmenu | |
" 使回格键(backspace)正常处理indent, eol, start等 | |
set backspace=2 | |
" 允许backspace和光标键跨越行边界 | |
set whichwrap+=<,>,h,l | |
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位) | |
set mouse=a | |
set selection=exclusive | |
set selectmode=mouse,key | |
" 通过使用: commands命令,告诉我们文件的哪一行被改变过 | |
set report=0 | |
" 在被分割的窗口间显示空白,便于阅读 | |
set fillchars=vert:\ ,stl:\ ,stlnc:\ | |
" 高亮显示匹配的括号 | |
set showmatch | |
" 匹配括号高亮的时间(单位是十分之一秒) | |
set matchtime=1 | |
" 光标移动到buffer的顶部和底部时保持3行距离 | |
set scrolloff=3 | |
" 为C程序提供自动缩进 | |
"自动补全 | |
: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 ' ''<ESC>i | |
function! ClosePair(char) | |
if getline('.')[col('.') - 1] == a:char | |
return "\<Right>" | |
else | |
return a:char | |
endif | |
endfunction | |
filetype plugin indent on | |
"打开文件类型检测, 加了这句才可以用智能补全 | |
set completeopt=longest,menu | |
set iskeyword+=. | |
set fileencodings=utf-8 | |
set termencoding=utf-8 | |
set encoding=utf8 | |
set fileencoding=utf8 | |
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030 | |
let &termencoding=&encoding | |
autocmd FileType python set omnifunc=pythoncomplete#Complete | |
let g:html_indent_inctags = "html,body,head,tbody" | |
let g:html_indent_script1 = "inc" | |
let g:html_indent_style1 = "inc" | |
filetype plugin indent on " required! | |
"syntastic相关 | |
execute pathogen#infect() | |
let g:syntastic_python_checkers=['pylint'] | |
let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd'] | |
"C,C++ 按F5编译运行 | |
map <F5> :call CompileRunGcc()<CR> | |
func! CompileRunGcc() | |
exec "w" | |
if &filetype == 'c' | |
exec "!gcc % -o %<" | |
exec "!time ./%<" | |
elseif &filetype == 'cpp' | |
exec "!g++ % -o %<" | |
exec "!time ./%<" | |
elseif &filetype == 'java' | |
exec "!javac %" | |
exec "!time java %<" | |
elseif &filetype == 'sh' | |
:!time bash % | |
elseif &filetype == 'python' | |
exec "!time python2.7 %" | |
elseif &filetype == 'html' | |
exec "!firefox % &" | |
elseif &filetype == 'go' | |
" exec "!go build %<" | |
exec "!time go run %" | |
elseif &filetype == 'mkd' | |
exec "!~/.vim/markdown.pl % > %.html &" | |
exec "!firefox %.html &" | |
endif | |
endfunc | |
"C,C++的调试 | |
map <F8> :call Rungdb()<CR> | |
func! Rungdb() | |
exec "w" | |
exec "!g++ % -g -o %<" | |
exec "!gdb ./%<" | |
endfunc | |
"代码格式优化化 | |
map <F6> :call FormartSrc()<CR><CR> | |
func FormartSrc() | |
exec "w" | |
if &filetype == 'c' | |
exec "!astyle --style=ansi -a --suffix=none %" | |
elseif &filetype == 'cpp' || &filetype == 'hpp' | |
exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1" | |
elseif &filetype == 'perl' | |
exec "!astyle --style=gnu --suffix=none %" | |
elseif &filetype == 'py'||&filetype == 'python' | |
exec "r !autopep8 -i --aggressive %" | |
elseif &filetype == 'java' | |
exec "!astyle --style=java --suffix=none %" | |
elseif &filetype == 'jsp' | |
exec "!astyle --style=gnu --suffix=none %" | |
elseif &filetype == 'xml' | |
exec "!astyle --style=gnu --suffix=none %" | |
else | |
exec "normal gg=G" | |
return | |
endif | |
exec "e! %" | |
endfunc | |
"结束定义FormartSrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment