Skip to content

Instantly share code, notes, and snippets.

@osvimer
Created November 19, 2020 16:00
Show Gist options
  • Save osvimer/4ba8b63fff685332cdd9b9f73701c2b6 to your computer and use it in GitHub Desktop.
Save osvimer/4ba8b63fff685332cdd9b9f73701c2b6 to your computer and use it in GitHub Desktop.
"==============================================================================
"---------------------------- Global Setting ------------------------------
"==============================================================================
" 定义快捷键的前缀,即<Leader>
let mapleader = ","
"==============================================================================
"----------------------------- Key Bindings -------------------------------
"==============================================================================
" 定义快捷键关闭当前分割窗口
nmap <Leader>q :q<CR>
" 定义快捷键保存当前窗口内容
nmap <Leader>w :w<CR>
" 定义快捷键保存所有窗口内容并退出 vim
nmap <Leader>WQ :wa<CR>:q<CR>
" 不做任何保存,直接退出 vim
nmap <Leader>Q :qa!<CR>
" 设置快捷键遍历子窗口
nnoremap nw <C-W><C-W> " 依次遍历
nnoremap <Leader>lw <C-W>l " 跳转至右方的窗口
nnoremap <Leader>hw <C-W>h " 跳转至左方的窗口
nnoremap <Leader>kw <C-W>k " 跳转至上方的子窗口
nnoremap <Leader>jw <C-W>j " 跳转至下方的子窗口
" 设置快捷键切换Buffer
nnoremap <Leader>bn :bn<CR> "切换到下一个buffer
nnoremap <Leader>bp :bp<CR> "切换到前一个buffer
" 定义:Man命令查看各类man信息的快捷键
nmap <Leader>man :Man 3 <cword><CR>
"==============================================================================
"-------------------------------- Vundle ----------------------------------
"==============================================================================
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
" vundle 管理的插件列表必须位于 vundle#begin() 和 vundle#end() 之间
call vundle#rc()
Plugin 'VundleVim/Vundle.vim' " 插件管理
Plugin 'tpope/vim-fugitive' " git wrapper
Plugin 'airblade/vim-gitgutter' " git diff 展示
Plugin 'mattn/gist-vim' " gist 插件
Plugin 'mattn/webapi-vim' " vim-gist requred
Plugin 'mattn/pastebin-vim' " Pastebin 插件
Plugin 'ryanoasis/vim-devicons' " icons support
Plugin 'ctrlpvim/ctrlp.vim' " 搜索并打开文件
Plugin 'scrooloose/nerdtree' " 目录树浏览
Plugin 'majutsushi/tagbar' " 大纲式快速导航
Plugin 'vim-scripts/taglist.vim' " 类似 TagBar
Plugin 'kien/tabman.vim' " 标签页管理器
Plugin 'wkentaro/conque.vim' " vim 内嵌终端
"Plugin 'fholgado/minibufexpl.vim' " 显示buffer
Plugin 'chazy/cscope_maps' " Cscope Settings
Plugin 'ludovicchabant/vim-gutentags' " 自动 ctags 索引
Plugin 'Yggdroot/LeaderF' " 函数列表
Plugin 'xolox/vim-misc' " required by vim-session
Plugin 'xolox/vim-session' " session 管理
Plugin 'easymotion/vim-easymotion' " 快速移动
Plugin 'scrooloose/nerdcommenter' " 快速注释代码
Plugin 'vim-utils/vim-man' " 使用 man 手册
Plugin 'vimwiki/vimwiki' " Personal Wiki
Plugin 'itchyny/calendar.vim' " Calendar and Note
Plugin 'christoomey/vim-tmux-navigator' " vim / tmux 无缝切换
Plugin 'vim-scripts/a.vim' " source/header 快速切换
"Plugin 'Valloric/YouCompleteMe' " 代码补全: 基于语义
"Plugin 'Shougo/neocomplete.vim' " 代码补全: 基于标签
Plugin 'ervandew/supertab' " 代码补全: 基于标签
"Plugin 'scrooloose/syntastic' " 语法检查: 与YCM冲突
"Plugin 'davidhalter/jedi-vim' " Python补全: 与YCM冲突
"Plugin 'Raimondi/delimitMate' " 引号/括号自动补全
Plugin 'JarrodCTaylor/vim-sql-suggest' "SQL completion
Plugin 'shawncplus/phpcomplete.vim' " Improved PHP omni-completion
"Plugin 'aperezdc/vim-template' " 新文件模板
"Plugin 'SirVer/ultisnips' " 代码块引擎
"Plugin 'honza/vim-snippets' " 代码块集合
"Plugin 'Shougo/neosnippet' " 另一个代码块引擎
"Plugin 'Shougo/neosnippet-snippets' " 另一个代码块集合
Plugin 'lilydjwg/fcitx.vim' " 输入法切换之状态恢复
Plugin 'ntpeters/vim-better-whitespace' " 显示行末多余空格
Plugin 'tpope/vim-surround' " 修改配对括号
"Plugin 'godlygeek/tabular' " 代码对齐增强
Plugin 'Chiel92/vim-autoformat' " 代码自动格式化
Plugin 'rhysd/vim-clang-format' " Clang-format 格式化
Plugin 'nathanaelkane/vim-indent-guides' " 代码缩进可视化关联
Plugin 'kshenoy/vim-signature' " 代码收藏书签可视化
Plugin 'derekwyatt/vim-fswitch' " 接口与实现快速切换
Plugin 'derekwyatt/vim-protodef' " 由接口快速生成实现框架
Plugin 'octol/vim-cpp-enhanced-highlight' " Cpp语法高亮增强(C++ 11/14)
Plugin 'pangloss/vim-javascript' " JavaScript语法高亮
Plugin 'elzr/vim-json' " Json语法高亮
Plugin 'othree/html5.vim' " html5语法高亮
Plugin 'hail2u/vim-css3-syntax' " css3 语法高亮
Plugin 'ap/vim-css-color' " 颜色代码预览
Plugin 'colorselector' " 配色选择器
Plugin 'flazz/vim-colorschemes' " 配色方案集合
Plugin 'tomasr/molokai' " 复古配色方案
Plugin 'sickill/vim-monokai' " sublime配色方案
Plugin 'altercation/vim-colors-solarized' " 淡雅配色方案
"Plugin 'Lokaltog/vim-powerline' " 状态栏增强
Plugin 'vim-airline/vim-airline' " 替代 powerline
Plugin 'vim-airline/vim-airline-themes' " airline 主题
call vundle#end() " 插件列表结束
filetype plugin indent on
"==============================================================================
"------------------------------- NERDTree ---------------------------------
"==============================================================================
"map <F4> :NERDTreeMirror<CR>
map nt :NERDTreeToggle<cr>
" 设置NERDTree子窗口宽度
let NERDTreeWinSize=32
" 设置NERDTree子窗口位置
let NERDTreeWinPos="left"
" 显示隐藏文件
let NERDTreeShowHidden=1
" NERDTree 子窗口中不显示冗余帮助信息
let NERDTreeMinimalUI=1
" 删除文件时自动删除文件对应 buffer
let NERDTreeAutoDeleteBuffer=1
" open a NERDTree automatically when vim starts up
"autocmd vimenter * NERDTree
" Close NERDTree When Leave
autocmd VimLeave * NERDTreeClose
"autocmd VimLeave * mksession! [filename]
" close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" open a NERDTree automatically when vim starts up if no files were specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
"==============================================================================
"-------------------------------- tabman ----------------------------------
"==============================================================================
" Usage:
" Press <leader>mt or run :TMToggle to toggle TabMan.
" Press <leader>mf or run :TMFocus to give focus to/open the TabMan window.
" Change the default mappings:
let g:tabman_toggle = 'tm'
let g:tabman_focus = 'tf'
" Change the width of the TabMan window:
let g:tabman_width = 25
" And the position:
let g:tabman_side = 'left'
" Set this to 1 to show windows created by plugins, help and quickfix:
let g:tabman_specials = 0
" Set this to 0 to disable line numbering in the TabMan window:
let g:tabman_number = 1
"==============================================================================
"-------------------------------- cscope ----------------------------------
"==============================================================================
" Usage:
" The following maps all invoke one of the following cscope search types:
" 's' symbol: find all references to the token under cursor
" 'g' global: find global definition(s) of the token under cursor
" 'c' calls: find all calls to the function name under cursor
" 't' text: find all instances of the text under cursor
" 'e' egrep: egrep search for the word under cursor
" 'f' file: open the filename under cursor
" 'i' includes: find files that include the filename under cursor
" 'd' called: find functions that function under cursor calls
if has("cscope")
set splitright
set cscopequickfix=s-,c-,d-,i-,t-,e-
nmap <leader>gs :vert scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gg :vert scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gc :vert scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gt :vert scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <leader>ge :vert scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gf :vert scs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <leader>gi :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <leader>gd :vert scs find d <C-R>=expand("<cword>")<CR><CR>
endif
" Autoload Cscope Database
set nocscopeverbose
"set cscopequickfix=s-,c-,d-,i-,t-,e-
set cst
function LoadCscope(path)
"防止无限递归
if a:path == $HOME
return
endif
if (executable("cscope") && has("cscope"))
let l:outfile=a:path."/cscope.out"
let l:outpath=a:path
if filereadable(outfile)
cs reset
exe "cs add" outfile outpath
else
"递归
let l:newpath=a:path."/.."
let newpath=resolve(newpath)
"echo newpath
call LoadCscope(newpath)
endif
endif
endfunction
call LoadCscope(getcwd())
"au BufEnter /* call LoadCscope()
"==============================================================================
"----------------------------- vim-session --------------------------------
"==============================================================================
let g:session_autosave = 'no'
let g:session_command_aliases = 1
"let g:session_menu = 0
" Disable all session locking - I know what I'm doing :-).
let g:session_lock_enabled = 0
let g:session_persist_font = 0
let g:session_persist_colors = 0
" Persist the value of the global option 'makeprg'.
let g:session_persist_globals = ['&makeprg']
"==============================================================================
"--------------------------------- Ctrlp ----------------------------------
"==============================================================================
"let g:ctrlp_map = ',,'
let g:ctrlp_open_multiple_files = 'v'
set wildignore+=*/tmp/*,*.so,*.swp,*.zip
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git)$',
\ 'file': '\v\.(log|jpg|png|jpeg)$',
\ }
"==============================================================================
"---------------------------- NERD Commenter ------------------------------
"==============================================================================
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1
" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
" Nerd Commenter 使用说明 (使用默认的快捷键, 不需要自己绑定)
" <leader>cc 加注释
" <leader>cu 解开注释
" <leader>c<space> 加上/解开注释, 智能判断
" <leader>cy 先复制, 再注解(p可以进行黏贴)
"==============================================================================
"----------------------------- vim-powerline ------------------------------
"==============================================================================
"let g:Powerline_symbols = 'fancy'
"==============================================================================
"------------------------------ vim-airline -------------------------------
"==============================================================================
let g:airline_theme = 'cool' "主题设置
let g:airline_powerline_fonts = 1 "启用powerline字体
let g:airline_section_x = ''
" 打开tabline功能,方便查看Buffer和切换
let g:airline#extensions#tabline#enabled = 1
" show buffer number
let g:airline#extensions#tabline#buffer_nr_show = 1
" set left separator
let g:airline#extensions#tabline#left_sep = ' '
" set left separator which are not editting
let g:airline#extensions#tabline#left_alt_sep = '|'
" 关闭状态显示空白符号计数
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#whitespace#symbol = '!'
"==============================================================================
"----------------------------- vim-gitgutter ------------------------------
"==============================================================================
if exists('&signcolumn') " Vim 7.4.2201
set signcolumn=yes
else
let g:gitgutter_sign_column_always = 1
endif
let g:gitgutter_override_sign_column_highlight = 0
let g:gitgutter_highlight_lines = 0
"highlight SignColumn ctermbg=whatever " terminal Vim
"highlight SignColumn guibg=whatever " gVim/MacVim
" The base of the diff
"let g:gitgutter_diff_base = '<commit SHA>'
" Extra arguments for git diff
"let g:gitgutter_diff_args = '-w'
let g:gitgutter_max_signs = 500 " default value
let g:gitgutter_realtime = 1
let g:gitgutter_eager = 0
let g:gitgutter_async = 0 " turn off asynchronous updates
let g:gitgutter_map_keys = 0 " disable default mapping
" jump between hunks:
nmap ]h <Plug>GitGutterNextHunk<cr>
nmap [h <Plug>GitGutterPrevHunk<cr>
nmap <Leader>ha <Plug>GitGutterStageHunk<cr>
nmap <Leader>hr <Plug>GitGutterUndoHunk<cr>
nmap <Leader>hv <Plug>GitGutterPreviewHunk<cr>
"==============================================================================
"-------------------------------- vim-gist --------------------------------
"==============================================================================
" copy the gist code with option '-c'
"let g:gist_clip_command = 'xclip -selection clipboard'
" detect filetype from the filename
let g:gist_detect_filetype = 1
" open browser after the post
let g:gist_open_browser_after_post = 0
" change the browser
let g:gist_browser_command = 'w3m %URL%'
" show your private gists with ':Gist -l'
let g:gist_show_privates = 1
" gist to be private by default
let g:gist_post_private = 0
" gist to be anonymous by default
let g:gist_post_anonymous = 0
" manipulate multiple files in a gist
let g:gist_get_multiplefile = 0
" use on GitHub Enterprise
"let g:gist_api_url = 'http://your-github-enterprise-domain/api/v3'
" You need to either set global git config:
" git config --global github.user Username
"
"==============================================================================
"-------------------------------- calendar --------------------------------
"==============================================================================
let g:calendar_frame = 'default'
" 日期格式 year-month-day
"let g:calendar_date_endian = "big"
" 日期分隔符
let g:calendar_date_separator = "-"
" 打开日历时的视图
"let g:calendar_view = "day"
" 设置View布局
let g:calendar_views = ['year', 'day', 'month', 'week', 'clock', 'days']
" Google Calendar and Google Task
let g:calendar_google_calendar = 0
let g:calendar_google_task = 0
"==============================================================================
"--------------------------- vim-tmux-navigator ---------------------------
"==============================================================================
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <c-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <c-j> :TmuxNavigateDown<cr>
nnoremap <silent> <c-k> :TmuxNavigateUp<cr>
nnoremap <silent> <c-l> :TmuxNavigateRight<cr>
"nnoremap <silent> <c-p> :TmuxNavigatePrevious<cr>
"==============================================================================
"----------------------------- vim-css-color ------------------------------
"==============================================================================
let g:cssColorVimDoNotMessMyUpdatetime = 1
"==============================================================================
"-------------------------------- SuperTab --------------------------------
"==============================================================================
let g:SuperTabDefaultCompletionType = "<c-n>"
let g:SuperTabContextDefaultCompletionType = "<c-n>"
"==============================================================================
"------------------------------ neocomplete -------------------------------
"==============================================================================
" " Disable AutoComplPop.
" let g:acp_enableAtStartup = 0
" " Use neocomplete.
" let g:neocomplete#enable_at_startup = 1
" " Use smartcase.
" let g:neocomplete#enable_smart_case = 1
" " Set minimum syntax keyword length.
" let g:neocomplete#sources#syntax#min_keyword_length = 3
" let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
"
" " Define dictionary.
" let g:neocomplete#sources#dictionary#dictionaries = {
" \ 'default' : '',
" \ 'vimshell' : $HOME.'/.vimshell_hist',
" \ 'scheme' : $HOME.'/.gosh_completions'
" \ }
"
" " Define keyword.
" if !exists('g:neocomplete#keyword_patterns')
" let g:neocomplete#keyword_patterns = {}
" endif
" let g:neocomplete#keyword_patterns['default'] = '\h\w*'
"
" " Plugin key-mappings.
" inoremap <expr><C-g> neocomplete#undo_completion()
" inoremap <expr><C-l> neocomplete#complete_common_string()
"
" " Recommended key-mappings.
" " <CR>: close popup and save indent.
" inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
" function! s:my_cr_function()
" return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
" " For no inserting <CR> key.
" "return pumvisible() ? "\<C-y>" : "\<CR>"
" endfunction
" " <TAB>: completion.
" inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" " <C-h>, <BS>: close popup and delete backword char.
" inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
" inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" " Close popup by <Space>.
" "inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"
"
" " AutoComplPop like behavior.
" "let g:neocomplete#enable_auto_select = 1
"
" " Shell like behavior(not recommended).
" "set completeopt+=longest
" "let g:neocomplete#enable_auto_select = 1
" "let g:neocomplete#disable_auto_complete = 1
" "inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
"
" " Enable omni completion.
" autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
" autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
" autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
" autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
" autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
"
" " Enable heavy omni completion.
" if !exists('g:neocomplete#sources#omni#input_patterns')
" let g:neocomplete#sources#omni#input_patterns = {}
" endif
" "let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
" "let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
" "let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
"
" " For perlomni.vim setting.
" " https://github.com/c9s/perlomni.vim
" let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
"
"==============================================================================
"------------------------------- Syntastic --------------------------------
"==============================================================================
set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_checkers = ['cpplint', 'gcc']
let g:syntastic_cpp_cpplint_exec = "cpplint"
" 设置 cpplint 的错误级别阈值(默认是 5),级别低于这一设置的不会显示
let g:syntastic_cpp_cpplint_thres = 1
" 设置错误聚合,同时显示两个 checker 的错误
let syntastic_aggregate_errors = 1
"==============================================================================
"------------------------------- tagbar ------------------------------------
"==============================================================================
nmap tb :TagbarToggle<CR>
" 设置 tagbar 子窗口的位置出现在主编辑区的左边
let tagbar_right=1
" 设置标签子窗口的宽度
let tagbar_width=32
" tagbar 子窗口中不显示冗余帮助信息
let g:tagbar_compact=1
" 设置 ctags 对哪些代码标识符生成标签
let g:tagbar_type_cpp = {
\ 'kinds' : [
\ 'c:classes:0:1',
\ 'd:macros:0:1',
\ 'e:enumerators:0:0',
\ 'f:functions:0:1',
\ 'g:enumeration:0:1',
\ 'l:local:0:1',
\ 'm:members:0:1',
\ 'n:namespaces:0:1',
\ 'p:functions_prototypes:0:1',
\ 's:structs:0:1',
\ 't:typedefs:0:1',
\ 'u:unions:0:1',
\ 'v:global:0:1',
\ 'x:external:0:1'
\ ],
\ 'sro' : '::',
\ 'kind2scope' : {
\ 'g' : 'enum',
\ 'n' : 'namespace',
\ 'c' : 'class',
\ 's' : 'struct',
\ 'u' : 'union'
\ },
\ 'scope2kind' : {
\ 'enum' : 'g',
\ 'namespace' : 'n',
\ 'class' : 'c',
\ 'struct' : 's',
\ 'union' : 'u'
\ }
\ }
let g:tagbar_autofocus=1
let g:tagbar_ctags_bin='$HOME/local/bin/ctags'
"autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen()
" indexer 调用 ctags 的参数
" 默认 --c++-kinds=+p+l,重新设置为 --c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+v
" 默认 --fields=+iaS 不满足 YCM 要求,需改为 --fields=+iaSl
let g:indexer_ctagsCommandLineOptions="--c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+v --fields=+iaSl --extra=+q"
"==============================================================================
"------------------------------- vim-gutentags -------------------------------
"==============================================================================
set tags=./.tags;,.tags
" gutentags 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
" 配置 ctags 的参数
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
" 检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
silent! call mkdir(s:vim_tags, 'p')
endif
"==============================================================================
"---------------------------------- Leaderf --------------------------------
"==============================================================================
" search word under cursor, the pattern is treated as regex, and enter normal mode directly
noremap <C-F> :<C-U><C-R>=printf("Leaderf! rg -e %s ", expand("<cword>"))<CR>
" search word under cursor, the pattern is treated as regex,
" append the result to previous search results.
noremap <C-G> :<C-U><C-R>=printf("Leaderf! rg --append -e %s ", expand("<cword>"))<CR>
" search word under cursor literally only in current buffer
noremap <C-B> :<C-U><C-R>=printf("Leaderf! rg -F --current-buffer -e %s ", expand("<cword>"))<CR>
" search visually selected text literally, don't quit LeaderF after accepting an entry
xnoremap gf :<C-U><C-R>=printf("Leaderf! rg -F --stayOpen -e %s ", leaderf#Rg#visual())<CR>
" recall last search. If the result window is closed, reopen it.
noremap go :<C-U>Leaderf! rg --stayOpen --recall<CR>
noremap <F5> :LeaderfFunction!<cr>
let g:Lf_ShortcutF = '<C-P>'
let g:Lf_CommandMap = {'<C-K>': ['<Up>'], '<C-J>': ['<Down>']}
highlight Lf_hl_match gui=bold guifg=Blue cterm=bold ctermfg=21
highlight Lf_hl_matchRefine gui=bold guifg=Magenta cterm=bold ctermfg=201
"==============================================================================
"-------------------------------- UltiSnips -------------------------------
"==============================================================================
" Trigger configuration. Do not use <tab> if you use YouCompleteMe
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
let g:UltiSnipsSnippetDirectories=["mysnippets"]
" *.cpp 和 *.h 间切换
nmap <Leader>ch :A<CR>
" 子窗口中显示 *.cpp 或 *.h
nmap <Leader>sch :AS<CR>
"==============================================================================
"----------------------------- YouCompleteMe ------------------------------
"==============================================================================
" YCM 补全菜单配色
highlight Pmenu ctermfg=2 ctermbg=3 guifg=#005f87 guibg=#EEE8D5 " 菜单
highlight PmenuSel ctermfg=2 ctermbg=3 guifg=#AFD700 guibg=#106900 " 选中项
" 让Vim的补全菜单行为与一般IDE一致
"set completeopt=longest,menu
" 补全功能在注释中同样有效
let g:ycm_complete_in_comments = 1
" 在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" 注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
" 允许 vim 加载 .ycm_extra_conf.py 文件,不再提示
let g:ycm_confirm_extra_conf = 0
" 指定.ycm_extra_conf.py 文件
let g:ycm_extra_conf_globlist = ['~/work/trunk/v5.0_dev/v5.0/*','~/work/trunk/v5.0/v5.0/*']
let g:ycm_global_ycm_extra_conf = '~/work/trunk/v5.0_dev/v5.0/.ycm_extra_conf.py'
" 特定文件关闭ycm
let g:ycm_filetype_blacklist = {
\ 'tagbar' : 1,
\ 'qf' : 1,
\ 'notes' : 1,
\ 'markdown' : 1,
\ 'unite' : 1,
\ 'text' : 1,
\ 'vimwiki' : 1,
\ 'gitcommit' : 1,
\}
" 开启 YCM 标签补全引擎
let g:ycm_collect_identifiers_from_tags_files = 1
" 引入 C++ 标准库tags
set tags+=~/.vim/ctags/stdcpp.tags
set tags+=~/.vim/ctags/sys.tags
"set tags+=~/.vim/ctags/cpp.tags
" YCM 集成 OmniCppComplete 补全引擎,设置其快捷键
"inoremap <leader>; <C-x><C-o>
" 补全内容不以分割子窗口形式出现,只显示补全列表
set completeopt-=preview
" 从第一个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion = 1
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc = 0
" 自动触发
let g:ycm_auto_trigger = 1
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax = 1
" 从第1个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion = 1
" 跳转到声明处
nnoremap <leader>jc :YcmCompleter GoToDeclaration<CR>
" 跳转到定义处,只能是 #include 或已打开的文件
"nnoremap <leader>jd :YcmCompleter GoToDefinition<CR>
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
"==============================================================================
"------------------------------- jedi-vim ---------------------------------
"==============================================================================
" Jedi is by default automatically initialized. If u don't want that, disable it
let g:jedi#auto_initialization = 1
" some VIM options (like completeopt and key defaults) which are automatically
" initialized, but you can skip this:
let g:jedi#auto_vim_configuration = 0
" You can make jedi-vim use tabs when going to a definition etc:
let g:jedi#use_tabs_not_buffers = 1
" If you are a person who likes to use VIM-splits
" This options could be "left", "right", "top", "bottom" or "winwidth".
" It will decide the direction where the split open.
let g:jedi#use_splits_not_buffers = "left"
" Jedi automatically starts the completion, if you type a dot, e.g. str.,
" if you don't want this:
let g:jedi#popup_on_dot = 1
" Jedi selects the first line of the completion menu:
" for a better typing-flow and usually saves one keypress.
let g:jedi#popup_select_first = 1
" Jedi displays function call signatures in insert mode in real-time,
" highlighting the current argument. The call signatures can be displayed as
" a pop-up in the buffer (set to 1, the default), which has the advantage of
" being easier to refer to, or in Vim's command line aligned with the function
" call (set to 2), which can improve the integrity of Vim's undo history.
let g:jedi#show_call_signatures = "1"
"NOTE: subject to change!
let g:jedi#goto_command = "<leader>d"
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_definitions_command = ""
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>n"
let g:jedi#completions_command = "<C-p>"
let g:jedi#rename_command = "<leader>r"
" Finally, if you don't want completion, but all the other features, use:
let g:jedi#completions_enabled = 1
let g:pymode_rope = 0
"==============================================================================
"------------------------ cpp-enhanced-highlight --------------------------
"==============================================================================
" Highlighting of class scope is disabled by default. To enable set
let g:cpp_class_scope_highlight = 1
" Highlighting of template functions is enabled by setting
let g:cpp_experimental_template_highlight = 1
"==============================================================================
"---------------------------- vim-javascript ------------------------------
"==============================================================================
" Enables syntax highlighting for JSDocs
let g:javascript_plugin_jsdoc = 0
" Enables some additional syntax highlighting for NGDocs. Requires JSDoc plugin to be enabled as well
let g:javascript_plugin_ngdoc = 0
" Enables syntax highlighting for Flow
let g:javascript_plugin_flow = 0
" Enables code folding based on our syntax file
"set foldmethod=syntax
" Concealing Characters
let g:javascript_conceal_function = "ƒ"
let g:javascript_conceal_null = "ø"
let g:javascript_conceal_this = "@"
let g:javascript_conceal_return = "⇚"
let g:javascript_conceal_undefined = "¿"
let g:javascript_conceal_NaN = "ℕ"
let g:javascript_conceal_prototype = "¶"
let g:javascript_conceal_static = "•"
let g:javascript_conceal_super = "Ω"
let g:javascript_conceal_arrow_function = "⇒"
"==============================================================================
"------------------------------- vim-json ---------------------------------
"==============================================================================
let g:vim_json_syntax_conceal = 0
let g:indentLine_noConcealCursor=""
"==============================================================================
"------------------------------ vim-html5 ---------------------------------
"==============================================================================
" Enable/Disable event-handler attributes support:
let g:html5_event_handler_attributes_complete = 1
" Enable/Disable RDFa attributes support:
let g:html5_rdfa_attributes_complete = 1
" Enable/Disable microdata attributes support:
let g:html5_microdata_attributes_complete = 1
" Enable/Disable WAI-ARIA attribute support:
let g:html5_aria_attributes_complete = 1
"==============================================================================
"------------------------------- vim-css3 ---------------------------------
"==============================================================================
augroup VimCSS3Syntax
autocmd!
autocmd FileType css setlocal iskeyword+=-
augroup END
"==============================================================================
"--------------------------- vim-indent-guides ----------------------------
"==============================================================================
" 随 vim 自启动
let g:indent_guides_enable_on_vim_startup=1
" 从第二层开始可视化显示缩进
let g:indent_guides_start_level=2
" 色块宽度
let g:indent_guides_guide_size=1
" 快捷键 i 开/关缩进可视化
:nmap <silent> <Leader>i <Plug>IndentGuidesToggle
let g:indent_guides_auto_colors = 0
"autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=black ctermbg=3
"autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=darkgrey ctermbg=4
"==============================================================================
"------------------------------- signature --------------------------------
"==============================================================================
let g:SignatureMap = {
\ 'Leader' : "m",
\ 'PlaceNextMark' : "m,",
\ 'ToggleMarkAtLine' : "m.",
\ 'PurgeMarksAtLine' : "m-",
\ 'DeleteMark' : "dm",
\ 'PurgeMarks' : "mda",
\ 'PurgeMarkers' : "m<BS>",
\ 'GotoNextLineAlpha' : "']",
\ 'GotoPrevLineAlpha' : "'[",
\ 'GotoNextSpotAlpha' : "`]",
\ 'GotoPrevSpotAlpha' : "`[",
\ 'GotoNextLineByPos' : "]'",
\ 'GotoPrevLineByPos' : "['",
\ 'GotoNextSpotByPos' : "mn",
\ 'GotoPrevSpotByPos' : "mp",
\ 'GotoNextMarker' : "[+",
\ 'GotoPrevMarker' : "[-",
\ 'GotoNextMarkerAny' : "]=",
\ 'GotoPrevMarkerAny' : "[=",
\ 'ListLocalMarks' : "ms",
\ 'ListLocalMarkers' : "m?"
\ }
"==============================================================================
"------------------------------ vim-fswitch -------------------------------
"==============================================================================
" *.cpp 和 *.h 间切换
nmap <silent> <Leader>sw :FSHere<cr>
"==============================================================================
"------------------------------ vim-protodef ------------------------------
"==============================================================================
" 成员函数的实现顺序与声明顺序一致
let g:disable_protodef_sorting=1
" 设置 pullproto.pl 脚本路径
let g:protodefprotogetter='~/.vim/bundle/protodef/pullproto.pl'
" 成员函数的实现顺序与声明顺序一致
let g:disable_protodef_sorting=1
"==============================================================================
"---------------------------- MiniBufExplorer -----------------------------
"==============================================================================
" 显示/隐藏 MiniBufExplorer 窗口
map <Leader>bl :MBEToggle<cr>
" buffer 切换快捷键
map <C-Tab> :MBEbn<cr>
map <C-S-Tab> :MBEbp<cr>
" MiniBufExpl Colors
hi MBENormal guifg=#808080 guibg=fg
hi MBEChanged guifg=#CD5907 guibg=fg
hi MBEVisibleNormal guifg=#5DC2D6 guibg=fg
hi MBEVisibleChanged guifg=#F1266F guibg=fg
hi MBEVisibleActiveNormal guifg=#A6DB29 guibg=fg
hi MBEVisibleActiveChanged guifg=#F1266F guibg=fg
"==============================================================================
"------------------------------- EasyMotion -------------------------------
"==============================================================================
map <Leader> <Plug>(easymotion-prefix)
" <Leader>f{char} to move to {char}
map <Leader>f <Plug>(easymotion-bd-f)
nmap <Leader>f <Plug>(easymotion-overwin-f)
" s{char}{char} to move to {char}{char}
"nmap s <Plug>(easymotion-overwin-f2)
" Move to line
map <Leader>L <Plug>(easymotion-bd-jk)
nmap <Leader>L <Plug>(easymotion-overwin-line)
" Move to word
map <Leader>w <Plug>(easymotion-bd-w)
nmap <Leader>w <Plug>(easymotion-overwin-w)
" Gif config
nmap s <Plug>(easymotion-s2)
nmap t <Plug>(easymotion-t2)
map / <Plug>(easymotion-sn)
omap / <Plug>(easymotion-tn)
map n <Plug>(easymotion-next)
map N <Plug>(easymotion-prev)
map <Leader>l <Plug>(easymotion-lineforward)
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
map <Leader>h <Plug>(easymotion-linebackward)
let g:EasyMotion_startofline = 0 " keep cursor column when JK motion
" Smartcase & Smartsign
let g:EasyMotion_smartcase = 1
let g:EasyMotion_use_smartsign_us = 1 " US layout
" Gif config
" Require tpope/vim-repeat to enable dot repeat support
" Jump to anywhere with only `s{char}{target}`
" `s<CR>` repeat last find motion.
"nmap s <Plug>(easymotion-s)
" Bidirectional & within line 't' motion
"omap t <Plug>(easymotion-bd-tl)
" Use uppercase target labels and type as a lower case
let g:EasyMotion_use_upper = 1
" type `l` and match `l`&`L`
let g:EasyMotion_smartcase = 1
" Smartsign (type `3` and match `3`&`#`)
let g:EasyMotion_use_smartsign_us = 1
"==============================================================================
"------------------------------- AutoFormat -------------------------------
"==============================================================================
" F5 键自动格式化代码
noremap <F5> :Autoformat<CR>
" to have your code be formatted upon saving your file:
"au BufWrite * :Autoformat
" To disable the fallback to vim's indent file, retabbing and removing trailing whitespace
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0
" To disable or re-enable these option for specific buffers
"autocmd FileType vim,tex let b:autoformat_autoindent=0
let g:formatter_yapf_style = 'chromium'
"==============================================================================
"------------------------------ clang-format ------------------------------
"==============================================================================
let g:clang_format#command = 'clang-format'
nmap <F4> :ClangFormat<cr>
autocmd FileType c ClangFormatAutoEnable
let g:clang_format#detect_style_file = 1
let g:clang_format#style_options = {
\ "Language" : "Cpp",
\ "BasedOnStyle" : "Google",
\ "AccessModifierOffset" : -1,
\ "AlignAfterOpenBracket" : "true",
\ "AlignEscapedNewlinesLeft" : "true",
\ "AlignOperands" : "true",
\ "AlignTrailingComments" : "true",
\ "AllowAllParametersOfDeclarationOnNextLine" : "true",
\ "AllowShortBlocksOnASingleLine" : "false",
\ "AllowShortCaseLabelsOnASingleLine" : "false",
\ "AllowShortIfStatementsOnASingleLine" : "true",
\ "AllowShortLoopsOnASingleLine" : "true",
\ "AllowShortFunctionsOnASingleLine" : "All",
\ "AlwaysBreakAfterDefinitionReturnType" : "false",
\ "AlwaysBreakTemplateDeclarations" : "true",
\ "AlwaysBreakBeforeMultilineStrings" : "true",
\ "BreakBeforeBinaryOperators" : "None",
\ "BreakBeforeTernaryOperators" : "true",
\ "BreakConstructorInitializersBeforeComma" : "false",
\ "BinPackParameters" : "true",
\ "BinPackArguments" : "true",
\ "ColumnLimit" : 80,
\ "ConstructorInitializerAllOnOneLineOrOnePerLine" : "true",
\ "ConstructorInitializerIndentWidth" : 4,
\ "DerivePointerAlignment" : "true",
\ "ExperimentalAutoDetectBinPacking" : "false",
\ "IndentCaseLabels" : "true",
\ "IndentWrappedFunctionNames" : "false",
\ "IndentFunctionDeclarationAfterType" : "false",
\ "MaxEmptyLinesToKeep" : 1,
\ "KeepEmptyLinesAtTheStartOfBlocks" : "false",
\ "NamespaceIndentation" : "None",
\ "ObjCBlockIndentWidth" : 2,
\ "ObjCSpaceAfterProperty" : "false",
\ "ObjCSpaceBeforeProtocolList" : "false",
\ "PenaltyBreakBeforeFirstCallParameter" : 1,
\ "PenaltyBreakComment" : 300,
\ "PenaltyBreakString" : 1000,
\ "PenaltyBreakFirstLessLess" : 120,
\ "PenaltyExcessCharacter" : 1000000,
\ "PenaltyReturnTypeOnItsOwnLine" : 200,
\ "PointerAlignment" : "Left",
\ "SpacesBeforeTrailingComments" : 2,
\ "Cpp11BracedListStyle" : "true",
\ "Standard" : "Auto",
\ "IndentWidth" : 2,
\ "TabWidth" : 8,
\ "UseTab" : "Never",
\ "BreakBeforeBraces" : "Attach",
\ "SpacesInParentheses" : "false",
\ "SpacesInSquareBrackets" : "false",
\ "SpacesInAngles" : "false",
\ "SpaceInEmptyParentheses" : "false",
\ "SpacesInCStyleCastParentheses" : "false",
\ "SpaceAfterCStyleCast" : "false",
\ "SpacesInContainerLiterals" : "true",
\ "SpaceBeforeAssignmentOperators" : "true",
\ "ContinuationIndentWidth" : 4 }
"==============================================================================
"----------------------------- General Setting -----------------------------
"==============================================================================
" 设定默认解码
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
set enc=utf-8
let &termencoding=&encoding
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" history文件中需要记录的行数
set history=1000
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 与windows共享剪贴板
set clipboard+=unnamed
" 设置快捷键将选中文本块复制至系统剪贴板
vnoremap <Leader>y "+y
" 设置快捷键将系统剪贴板内容粘贴至vim
nmap <Leader>p "+p
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
"set mousehide
set selection=exclusive
set selectmode=mouse,key
" 当右键单击窗口的时候,弹出快捷菜单。
set mousemodel=popup
" 不让vim发出讨厌的滴滴声
set noerrorbells
set novisualbell
set t_vb=
if has('autocmd')
autocmd GUIEnter * set vb t_vb=
endif
" No bell settings End }}}
" 帮助文档语言为中文
set helplang=cn
" 保存全局变量
set viminfo+=!
" Opening Vim help in a vertical split window
autocmd FileType help wincmd L
" 文件间复制粘贴: 使用鼠标复制内容到剪切板
"set mouse=v
" F12键切换鼠标
" toggle between terminal and vim mouse
map <silent><F12> :let &mouse=(&mouse == "a"?"":"a")<CR>:call ShowMouseMode()<CR>
imap <silent><F12> :let &mouse=(&mouse == "a"?"":"a")<CR>:call ShowMouseMode()<CR>
function ShowMouseMode()
if (&mouse == 'a')
echo "mouse-vim"
else
echo "mouse-xterm"
endif
endfunction
"==============================================================================
"---------------------------- File Setting --------------------------------
"==============================================================================
" 自动格式化
set formatoptions=tcrqn
" 继承前一行的缩进方式,特别适用于多行注释
set autoindent
" 为C程序提供自动缩进
set smartindent
" 使用C样式的缩进
set cindent
" 制定C/C++文件缩进方式
set cinoptions=:0g1h1t0(sus
" :0 switch 下的 case 相对于switch缩进 1 个空格
" g1 public、protected、private 相对 class、struct 所在的块缩进 1 个空格
" h1 public、protected、private 后的成员变量、函数相对权限控制语句缩进1个空格
" t0 如果函数返回值与函数名不在同一行,则返回值缩进 0 个空格
" (cus 当一对括号跨越多行时,其后的行缩进等于 shiftwidth 指定的距离
set tabstop=2 " 设置编辑时制表符占用空格数
set softtabstop=2 " 把连续数量的空格视为一个制表符
set shiftwidth=2 " 设置格式化时制表符占用空格数
set expandtab " 将制表符扩展为空格
"set noexpandtab " 不要将制表符扩展为空格
set nowrap " 不要自动换行
" 环境恢复
" 设置环境保存项
set sessionoptions="blank,globals,localoptions,tabpages,sesdir,folds,help,options,resize,winpos,winsize"
" 在行和段开始处使用制表符
"set smarttab
" 侦测文件类型
"filetype on
" 载入文件类型插件
"filetype plugin on
" 为特定文件类型载入相关缩进文件
"filetype indent on
" 自动保存文件
"let g:auto_save = 1
" 要备份文件(根据自己需要取舍)
"set backup
" 设置无备份文件
set writebackup
set nobackup
" 不要生成swap文件,当buffer被丢弃的时候隐藏它
"setlocal noswapfile
set bufhidden=hide
set dir=~/.vim/tmp
" 字符间插入的像素行数目
set linespace=0
set wildmenu " vim 自身命令行模式智能补全
set autoread " 自动重新加载外部修改内容
set autochdir " 自动切换当前目录为当前文件所在的目录
" F2键: 替换Tab为空格
nmap <F2> :%ret! 2<cr>
" F3键: 去掉行末空格
nmap <F3> :%s/\s\+$//<cr>
" F9键切换粘贴模式
set pastetoggle=<F9>
" Ctrl+s: 保存文件
:noremap <C-s> :w<cr>
:inoremap <C-s> <esc>:w<cr>
" 记住文件上次光标位置
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
" markdown
let g:vim_markdown_folding_disabled=1
"==============================================================================
"--------------------------- Search and Match ------------------------------
"==============================================================================
" 开启Magic:默认使用正则表达式
"set magic
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=5
" 在搜索的时候忽略大小写
"set ignorecase
" 不要高亮被搜索的句子(phrases)
"set hlsearch
set nohlsearch
" 开启实时搜索功能: 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch
"==============================================================================
"---------------------------- Display Effect ------------------------------
"==============================================================================
" 显示行号
set number
" 光标所在行显示横线
set cursorline
" 高亮显示当前列
set cursorcolumn
" 添加水平滚动条
set guioptions+=b
" 在状态行上显示光标所在位置的行号和列号
set ruler
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
" 显示非可见字符
"set list
"set nolist
" 非可见字符显示方式
"set listchars=tab:▸\ ,eol:¬,nbsp:⋅,trail:•
" 命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2
" 在屏幕最后一行显示 (部分的) 命令
set showcmd
" 总是显示状态栏
set laststatus=2
" 我的状态行显示的内容(包括文件类型和解码)
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
" 状态行颜色
highlight StatusLine guifg=SlateBlue guibg=Yellow
highlight StatusLineNC guifg=Gray guibg=White
" 开启语法高亮功能
syntax enable
" 允许用指定语法高亮配色方案替换默认方案
syntax on
" 高亮字符,让其不受100列限制
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%101v.*'
" 带有如下符号的单词不要被换行分隔
set iskeyword+=_,$,@,%,#,-
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
" 输入:set list命令是应该显示些啥?
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 不要闪烁
set novisualbell
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
" 在每个tab上显示编号
set guitablabel=%{tabpagenr()}.%t\ %m
" 主题配色
colorscheme molokai
let g:molokai_original = 1
let g:rehash256 = 1
"colorscheme monokai
"colorscheme solarized
if has('gui_running')
set background=light
else
set background=dark
endif
let g:solarized_termcolors=256
" Force 256 color mode if available
if $TERM =~ "-256color"
set t_Co=256
endif
" xterm 设置
if &term=="xterm"
set t_Co=256
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endi
" 代码折叠
"set foldenable " 启动 vim 时自动折叠
"set nofoldenable " 启动 vim 时关闭折叠代码
"set foldmethod=syntax " 基于语法进行折叠
"set foldmethod=indent " 基于缩进进行折叠
"set foldcolumn=0 " 设置折叠区域的宽度
"setlocal foldlevel=1 " 设置折叠层数
"set foldclose=all " 设置为自动关闭折叠
hi Normal guibg=NONE ctermbg=NONE
"==============================================================================
"---------------------------- Copyright Statement --------------------------
"==============================================================================
" 自动添加或更新版权声明头
"autocmd BufNewFile *.[ch],*.hpp,*.cpp,*.cc exec ":call TitleDet()"
map <F10> :call TitleDet()<cr>'s
function AddTitle()
call append(0,"/*=========================================================")
call append(1,"* Author : Junjie Huang")
call append(2,"* Email : [email protected]")
call append(3,"* Last modified : ".strftime("%Y-%m-%d %H:%M"))
call append(4,"* Filename : ".expand("%:t"))
call append(5,"* Description : ")
call append(6,"=========================================================*/")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
" 更新最近修改时间和文件名
function UpdateTitle()
normal m'
execute '/* *Last modified :/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/* *Filename :/s@:.*$@\=": ".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
" 判断前7行代码里面,是否有Last modified这个单词,
" 如果没有的话,代表没有添加过作者信息,需要新添加;
" 如果有的话,那么只需要更新即可
function TitleDet()
let n=1
"默认为添加
while n < 7
let line = getline(n)
if line =~ '^\*\s*\S*Last\smodified\s\s:\s\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction
"==============================================================================
"---------------------------- Configration Override -------------------------
"==============================================================================
" 设定背景透明
hi Normal guibg=NONE ctermbg=NONE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment