vimrc

vimrc配置

set nocompatible
call pathogen#infect() 
filetype plugin indent on
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileformats=unix,dos
"ed ++ff=dos %
"set ff?

set nu
set cursorline
"set cursorcolumn
set showmatch
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set cindent 
set hlsearch
set laststatus=2
" don't use swp file
set noswapfile

filetype on
filetype indent on
syntax enable
syntax on

set backspace=indent,eol,start
" colorscheme desert
" colorscheme ron
colorscheme default
set t_Co=256

cabbrev q <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'close' : 'q')<CR>

"NERDTree快捷键
nmap <C-n> :NERDTreeToggle <CR>
noremap .n :NERDTreeFind <CR>

" NERDTree.vim
let g:NERDTreeWinPos="right"
let g:NERDTreeWinSize=30
let g:NERDTreeShowLineNumbers=0
let g:neocomplcache_enable_at_startup = 1 
"修改树的显示图标
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'
let NERDTreeShowHidden = 1
"打开vim时如果没有文件自动打开NERDTree
" autocmd vimenter * if !argc()|NERDTree|endif
"当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

"vim-multiple-cursors
let g:multi_cursor_use_default_mapping=0
" Default mapping
let g:multi_cursor_next_key='.m'
let g:multi_cursor_prev_key='.p'
let g:multi_cursor_skip_key='.x'
let g:multi_cursor_quit_key='<Esc>'

nmap <C-l> :TagbarToggle<CR>
"nmap <C-T> :pop<CR>
" 启动时自动focus
"let g:tagbar_ctags_bin = "$HOME/work/source/ctags/ctags"
let g:tagbar_autofocus = 0
let g:tagbar_left = 1
"let g:tagbar_width = 25
let g:tagbar_indent = 1
let g:tagbar_singleclick = 1
let g:tagbar_autoclose=1
let g:tagbar_sort = 0

let g:lightline = {
            \ 'colorscheme': 'PaperColor_light',
            \ 'active': {
            \   'right': [[ 'syntastic', 'lineinfo' ], ['percent'], 
            \             [ 'fileformat', 'fileencoding', 'filetype' ], [ 'prototype' ] ]
            \ },
            \ 'component_function': {
            \   'prototype': 'Tagbar_prototype',
            \ },
            \ 'subseparator': { 'left': '|', 'right': '|' }
            \ }

function! Tagbar_prototype()
    return tagbar#currenttag('%s', 'No current tag') . " |"
endfunction

function! RestoreSession()
    if argc() == 0
        if filereadable("./.pro_session.vim")
            execute 'source ./.pro_session.vim'
        end
        if filereadable("./.view.vim")
            execute 'source ./.view.vim'
        end
    end
endfunction

autocmd VimEnter * call RestoreSession()

nmap <C-\>se 
	\:NERDTreeClose <CR>
	\:TagbarClose <CR>
	\:cclose <CR>
	\:mkview! ./.view.vim <CR>
    \:mksession! ./.pro_session.vim <CR>
	\:wa <CR>


" mark 设置
nmap <F2> \m
" 由于保存session之后再次打开coloschem的背景会覆盖mark故需要重新设置一次,
" 同时需要将自定义的语法高亮重新设置
nmap <leader><F2> :colorscheme ron <CR>
            \:set cursorline <CR>
            \:syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2 <CR>
            \:syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1 <CR>
            \:hi cFunctions gui=NONE cterm=bold  ctermfg=blue <CR>
            \:hi PmenuSel ctermbg=White <CR>
            \:hi CursorLine term=bold cterm=bold guibg=Grey40 <CR>

nmap <F3> \#
nmap <F4> \*

nmap <leader><F5> :MarkClear<CR>
	\:noh<CR>

" delete the appended spaces and tabs
nmap <F5> :%s/\s\+$//g

" ------------------------------------------------------------------------------
nmap <F6> :set nowrap <CR>
nmap <leader><F6> :set wrap <CR>
nmap <leader>zf zf% 

" ------------------------------------------------------------------------------
nnoremap <silent> <Leader>l ml:execute 'match Search /\%'.line('.').'l/'<CR>
nnoremap <silent> <Leader>lc :match<CR>

" ------------------------------------------------------------------------------
nmap <F8> :Dox <CR>
" ------------------------------------------------------------------------------

nmap <F10> :set nonu<CR>
nmap <leader><F10> :set nu<CR>
nmap .m :marks <CR>
"==================jumplist for gj================"
function! GotoJump()
	jumps
	let j = input("Please select your jump: ")
	if j != ''
		let pattern = '\v\c^\+'
		if j =~ pattern
			let j = substitute(j, pattern, '', 'g')
			execute "normal " . j . "\<c-i>"
		else
			execute "normal " . j . "\<c-o>"
		endif
	endif
endfunction
nmap <silent>gj :call GotoJump()<CR>

nmap <F11> :set ts=4<CR>
	\:set expandtab<CR>
	\:%retab!<CR>

" ------------------------------------------------------------------------------
let g:ctrlp_max_height=15
nmap <C-j> :cnext <CR>
nmap <C-k> :cprev <CR>
nnoremap <silent> <C-p> :Files<CR>

"nmap <leader>qf <Plug>window:quickfix:toggle
nmap <leader>qf <Plug>(qf_qf_toggle)
    \:pc <CR>

let g:qf_auto_open_quickfix=0
let g:qf_auto_quit=1
nmap .s :cwindow<CR>
	\:SaveList 

nmap .l :cwindow<CR>
	\:LoadList 

" clear quickfix window
nmap .c :call setqflist([])<CR>

" ------------------------------------------------------------------------------
" cscope, quickr设置
let g:quickr_cscope_autoload_db = 0
let g:quickr_cscope_use_qf_g = 1
let g:quickr_preview_on_cursor=1
let g:gutentags_project_root=['.cscope']
let g:gutentags_add_default_project_roots = 0
"let g:gutentags_ctags_executable = "/proj/shizhai/work/source/ctags/ctags"
" 所生成的数据文件的名称 "
" let g:gutentags_ctags_tagfile = '.tags'
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录 "
" 检测 .cscope/不存在就新建 "
"let s:vim_tags = expand('./.cscope')
let s:vim_tags = '.cscope'
"silent! call mkdir(s:vim_tags, 'p')
"let g:gutentags_ctags_exclude=[]
if isdirectory(s:vim_tags)
    let g:gutentags_cache_dir = s:vim_tags
    let g:gutentags_file_list_command = 'cat ./.cscope/cscope.files'
    "let s:profiletag="/proj/shizhai/work/proj/profile/ignoretags"
    "if filereadable(s:profiletag)
    "    let s:lines = readfile(s:profiletag)
    "    for s:line in s:lines
    "        call add(g:gutentags_ctags_exclude, s:line)
    "    endfor
    "endif
endif
"let g:gutentags_debug=1
"let g:gutentags_trace = 1
" 配置 ctags 的参数 "

if has("cscope")
	set csprg=/usr/bin/cscope
	set csto=1
	" add any database in current directory
	if filereadable(".cscope/cscope.out")
	    cs add .cscope/cscope.out
	" else add database pointed to by environment
	elseif $CSCOPE_DB != ""
	    cs add $CSCOPE_DB
	endif
	set csverb
endif
nmap cs <plug>(n_quickr_cscope_symbols)
nmap cg <plug>(n_quickr_cscope_global)
nmap cc <plug>(n_quickr_cscope_callers)
nmap cf <plug>(n_quickr_cscope_files)
nmap ci <plug>(n_quickr_cscope_includes)
nmap cd <plug>(n_quickr_cscope_functions)

"nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
"nmap cs :cs find s 
"nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
"nmap cg :cs find g 
"nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
"nmap cc :cs find c 
"nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
"nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
"nmap <C-\>f :cs find f <C-R>=expand("<cword>")<CR><CR>
"nmap cf :cs find f 
"nmap <C-\>i :cs find i ^<C-R>=expand("<cword>")<CR>$<CR>
"nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>

map <F9> :exec "!update_tag 1 1abcdefg &"<CR>
            \: cs reset <CR><CR>

execute 'augroup autoscope_buffer'
execute '  autocmd!'
execute '  autocmd BufWritePost * silent exec "!update_tag 0 ".expand("%")." &"'
execute '  autocmd BufWritePost * silent :cs reset'
execute 'augroup end'

" ------------------------------------------------------------------------------
" undo 配置
set undofile
set undodir=~/.vim/.undo
set undolevels=1000         " How many undos
set undoreload=10000        " number of lines to save for undo

"引入myjl插件可以动态remove jumplist item,注释上述
" 设置提示窗口选中条目颜色
hi PmenuSel ctermbg=White
hi CursorLine term=bold cterm=bold guibg=Grey40
hi MatchParen term=reverse ctermbg=242 guibg=Grey40

let g:acp_enableAtStartup = 1
let g:acp_behaviorKeywordLength = 1

" ------------------------------------------------------------------------------
let g:indentLine_color_term = 2
"let g:indentLine_bgcolor_term = 239
let g:indentLine_bgcolor_gui = '#FFFFFF'
"let g:indentLine_char_list = ['|', '¦', '┆', '┊']
"let g:indentLine_char = '┆'

" ------------------------------------------------------------------------------
"新建.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: shizhai")
        call append(line(".")+2, "\# mail: ysprogram@163.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      : shizhai")
        call append(line(".")+2, "* Mail        : ysprogram@163.com")
        call append(line(".")+3, "* Created Time: ".strftime("%c"))
        call append(line(".")+4, "*/")
        call append(line(".")+5, "")
    endif
    if &filetype == '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, "#include <stdlib.h>")
        call append(line(".")+8, "")
    endif
    "新建文件后,自动定位到文件末尾
    autocmd BufNewFile * normal G
endfunc

" 在接受补全后不分裂出一个窗口显示接受的项
set completeopt-=preview
let g:ycm_show_diagnostics_ui = 0

vim插件及进阶

我的博客

posted @ 2020-07-28 11:21  石斋  阅读(248)  评论(0编辑  收藏  举报