Last active
December 8, 2016 07:55
-
-
Save limboinf/baac945fc21df885e19e5cb16ad99c45 to your computer and use it in GitHub Desktop.
我的vim配置,有如下文件和目录: ~/.vimrc ~/.vim/vim_template/vim_header_for_python ~/.vim/vim_template/vim_header_for_sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible " required | |
filetype off " required | |
" set the runtime path to include Vundle and initialize | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
" alternatively, pass a path where Vundle should install plugins | |
"call vundle#begin('~/some/path/here') | |
" let Vundle manage Vundle, required | |
Plugin 'gmarik/Vundle.vim' | |
" 代码折叠插件 | |
Plugin 'tmhedberg/SimpylFold' | |
" 快速注释 | |
" http://www.wklken.me/posts/2015/06/07/vim-plugin-nerdcommenter.html | |
Bundle 'scrooloose/nerdcommenter' | |
" 注释的时候自动加个空格, 强迫症必配 | |
let g:NERDSpaceDelims=1 | |
" ========================================== | |
" TAGBAR[大纲式导航] | |
" http://www.wklken.me/posts/2015/06/07/vim-plugin-tagbar.html | |
" ========================================== | |
Bundle 'majutsushi/tagbar' | |
nmap <F9> :TagbarToggle<CR> | |
" 启动时自动focus | |
let g:tagbar_autofocus = 1 | |
" ========================================== | |
" RAINBOW_PARENTHESES[括号高亮] | |
" http://bit.ly/2g5jstk | |
" ========================================== | |
Bundle 'kien/rainbow_parentheses.vim' | |
let g:rbpt_colorpairs = [ | |
\ ['brown', 'RoyalBlue3'], | |
\ ['Darkblue', 'SeaGreen3'], | |
\ ['darkgray', 'DarkOrchid3'], | |
\ ['darkgreen', 'firebrick3'], | |
\ ['darkcyan', 'RoyalBlue3'], | |
\ ['darkred', 'SeaGreen3'], | |
\ ['darkmagenta', 'DarkOrchid3'], | |
\ ['brown', 'firebrick3'], | |
\ ['gray', 'RoyalBlue3'], | |
\ ['darkmagenta', 'DarkOrchid3'], | |
\ ['Darkblue', 'firebrick3'], | |
\ ['darkgreen', 'RoyalBlue3'], | |
\ ['darkcyan', 'SeaGreen3'], | |
\ ['darkred', 'DarkOrchid3'], | |
\ ['red', 'firebrick3'], | |
\ ] | |
" 不加入这行, 防止黑色括号出现, 很难识别 | |
" \ ['black', 'SeaGreen3'], | |
let g:rbpt_max = 16 | |
let g:rbpt_loadcmd_toggle = 0 | |
au VimEnter * RainbowParenthesesToggle | |
au Syntax * RainbowParenthesesLoadRound | |
au Syntax * RainbowParenthesesLoadSquare | |
au Syntax * RainbowParenthesesLoadBraces | |
" 自动缩进 | |
Plugin 'vim-scripts/indentpython.vim' | |
" 自动补全 | |
Bundle 'Valloric/YouCompleteMe' | |
" 语法高亮 | |
Plugin 'scrooloose/syntastic' | |
" PEP8代码风格检查 | |
Plugin 'nvie/vim-flake8' | |
" 最后,让你的代码变得更漂亮: | |
let python_highlight_all=1 | |
syntax on | |
" 显示tab和空格 | |
set list | |
" 设置tab和空格样式 | |
set lcs=tab:\|\ ,nbsp:%,trail:- | |
" 设定行首tab为灰色 | |
highlight LeaderTab guifg=#666666 | |
" 匹配行首tab | |
match LeaderTab /^\t/ | |
" 定义快捷键的前缀,即<Leader> | |
let mapleader=";" | |
nnoremap <leader>d dd | |
" 自定义快捷键 | |
" 将ESC键映射为jk | |
inoremap jk <ESC> | |
" 配色方案 | |
" GUI模式可以尝试solarized方案, 终端模式可以尝试Zenburn方案: | |
Plugin 'jnurmine/Zenburn' | |
Plugin 'altercation/vim-colors-solarized' | |
" ======================= | |
" 如果你想用tab键,可以利用vim-nerdtree-tabs插件实现: | |
Plugin 'jistr/vim-nerdtree-tabs' | |
" 还想隐藏.pyc文件?那么再添加下面这行代码吧: | |
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree | |
" ======================= | |
" ======================= | |
" [超级搜索] | |
" 想要在Vim中搜索任何文件?试试ctrlP插件吧, 正如插件名,按Ctrl+P就可以进行搜索 | |
Plugin 'kien/ctrlp.vim' | |
" ======================= | |
" 高亮:https://github.com/hdima/python-syntax | |
Plugin 'hdima/python-syntax' | |
let python_highlight_all = 1 | |
" 开启目录树导航, https://github.com/scrooloose/nerdtree | |
Plugin 'scrooloose/nerdtree' | |
" ======================= | |
" [其他操作] | |
" 开启显示行号: | |
set nu | |
" Git集成 | |
Plugin 'tpope/vim-fugitive' | |
" Powerline状态栏, 显示当前的虚拟环境、Git分支、正在编辑的文件等信息 | |
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'} | |
" vim-json-line-format https://github.com/vim-scripts/vim-json-line-format | |
Plugin 'axiaoxin/vim-json-line-format' | |
" 系统剪贴板 | |
set clipboard=unnamed | |
" ======================= | |
" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin) | |
" All of your Plugins must be added before the following line | |
call vundle#end() " required | |
filetype plugin indent on " required | |
" 通过快捷组合键进行切换分隔布局 | |
"split navigations | |
nnoremap <C-J> <C-W><C-J> | |
nnoremap <C-K> <C-W><C-K> | |
nnoremap <C-L> <C-W><C-L> | |
nnoremap <C-H> <C-W><C-H> | |
" 代码折叠 | |
" Enable folding | |
set foldmethod=indent | |
set foldlevel=99 | |
" 代码折叠要手动输入za来折叠和取消,下面使用空格键映射 | |
" Enable folding with the spacebar | |
nnoremap <space> za | |
" 希望看到折叠代码的文档字符串 | |
let g:SimpylFold_docstring_preview=1 | |
set tabstop=4 | |
set softtabstop=4 | |
set shiftwidth=4 | |
" 支持PEP8风格的缩进 | |
au BufNewFile,BufRead *.py | |
\ set tabstop=4 | | |
\ set softtabstop=4 | | |
\ set shiftwidth=4 | | |
\ set textwidth=79 | | |
\ set expandtab | | |
\ set autoindent | | |
\ set fileformat=unix | |
" Keep indentation level from previous line: | |
autocmd FileType python set autoindent | |
" 支持UTF-8编码 | |
set encoding=utf-8 | |
" YouCompleteMe自动补全安装后还可以进行一些小的调整 | |
" 上面的第一行确保了在你完成操作之后,自动补全窗口不会消失, | |
" 第二行则定义了“转到定义”的快捷方式。 | |
let g:ycm_autoclose_preview_window_after_completion=1 | |
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR> | |
" 支持Virtualenv虚拟环境 | |
" 上面“转到定义”功能的一个问题,就是默认情况下Vim不知道virtualenv虚拟环境 | |
" 所以你必须在配置文件中添加下面的代码,使得Vim和YouCompleteMe能够发现你的虚拟环境: | |
"python with virtualenv support | |
py << EOF | |
import os | |
import sys | |
if 'VIRTUAL_ENV' in os.environ: | |
project_base_dir = os.environ['VIRTUAL_ENV'] | |
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py') | |
execfile(activate_this, dict(__file__=activate_this)) | |
EOF | |
" 高亮光标所在的行列 | |
set cursorcolumn | |
set cursorline | |
" 美化上面的光标所在行高亮, ref: http://www.jianshu.com/p/b8763c23ea64 | |
highlight CursorLine cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE | |
highlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE | |
" .vimrc配置, 新建文件时,如果autocmd匹配文件类型成功,则根据模版自动生成文件头 | |
" https://gist.github.com/zxkletters/6521114 | |
" auto add file header | |
autocmd BufNewFile *.py 0r $HOME/.vim/vim_template/vim_header_for_python | |
autocmd BufNewFile *.py ks|call CreatedTime()|'s | |
autocmd BufNewFile *.sh 0r $HOME/.vim/vim_template/vim_header_for_sh | |
autocmd BufNewFile *.sh ks|call FileName()|'s | |
autocmd BufNewFile *.sh ks|call CreatedTime()|'s | |
fun FileName() | |
if line("$") > 10 | |
let l = 10 | |
else | |
let l = line("$") | |
endif | |
exe "1," . l . "g/File Name:.*/s/File Name:.*/File Name: " .expand("%") | |
endfun | |
fun CreatedTime() | |
if line("$") > 10 | |
let l = 10 | |
else | |
let l = line("$") | |
endif | |
exe "1," . l . "g/Created Time:.*/s/Created Time:.*/Created Time: " .strftime("%Y-%m-%d %T") | |
endfun | |
" end auto add file header | |
"""""""""""""""""""""" | |
"Quickly Run | |
"""""""""""""""""""""" | |
map <F5> :call CompileRunGcc()<CR> | |
func! CompileRunGcc() | |
exec "w" | |
if &filetype == 'c' | |
exec "!g++ % -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 python %" | |
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 | |
"""""""""""""""""""""" | |
"vim-snippets代码智能补全插件 | |
"https://github.com/garbas/vim-snipmate | |
"""""""""""""""""""""" | |
Plugin 'MarcWeber/vim-addon-mw-utils' | |
Plugin 'tomtom/tlib_vim' | |
Plugin 'garbas/vim-snipmate' | |
" Optional: | |
Plugin 'honza/vim-snippets' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
:Author: beginman.cn | |
:Mail: [email protected] | |
:Created Time: | |
:Copyright: (c) 2016 by beginman. | |
:License: MIT, see LICENSE for more details. | |
""" | |
# path: ~/.vim/vim_template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
######################################################################### | |
# File Name: | |
# Author: beginman(fangpeng) | |
# mail: [email protected] | |
# Created Time: | |
######################################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment