vimrc

if has("syntax")
syntax on
endif
set nocompatible "取消vi 兼容模式 "{{{ paste mode f6,f7
:map <F6> :set paste<CR>
:map <F7> :set nopaste<CR>
:imap <F6> <C-O>:set paste<CR>
:imap <F7> <nop>
:set pastetoggle=<F6>
"}}} "{{{ fold
set foldenable " 开始折叠
set foldmethod=syntax " 设置语法折叠
set foldcolumn=0 " 设置折叠区域的宽度
setlocal foldlevel=0 " 设置折叠层数
"set foldopen=all "光标到达折叠快时,自动打开
set foldclose=all " 离开代码块后,自动折叠
" 用空格键来开关折叠
nnoremap <space> zi "}}}
set mouse=v "可视模式
set mouse=a " Enable mouse usage (all modes) 启用鼠标方便翻页,移动光标 set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching set nobackup "no backup
set autoread " 设置当文件被改动时自动载入
set autowrite " Automatically save before commands like :next and :make
set hidden " Hide buffers when they are abandoned set nu "show line number
set ruler "show cursor site in right below
set tabstop=4 " 统一缩进为4
set shiftwidth=4
set incsearch " 输入字符串就显示匹配点
set hlsearch " 高亮度搜寻
set autoindent "自动缩进
set cindent set completeopt=longest,menu
set completeopt=preview,menu "代码补全
"{{{start----- 自动补全 -----------------
: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
"}}} "end-------------------------------- "----- 打开文件类型检测-----------------
filetype plugin indent on au BufNewFile,BufRead *.h set filetype=h
"start---------- definition SetTitle() ------------------------------------ autocmd BufNewFile *.cpp,*.c,*.h,*.sh,*.java exec ":call SetTitle()"
func SetTitle()
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: ims")
call append(line(".")+2, "\# Created Time: ".strftime("%c"))
call append(line(".")+3, "\#########################################################################")
call append(line(".")+4, "\#!/bin/bash")
call append(line(".")+5, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: ims")
call append(line(".")+2, " > Created Time: ".strftime("%c"))
call append(line(".")+3, " ************************************************************************/")
call append(line(".")+4, "")
endif if &filetype == 'cpp'
call append(line(".")+5, "#include<iostream>")
call append(line(".")+6, "using namespace std;")
call append(line(".")+7, "")
call append(line(".")+8, "int main()")
call append(line(".")+9, "{")
call append(line(".")+10, "\t")
call append(line(".")+11, "\treturn 0;")
call append(line(".")+12, "}")
endif if &filetype == 'h'
let tem= expand("%")
let lens= strlen(tem)
let substr = strpart(tem,0,lens-2)
let headstr = toupper(substr).'_H'
call append(line(".")+5, '#ifndef '.headstr)
call append(line(".")+6, '#define '.headstr)
call append(line(".")+7, "")
call append(line(".")+8, " ")
call append(line(".")+9, "#endif")
set filetype=cpp
endif if &filetype == 'c'
call append(line(".")+5, "#include<stdio.h>")
call append(line(".")+6, "")
call append(line(".")+7, "")
call append(line(".")+8, "int main()")
call append(line(".")+9, "{")
call append(line(".")+10, "\t")
call append(line(".")+11, "\treturn 0;")
call append(line(".")+12, "}")
endif normal 12G"
endfunc
au BufRead *.h set filetype=cpp "end----------- SetTitle() -------------------------------- "start------- set title of file of .py ----------
autocmd BufNewFile *.py exec ":call SetTitleOfFilePy()"
func SetTitleOfFilePy()
call setline(1,"\#! /usr/bin/python3.5")
call append(line("."), "\# -*- coding: UTF-8 -*-")
call append(line(".")+1, "\####################################################################")
call append(line(".")+2, "\# File Name: ".expand("%"))
call append(line(".")+3, "\# Author: ims")
call append(line(".")+4, "\# Created Time: ".strftime("%c"))
call append(line(".")+5, "\####################################################################")
call append(line(".")+6, "")
call append(line(".")+7, "")
normal 9G
endfunc
"end-------------------------------------------- "start------运行.c/.cpp/.java/.sh文件-----------------
nnoremap <F4> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "! ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -std=c++11 -o %<"
exec "! ./%<"
elseif &filetype == 'java' :
exec "!javac %"
exec "!java %<"
elseif &filetype == 'sh'
exec "!chmod +x %"
:!./%
endif
endfunc
"end------------------------------------------
"start------运行.py 文件 <F4> ---------------- nnoremap <F3> :call RunPy()<CR>
func! RunPy()
exec "w"
exec "!chmod +x %"
:!./%
endfunc
"end----------------------------------- "{{{ cscope setting
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
"}}} "{{{ CtrlP Settings
" two setting can prevent change of ctrlp_working_path
set noautochdir
let g:ctrlp_working_path_mode = 0
"}}} "{{{ map ctags,srcExpl,NerdTree:F8,F9,F10,F12
" Open and close the taglist.vim separately
nnoremap <F9> :TrinityToggleTagList<CR>
" Open and close the srcexpl.vim separately
nnoremap <F10> :TrinityToggleSourceExplorer<CR>
" Open and close the NERD_tree.vim separately
nnoremap <F12> :TrinityToggleNERDTree<CR>
" Open and close all the three plugins on the same time
"nnoremap <F12> :TrinityToggleAll<CR>
"}}} "add command from tutor :let mapleader = "\\"
:let maplocalleader = "\\"
"{{{ my shortcut key
:nnoremap <localleader>q :q<cr>
:nnoremap <localleader>qq :q!<cr>
:nnoremap <localleader>wq :wq<cr>
:nnoremap <localleader>wa :wa<cr>
:nnoremap <localleader>qa :qa<cr>
:nnoremap <localleader>s :%s/
:nnoremap <localleader>sh :ConqueTerm bash <cr>
:nnoremap <localleader>shs :ConqueTermSplit bash<cr>
:nnoremap <localleader>shv :ConqueTermVSplit bash<cr>
:nnoremap <localleader>sht :ConqueTermTab bash<cr> :nnoremap <localleader>y "+y<cr>
:nnoremap <localleader>yy "+yy<cr>
:nnoremap <localleader>yw "+yw<cr>
:nnoremap <localleader>/ :/\<\>
:nnoremap <localleader>? :?\<\> :inoremap <c-d> <esc>ddo
:nnoremap <localleader>ev :vsplit$MYVIMRC<cr>
:nnoremap <localleader>ms :vsplit $VIMRUNTIME/colors/ims.vim<cr>
:nnoremap <localleader>sv :source$MYVIMRC<cr>
:inoremap jk <esc>
:nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
:nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
:autocmd FileType cpp nnoremap <buffer> <localleader>c I//<esc>
:autocmd FileType python nnoremap <buffer> <localleader>c I#<esc>
:autocmd FileType python :iabbrev <buffer> if if()<left>
:autocmd FileType cpp :iabbrev <buffer> for for(int i=0; i< ; i++)<esc>7h
:autocmd FileType c :iabbrev <buffer> for for(int i=0; i< ; i++)<esc>7h
"}}} "{{{ cscope cs find
:nnoremap <c-@> :cs f
"}}} "{{{ format text
nmap <tab> V>
nmap <s-tab> V<
vmap <tab> >gv
vmap <s-tab> <gv
"}}} "sdvc{{{
set keywordprg=sdcv\ -u\ 朗道英汉字典5.0
function! Mydict()
let retstr=system('sdcv '.expand("<cword>"))
windo if expand("%")=="dict-win" |q!|endif
30vsp dict-win
setlocal buftype=nofile bufhidden=hide noswapfile
1s/^/\=retstr/
1
endfunction
nnoremap F :call Mydict()<CR>
"use sdcv instead man
:set keywordprg=sdcv
"}}} "{{{ minibufexplore settings
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
let g:bufExplorerMaxHeight=3
"}}} "{{{ Colors Settings
colorscheme ims
set guifont=Consolas:h13:cANSI
"}}} set clipboard+=unnamedplus

ims.vim

" Vim color file modify from industrial
" Maintainer: ims
let colors_name = "ims"
" Remark: "industry" stands for 'industrial' color scheme. In industrial
" HMI (Human-Machine-Interface) programming, using a standard color
" scheme is mandatory in many cases (in traffic-lights for example):
" LIGHT_RED is 'Warning'
" LIGHT_YELLOW is 'Attention'
" LIGHT_GREEN is 'Normal'
" LIGHT_MAGENTA is 'Warning-Attention' (light RED-YELLOW)
" LIGHT_CYAN is 'Attention-Normal' (light YELLOW-GREEN).
" BLACK is Dark-High-Contrast Background for maximum safety.
" BLUE is Shade of BLACK (not supposed to get attention).
"
" Industrial color scheme is by nature clear, safe and productive.
" Yet, depends on the file type's syntax, it might appear incorrect.
" Reset to dark background, then reset everything to defaults:
set background=dark
highlight clear
if exists("syntax_on")
syntax reset
endif
" First set Normal to regular white on black text colors:
hi Normal ctermfg=LightGray ctermbg=233 guifg=#dddddd guibg=Black " Syntax highlighting (other color-groups using default, see :help group-name):
hi Comment cterm=NONE ctermfg=DarkCyan gui=NONE guifg=#00aaaa "包括非活动 buf explore 文件名
hi Constant cterm=NONE ctermfg=LightCyan gui=NONE guifg=#00ffff
hi Identifier cterm=NONE ctermfg=LightMagenta gui=NONE guifg=#ff00ff
hi Function cterm=NONE ctermfg=LightGreen gui=NONE guifg=#00ff00
hi Statement cterm=NONE ctermfg=White gui=bold guifg=#ffffff
hi PreProc cterm=NONE ctermfg=Yellow gui=NONE guifg=#ffff00
hi Type cterm=NONE ctermfg=LightGreen gui=bold guifg=#00ff00
hi Special cterm=NONE ctermfg=Yellow gui=NONE guifg=#ff0000 "包括活动 buf explore 文件名
hi Delimiter cterm=NONE ctermfg=Yellow gui=NONE guifg=#ffff00
hi Statement cterm=bold ctermfg=green "system function hi StatusLine cterm=none ctermfg=DarkCyan ctermbg=234 guifg=blue guibg=darkgray gui=none
hi StatusLineNC cterm=none ctermfg=235 ctermbg=235 guifg=black guibg=darkgray gui=none
hi VertSplit cterm=none ctermfg=DarkCyan ctermbg=234 guifg=black guibg=LightRed gui=none
hi CursorLine cterm=none ctermbg=235
hi CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
set cul
"set cuc hi LineNr ctermfg=DarkCyan ctermbg=234 hi MatchParen ctermfg=16 ctermbg=208 cterm=bold
hi ModeMsg ctermfg=red " color of insert
hi MoreMsg ctermfg=229
hi Operator ctermfg=Yellow hi Directory ctermfg=118 cterm=bold
hi Error ctermfg=219 ctermbg=89
hi ErrorMsg ctermfg=199 ctermbg=16 cterm=bold
hi Exception ctermfg=118 cterm=bold
hi Float ctermfg=135
hi FoldColumn ctermfg=67 ctermbg=16
hi Folded ctermfg=67 ctermbg=16
hi Function ctermfg=118
hi Identifier ctermfg=208
hi Ignore ctermfg=244 ctermbg=232
hi IncSearch ctermfg=Yellow ctermbg=red hi Keyword ctermfg=161 cterm=bold
hi Label ctermfg=229 cterm=none
hi Macro ctermfg=193
hi SpecialKey ctermfg=81 hi Type ctermfg=118 cterm=none
hi Structure ctermfg=118 cterm=none
hi Macro ctermfg=161 cterm=bold
hi PreCondit ctermfg=161 cterm=bold hi StorageClass ctermfg=208
"hi Tag ctermfg=161
hi Title ctermfg=166
hi Todo ctermfg=231 ctermbg=232 cterm=bold
"test augroup hightlightFun
autocmd!
" hilight function name
autocmd BufNewFile,BufRead,BufWrite * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
autocmd BufNewFile,BufRead,BufWrite * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
hi cfunctions ctermfg=81 "(这一行就是给函数名加颜色的)
autocmd BufNewFile,BufRead,BufWrite * :syntax match operators "[=\*\&\%\-\>\<\+]"
autocmd BufNewFile,BufRead,BufWrite * :syntax match operators "\<WORD32\>"
autocmd BufNewFile,BufRead,BufWrite * :syntax match operators "\<WORD16\>"
autocmd BufNewFile,BufRead,BufWrite * :syntax match operators "\<BYTE\>"
hi operators ctermfg=DarkCyan "
augroup END :function SetLocalStatusLine()
: setlocal statusline =%f
setlocal statusline +=%2*%r%*
setlocal statusline +=%=%y
setlocal statusline +=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\"+\":\"\").\"]\"}
setlocal statusline +=[%{&ff}][a:%03.3b]
setlocal statusline +=[r:%l/%2*%L%*,c:%c]
setlocal statusline +=%1*%m%*
setlocal statusline +=%3*[%p%%]%* hi User1 cterm=bold ctermfg=1 ctermbg=234
hi User2 cterm=none ctermfg=11 ctermbg=234
hi User3 cterm=none ctermfg=10 ctermbg=234
set laststatus=2
:endfunction augroup filetype_statusline
autocmd!
autocmd FileType c call SetLocalStatusLine()
autocmd FileType cpp call SetLocalStatusLine()
autocmd FileType python call SetLocalStatusLine()
augroup END set showcmd "vim -R file 只读
"vim -M 不能修改模式
"Cursor光标
"ErrorMsg命令行中的错误提示
"Folded折叠行
"LineNr行号
"NonText非文本区(控制字符和一些特殊字符和编辑器空白区等)
"Normal编辑区一般文本的前景和背景色
"Search搜索
"StatusLine状态行
"Visual圈选区 hi Search cterm=none ctermfg=red ctermbg=185
hi Visual cterm=none ctermbg=239
05-02 03:24