""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " __ __ __ __ __ ______ ______ ______ ______ " /\ \ / / /\ \ /\ "-./ \ /\ ___\ /\ __ \ /\ ___\ /\__ _\ " \ \ \"/ \ \ \ \ \ \-./\ \ \ \ __\ \ \ __ \ \ \___ \ \/_/\ \/ " \ \__| \ \_\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \/\_____\ \ \_\ " \/_/ \/_/ \/_/ \/_/ \/_/ \/_/\/_/ \/_____/ \/_/ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " chenxuan's vim config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " base config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let mapleader = "," " use ',' as leader set nocompatible " set not compatible with vi filetype on " set file type detection filetype plugin on " set load plugin by file type set noeb " turn off error syntax prompts syntax enable " highlight enable syntax on " highlight auto set t_Co=256 " open 256 color set vb t_vb= " set no bell set cmdheight=1 " set command height set showcmd " show select line nums in visual set textwidth=0 " close auto enter set ruler " cursor position displayed set laststatus=2 " show status, nvim 3, vim 2 set number " show line number set relativenumber " show relativenumber set cursorline " highlight current line set whichwrap+=<,>,h,l " set the cursor key across rows set ttimeoutlen=0 " set response time set virtualedit=block,onemore " allows the cursor appear after last character set noshowmode " disable bottom mode displayed 'insert' set hidden " allows toggle buffers in unsaved set matchpairs+=<:> " make % can jump <> set background=dark " set background color set maxmempattern=10240 " add max pattern memory size(10M) " set jumpoptions=stack " set jump to stack instead of list """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " code indent and typesetting config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set autoindent " set auto indent set cindent " set indent by c/cpp set cinoptions=g0,:0,N-s,(0 " set c/cpp indent way set smartindent " smart choose indent way filetype indent on " intelligent indent for different languages set noexpandtab " set forbidden space to replace tab set tabstop=4 " number of spaces used by tabs when editing set shiftwidth=4 " number of spaces tab occupies when formatting set softtabstop=4 " set 4 spaces as tabs set smarttab " use tabs at the beginning of lines and segments set nowrap " disable divide a line to two set backspace=2 " use enter key to normally handle input, eol, start, etc set sidescroll=10 " sets the number of characters to scroll to the right set nofoldenable " disables folding code set list lcs=tab:¦\ " default show indent line set sidescroll=0 " set move line when cursor too right set sidescrolloff=4 " set curor line to right " set scrolloff=5 " set cursor line to bottom """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " code inside completion config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set wildmenu " vim itself named line pattern intelligent completion set completeopt-=preview " completion window is not displayed when completed, only list is displayed """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " search config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set hlsearch " highlight search results set incsearch " turn on real-time search set ignorecase " search is not case sensitive set smartcase " search smart match case """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " cache config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nobackup " set no back up set noswapfile " disable create temp file set autoread " if file change by others,load it auto set autowrite " set auto save set confirm " if quit without save,make confirm """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " encode config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set langmenu=zh_CN.UTF-8 " set langmenu encode utf-8 set helplang=cn " set helplang Chinese set termencoding=utf-8 " set term encode set encoding=utf8 " set encode set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030 " set detect encode of file """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " gvim/macvim config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if has("gui_running") set guifont=DroidSansMono\ Nerd\ Font\ Regular\ 14 " set fonts in gvim set guioptions-=m " hide the menu bar set guioptions-=T " hide tool bar set guioptions-=L " hide left scroll bar set guioptions-=r " hide right scroll bar set guioptions-=b " hide bottom scroll bar set showtabline=0 " hide tab bar set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50 endif " load vim default plugin runtime macros/matchit.vim " key map and inside config setting " reload .vimrc nnoremap s :source $MYVIMRC nnoremap S :source =expand('%:p') " install and clean plug nnoremap i :PlugInstall nnoremap c :PlugClean " vim-buffer nnoremap :call ChangeBuffer('p') nnoremap :call ChangeBuffer('n') nnoremap H :call ChangeBuffer('p') nnoremap L :call ChangeBuffer('n') nnoremap &bt==''?":w":&bt=='terminal'?"i\": \ getwininfo(win_getid())[0]["quickfix"]!=0?"\:cclose": \ getwininfo(win_getid())[0]["loclist"]!=0?"\:lclose":"\" nnoremap d :call CloseBuf() func! s:ChangeBuffer(direct) abort if &bt!=''||&ft=='netrw'|echoerr "buftype is ".&bt." cannot be change"|return|endif if a:direct=='n'|bn else|bp|endif while &bt!='' if a:direct=='n'|bn else|bp|endif endwhile endfunc func! s:CloseBuf() if &bt!=''||&ft=='netrw'|bd|return|endif let buf_now=bufnr() let buf_jump_list=getjumplist()[0]|let buf_jump_now=getjumplist()[1]-1 while buf_jump_now>=0 let last_nr=buf_jump_list[buf_jump_now]["bufnr"] let last_line=buf_jump_list[buf_jump_now]["lnum"] if buf_now!=last_nr&&bufloaded(last_nr)&&getbufvar(last_nr,"&bt")=='' execute ":buffer ".last_nr|silent! execute ":bd ".buf_now|return else|let buf_jump_now-=1 endif endwhile bp|while &bt!=''|bp|endwhile execute "bd ".buf_now endfunc " insert model to move cursor imap imap imap imap " move in insert inoremap inoremap ^ inoremap vnoremap inoremap w inoremap D inoremap CtrlB() func! s:CtrlB() if pumvisible()|return "\" elseif getline('.')[col('.')-2]==nr2char(9) let s:pos=col('.')|let s:result="" while s:pos!=0|let s:result=s:result."\"|let s:pos-=1|endwhile return s:result else return "\b" endif endfunc " use jk map for esc inoremap jk " select paste snoremap "0P " delete line inoremap dd snoremap dd " find next {} nnoremap /{:nohva} nnoremap ?}:nohva{ inoremap /{:nohva} vnoremap /{:nohva} vnoremap ?}:nohva{ inoremap ?}:nohva{ " yank to system vnoremap y "+y nnoremap y "+y " paste to system nnoremap p "+p nnoremap P "+P vnoremap p "+p vnoremap P "+P augroup ReadPost au! autocmd FileType java,c,cpp set commentstring=//\ %s autocmd TerminalOpen * if &bt=='terminal'|setlocal norelativenumber|setlocal nonumber|endif autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | execute "normal! zz" | endif autocmd BufDelete * if expand('%:p')!=''&& &bt==""|let g:map_recent_close[expand('%:p')] = \{'lnum':line('.'),'col':col('.'),'text':'close at '.strftime("%H:%M"),'time':localtime()} \|endif autocmd MenuPopup * call RightMouseMenu() augroup END " global popupmenu let g:rightmouse_popupmenu={} let g:rightmouse_extramenu=[] func AddMouseMenu(func) if type(a:func)!=2|echoerr 'func must be function'|return|endif call add(g:rightmouse_extramenu,a:func) endfunc func RightMouseMenu() if has_key(g:rightmouse_popupmenu, &ft)|call g:rightmouse_popupmenu[&ft]() else|call MouseConfig()|endif if !empty(g:rightmouse_extramenu)|for Func_name in g:rightmouse_extramenu|call Func_name()|endfor|endif endfunc " load the file last edit pos let g:map_recent_close={} func! s:GetRecentClose() let s:list=[] for [key,value] in items(g:map_recent_close) let value['filename']=key call insert(s:list,value) endfor let s:func={m1,m2 -> m1['time']>m2['time']?-1:1} call sort(s:list,s:func) call setqflist(s:list,'r') copen endfunc nnoremap q :call GetRecentClose() " ctags config command! -nargs=? TagCreate call s:CreateTags(,0) command! -nargs=? TagPwd call s:CreateTags(,1) command! -nargs=0 TagKind echo system("ctags --list-maps") command! -nargs=1 -complete=tag TagFind exec ":ts /". command! -nargs=1 -complete=file TagSave if exists("g:tag_file")&&filereadable(g:tag_file)|call system("cp ".g:tag_file." ".)|endif cab TagSave TagSave =termtask#Term_get_dir()/tags nnoremap FindTags(expand('')) vnoremap "sy:TagFind =@s func! s:FindTags(str) let list=taglist(a:str) if len(list)==1|return "\"|else|return ":ts ".a:str."\"|endif endfunc func! s:CreateTags(arg,flag) if exists("g:tag_file")|exec "set tags-=".g:tag_file|endif|let g:tag_file=tempname() if a:flag|let g:tag_file="./tags"|endif if a:arg!=""|let arg=" --languages=".a:arg|else|let arg=" "|endif let dir=termtask#Term_get_dir() call job_start("ctags -f ".g:tag_file.arg." --tag-relative=no -R ".dir, \{"close_cb":"CreateTagCB","err_cb":"CreateTagErrCB"}) exec "set tags+=".g:tag_file endfunc func! CreateTagErrCB(chan,msg) echoerr a:msg endfunc func! CreateTagCB(chan) call popup_create("tags create success", #{pos:'botright',time: 1000,highlight: 'WarningMsg',border: [],close: 'click',}) endfunc " termdebug let g:termdebug_wide=1 nnoremap d :packadd termdebug:Termdebug nnoremap :packadd termdebug:Termdebug nnoremap :Break nnoremap :Over nnoremap :Step " term console func! Tapi_EditFile(bufnum,arglist) execute ":wincmd p" if isdirectory(a:arglist[0]) execute ":cd " . a:arglist[0]|echo "cd ".a:arglist[0]." success" else execute ":edit " . a:arglist[0]|echo "open ".a:arglist[0]." success" endif if len(a:arglist)>1|call term_sendkeys(a:bufnum,a:arglist[1]."\")|endif if len(gettabinfo())>1|tabclose|if filereadable(a:arglist[0])|execute ":edit " . a:arglist[0]|endif|endif endfunc tnoremap tnoremap printf '\033]51;["call","Tapi_EditFile",["%s/%s"]]\007' $PWD tnoremap printf '\033]51;["call","Tapi_EditFile",["%s/%s","exit"]]\007' $PWD tnoremap exit nnoremap T :bo term ++rows==winheight(0)/3 nnoremap t :vert term nnoremap t :tabe:execute ":vert term ++curwin ++close " nnoremap T :let @s=expand('%:p:h'):tabe:call term_start($SHELL,{"cwd":"=@s","curwin":1,"term_finish":"close"}) " lazygit nnoremap g :call ShellOpenFile("LAZYGIT_FILE"):call term_start("lazygit",{"close_cb":"ShellOpenFile","curwin":1,"term_finish":"close"}) nnoremap G :let @s=expand('%'):tabe:vert term ++curwin ++close lazygit -f s func! s:ShellOpenFile(event) abort if type(a:event)==type("") tabe if !exists("s:shell_open_file")||getenv(a:event)==v:null let s:shell_open_file=tempname()|let s:shell_open_env=a:event call setenv(a:event,s:shell_open_file) endif return endif tabclose if exists("s:shell_open_file")&&filereadable(expand(s:shell_open_file))&&getenv(s:shell_open_env)==s:shell_open_file&&filereadable(expand(s:shell_open_file)) call setenv(s:shell_open_env, v:null) for line in readfile(s:shell_open_file) let msg=split(line) let file=msg[0] if filereadable(file) execute ":edit ".file elseif isdirectory(file) execute ":cd ".file endif if len(msg)>1&&msg[1]!=1|call cursor(msg[1],0)|endif endfor endif endfunc " lf config define nnoremap E :call ShellOpenFile("OPEN_FILE"):call term_start("lf =getenv('HOME')",{"close_cb":"ShellOpenFile","curwin":1}) nnoremap e :call ShellOpenFile("OPEN_FILE"):call term_start("lf",{"close_cb":"ShellOpenFile","curwin":1}) " fzf self defile func! s:FzfFind(command) vert call term_start('bash',{'term_finish':"close"}) call term_sendkeys(term_list()[0],a:command."\") endfunc let g:fzf_temp_file="" func! Tapi_Fzf(bufnum,arglist) wincmd p|let temp=getenv("FZF_VIM") if len(a:arglist)>1|call term_sendkeys(a:bufnum,a:arglist[1]."\")|endif if temp!=v:null for line in readfile(g:fzf_temp_file) let list=matchstr(line,"\/\^.*") if a:arglist[0]=="0"|let @/="\\V\\^".line."\\$"|else|let @/="\\V".escape(strpart(list,1,len(list)-2),"^$")|endif call feedkeys('n','in')|set hlsearch endfor endif endfunc nnoremap z :call FzfFind('printf "\033]51;[\"call\",\"Tapi_EditFile\",[\"%s/%s\",\"exit\"]]\007" $PWD `fzf --layout=reverse --preview-window=down --preview "head -64 {}"`') nnoremap Z :let fzf_temp_file=tempname():call setenv("FZF_VIM",g:fzf_temp_file):call FzfFind('ctags -x --_xformat="%N %P" -f - =expand('%:p')fzf > $FZF_VIM;printf "\033]51;[\"call\",\"Tapi_Fzf\",[\"$FZF_VIM\",\"exit\"]]\007"') " yank and paste nnoremap p "0p vnoremap p "0p nnoremap P "0P vnoremap P "0P " vimdiff tool cab Diff "Diff ".expand('%:p:h')."/" command! -nargs=1 -bang -complete=file Diff exec ":vert diffsplit ". command! -nargs=0 Remote :diffg RE command! -nargs=0 Base :diffg BA command! -nargs=0 Local :diffg LO " edit binrary func! s:BinraryEdit(args) abort if join(readfile(expand('%:p'), 'b', 5), '\n') !~# '[\x00-\x08\x10-\x1a\x1c-\x1f]\{2,}' echo "not a bin file"|return endif if &readonly|execute ":edit ++bin ".expand('%:p')|endif|setlocal bin if !executable('xxd')|echoerr "xxd not find,install it first"|return|endif echo "transform...please wait..." let g:xxd_cmd=":%!xxd ".a:args silent! execute g:xxd_cmd|let &modified=0|redraw! augroup Binrary au! autocmd BufWritePre let g:bin_pos_now=getcurpos()|silent! exec ":%!xxd -r" autocmd BufWritePost silent! exec g:xxd_cmd|call cursor([g:bin_pos_now[1],g:bin_pos_now[2]]) autocmd BufDelete au! Binrary augroup END endfunc command! -nargs=? Binrary :call BinraryEdit() " change window width nnoremap + nnoremap - nnoremap < nnoremap > " change window pos in normal nnoremap k nnoremap j nnoremap h nnoremap l nnoremap k nnoremap j nnoremap h nnoremap l " change window location nnoremap K nnoremap J nnoremap H nnoremap L " quick fix nnoremap ]q :cnext nnoremap [q :cprevious nnoremap \q :cclose nnoremap =q :copen nnoremap ]Q :cnext:call Qfpopup() nnoremap [Q :cprevious:call Qfpopup() func! s:Qfpopup()abort let dict=getqflist({'all':1})|let pos=dict['idx']|let item=dict['items']|let len=len(dict['items']) if len==0||(pos==1&&item[pos-1]['lnum']==0)|cclose|return|endif|let show=[item[pos-1]['text']] while pos " normal model nnoremenu PopUp.Paste\ Text "+p nnoremenu PopUp.Select\ All ggVG nnoremenu PopUp.Back\ Pos zz nnoremenu PopUp.Next\ Pos zz " fold nnoremenu PopUp.Open\ Fold zO nnoremenu PopUp.Close\ Fold zC " close nnoremenu PopUp.Close\ Mouse :set mouse="" nnoremenu PopUp.-Sep- : " term model tlnoremenu PopUp.Exit\ Term exit endfunc unmenu PopUp call MouseConfig() " default set mouse enable nnoremap =m :unmenu PopUpcall MouseConfig() nnoremap \m :set mouse="" " show indent line nnoremap =i :set list lcs=tab:¦\ nnoremap \i :set nolist " set spell nnoremap =s :setlocal spell nnoremap \s :setlocal nospell " z= is list of change " set wrap nnoremap =r :setlocal wrap:noremap j gj:noremap k gk nnoremap \r :setlocal nowrap:unmap j:unmap k " set line number nnoremap =n :setlocal norelativenumber nnoremap \n :setlocal relativenumbersetlocal number " close/open number nnoremap =N :setlocal norelativenumber:setlocal nonumber:set nolist nnoremap \N :setlocal relativenumber:setlocal number:set list lcs=tab:¦\ " set fold auto,use zE unset all fold,zf create fold nnoremap =z :setlocal fdm=indent:setlocal fen nnoremap \z :setlocal fdm=manual:setlocal nofen nnoremap =o zO nnoremap \o zC nnoremap foldlevel('.')>0?"zc":"\" " tab ctrl nnoremap =t :tabnew nnoremap \t :tabc nnoremap [t :tabp nnoremap ]t :tabn " set search noh nnoremap \h :noh nnoremap =h :set hlsearch " set auto indent file nnoremap = :call IndentSet() func! s:IndentSet()abort let line=matchstr(getline(line('.')),"^\\s*") for temp in getline(line('.')+1, line('$')) let temp=matchstr(temp,"^\\s*")|if temp!=line|break|endif endfor if (len(line)!=0&&line[0]==' ')||(len(temp)!=0&&temp[0]==' ') setlocal expandtab|exec "setlocal shiftwidth=".abs(len(line)-len(temp)) endif echo 'indent ok' endfunc func! g:SetTypeIndex(index_type,index_num) abort if a:index_type=='tab'|setlocal noexpandtab else|setlocal expandtab|endif exec "setlocal shiftwidth=".a:index_num exec "setlocal softtabstop=".a:index_num exec "setlocal softtabstop=".a:index_num endfunc " delete in end of line nnoremap d :%s/ *$//g:noh nnoremap g :syntax match DiffDelete " *$" " delete empty line nnoremap dl :g/^\s*$/d " select search xmap g/ "sy/\V=@s " run macro in visual model xnoremap @ :normal @ " repeat for macro nnoremap @@ " md fold enable let g:markdown_fold_enable=1 " termtask project config command! -nargs=? -complete=customlist,termtask#Term_task_list TaskRun :call termtask#Term_task_run() command! -nargs=0 TaskList :echo termtask#Term_task_list('','','') command! -nargs=0 TaskLoad :call termtask#Term_task_run('') nnoremap c :TaskRun nnoremap C :call termtask#Term_config_edit() " auto read project file " let s:fileway=termtask#Term_get_dir() . '/.config.vim' " if filereadable(s:fileway) " execute 'source ' . s:fileway " endif " get key binding let g:findkey_mode=0 nnoremap h :call findkey#get_key_msg(0) nnoremap -h :call findkey#get_key_msg(1) nnoremap ]h :call findkey#open_file(1) nnoremap [h :call findkey#open_file(0) " show space indent line nnoremap =I :call indentline#Enable() nnoremap \I :call indentline#Disable() " highlight color nnoremap =c :call highlightcolor#Able() nnoremap \c :call highlightcolor#DisAble() " multcursor nnoremap :call multcursor#Choose() nnoremap -s :call multcursor#Toggle() " rainbow-pair nnoremap =b :call rainbow#load() nnoremap \b :call rainbow#clear() " rest test augroup restful au! autocmd BufNewFile,BufRead *.rest silent! call rest#Able() augroup END cab pyj !python3 -m json.tool nnoremap i :call rest#VrcQuery(1) nnoremap I :call rest#VrcQuery(0) " gutter for git let g:gitgutter_sign_able=1 let g:gitgutter_highlight_able=0 nnoremap =g :call gutter#GitGutterAble() nnoremap \g :call gutter#GitGutterDisable() nnoremap [g :call gutter#GitGutterChangeTurn(0,line('.')) nnoremap ]g :call gutter#GitGutterChangeTurn(1,line('.')) nnoremap -g :call gutter#GitGutterRecover() nnoremap zg :call gutter#GitGutterFold() nnoremap :call gutter#GitGutterDiff() " editorconfig nnoremap =E :call editorconfig#Able() nnoremap \E :call editorconfig#Disable() nnoremap -E :call editorconfig#EditconfigFile() " line cword let g:cursorline_delay=0 nnoremap =f :call cursorline#Able() nnoremap -f :call cursorline#Toggle() nnoremap \f :call cursorline#Disable() " ici to tran let g:term_cmd='~/.local/bin/ici' xnoremap i :call termtask#Term_cmd_exec_popup('v') nnoremap i :call termtask#Term_cmd_exec_popup('') " use select area to replace xnoremap s :execute "normal! gv\"sy":%s/\V=escape(@s,'/\.')/=escape(@s,'/\.')/gn nnoremap gs :%s/=@///gn xnoremap gs :execute "normal! gv\"sy":call ReplaceGlobal(@s) func s:ReplaceGlobal(str) abort let escape_char='."' let str=escape(a:str,escape_char)|let replace=escape(input("replace ".a:str." to:",a:str),escape_char) if replace==""|return|endif let sed='sed'|if has('macunix')|let sed='gsed'|endif echo system('find . -path "./.git" -prune -o -type f -exec '.sed.' -i "s|'.str.'|'.replace.'|g" {} +') " reload file exec ":edit ".expand('%') endfunc " object buffer nnoremap =e gg=G onoremap ae :normal! ggVG xnoremap ae :normal! ggVG " object line onoremap il :normal! ^v$BE xnoremap il :normal! ^v$ onoremap al :normal! 0v$ xnoremap al :normal! 0v$ " object argc onoremap aa :call obj#GetArgs('a') onoremap ia :call obj#GetArgs('i') xnoremap aa :call obj#GetArgs('a') xnoremap ia :call obj#GetArgs('i') " object indent onoremap ai :call obj#GetIndent(0) onoremap ii :call obj#GetIndent(1) xnoremap ai :call obj#GetIndent(0) xnoremap ii :call obj#GetIndent(1) " object syntax onoremap ih :call obj#GetSynchl('i') xnoremap ih :call obj#GetSynchl('i') " object bigword onoremap iq :call obj#GetBigWord('i') xnoremap iq :call obj#GetBigWord('i') " object all onoremap i/ :call obj#GetAllObj('i','/') xnoremap i/ :call obj#GetAllObj('i','/') onoremap i- :call obj#GetAllObj('i','-') xnoremap i- :call obj#GetAllObj('i','-') onoremap i. :call obj#GetAllObj('i','.') xnoremap i. :call obj#GetAllObj('i','.') onoremap i* :call obj#GetAllObj('i','*') xnoremap i* :call obj#GetAllObj('i','*') " easy to get obj onoremap i, i< onoremap a, a< xnoremap i, i< xnoremap a, a< onoremap i; i" onoremap a; a" xnoremap i; i" xnoremap a; a" onoremap in i{ onoremap an a{ xnoremap in i{ xnoremap an a{ " sudo to write file func! SaveAsRoot() execute "w !sudo tee % >/dev/null" " reload buffer exec ":edit! ".expand('%') endfunc cab w!! call SaveAsRoot() " quick to change dir " cab cdn cd =expand('%:p:h') cab cdn getcmdtype() == ':' ? "cd ".expand('%:p:h') : "cdn" cab cdr getcmdtype() == ':' ? "cd ".termtask#Term_get_dir() : "cdr" " cmd emacs model cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap " cmd pair let g:pair_map={'(':')','[':']','{':'}','"':'"',"'":"'",'<':'>','`':'`',} func! s:Judge(ch,mode) if a:mode=='c'&&getcmdtype()!=':'|return a:ch|endif if a:mode!='c'|let ch=getline('.')[col('.')-1]|else|let ch=getcmdline()[getcmdpos()-1]|endif if a:ch=='"'||a:ch=="'"||a:ch=='`'|if ch!=a:ch|return a:ch.a:ch."\"|endif|endif if ch==a:ch|return "\"|endif return a:ch endfunc func! s:Backspace(mode) if a:mode!='c' let s:pair=getline('.')[col('.')-1]|let s:pair_l=getline('.')[col('.')-2] else let s:pair=getcmdline()[getcmdpos()-1]|let s:pair_l=getcmdline()[getcmdpos()-2] endif if has_key(g:pair_map, s:pair_l)&&(g:pair_map[s:pair_l]==s:pair)|return "\\\"|else|return "\"|endif endfunc cnoremap ( getcmdtype()==':' ? "()\" : "(" cnoremap [ getcmdtype()==':' ? "[]\" : "[" cnoremap { getcmdtype()==':' ? "{}\" : "{" cnoremap " Judge('"','c') cnoremap ` Judge('`','c') cnoremap ' Judge("'",'c') cnoremap > Judge('>','c') cnoremap ) Judge(')','c') cnoremap } Judge('}','c') cnoremap ] Judge(']','c') cnoremap Backspace('c') " jump > inoremap > Judge('>','i') " set cursor middle nnoremap zz nnoremap zz " set tab indent xnoremap >gv xnoremap smap " enhance gf nnoremap gf gF vnoremap gf gF " set split window nnoremap _ :vsp:bn nnoremap + :sp:bn " edit file nnoremap e :edit=getcwd()/ nnoremap E :edit=expand('%:p:h')/ nnoremap e :edit~/ " open : quick nnoremap ; : xnoremap ; : " bs to delete xnoremap d snoremap " add empty line nnoremap U :call append(line('.')-1,"") nnoremap M :call append(line('.'),"") " make move easy nnoremap $ vnoremap $ nnoremap getline('.')[col('.')-1]>='0'&&getline('.')[col('.')-1]<='9'?"\":"^" vnoremap mode()==#'v'&&line('.')==line('v')?"^":"\" " enhance c-a and c-x nnoremap g getline('.')[col('.')-1]=='9'?"r0":"r".(getline('.')[col('.')-1]+1) nnoremap g getline('.')[col('.')-1]=='0'?"r9":"r".(getline('.')[col('.')-1]-1) " add space func! s:AddSpace() execute("normal! i ")|redraw|let ch=nr2char(getchar()) while ch==' '|execute("normal! i ")|redraw|let ch=nr2char(getchar())|endwhile call feedkeys(ch,'im') endfunc nnoremap :call AddSpace() " scroll in other window nnoremap \u pp nnoremap \d pp " redraw the screen nnoremap R :redr! " ctrl file system command! -nargs=0 -bang Pwd echo expand('%:p') command! -nargs=? -bang Reload exec ":edit ".." ".expand('%') nnoremap S :edit=expand('%') command! -nargs=0 -bang Delete if filereadable(expand('%'))|w|call delete(expand('%'))|call CloseBuf()|execute ":bn"|endif command! -nargs=1 -bang -complete=file Rename let @s=expand('%')|f |w|call delete(@s) cab Rename "Rename ".expand('%:p:h')."/" command! -nargs=1 -bang -complete=file Mkdir echo mkdir() cab Mkdir "Mkdir ".expand('%:p:h')."/" command! -nargs=1 -bang -complete=file Rmdir echo delete(,"d") cab Rmdir "Rmdir ".expand('%:p:h')."/" command! -nargs=0 -bang Write call mkdir(expand("%:p:h"),"p")|write! " use cd to change dir " autoload file func s:SetUpdateTime(delay) abort setlocal readonly if a:delay==""|let delay=1000 else|let delay=a:delay|endif if !exists("s:update_timer")||s:update_timer==-1|let s:update_timer=timer_start(delay, "TimerUpdate",{"repeat":-1})|echo "check begin" else|call timer_stop(s:update_timer)|let s:update_timer=-1|echo "check stop"|setlocal noreadonly|endif endfunc func TimerUpdate(timer) checktime execute "normal! Gzz" endfunc command! -nargs=? -bang Check call s:SetUpdateTime() " select move xnoremap :move '<-2gv xnoremap :move '>+1gv xnoremap yloVpgv xnoremap yhoVpgv xnoremap :move '>+1gv xnoremap :move '<-2gv xnoremap yloVpgv xnoremap yhoVpgv " open link,is default in vim by gx func! s:GotoLink() let s:list=matchstrpos(getline('.'),'https*://\S[^][(){}]*',0) let s:link=s:list[0] while s:list[0]!=''&&(s:list[1]>col('.')||s:list[2]gl :call GotoLink() " set alias iab ;e 1607772321@qq.com iab ;n chenxuan nnoremap \a :iabc nnoremap =a :ab " set function to choose select area func s:GetSelectArea() norm! gv"sy let split_ch="'" if stridx(@s, split_ch)!=-1|let split_ch = '"'|endif return split_ch.@s.split_ch endfunc """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " plug list """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " if your network is not good,change it to mirror " let g:plug_url_format="https://git::@gitee.com/%s.git" call plug#begin('~/.vim/plugged') " begin vim Plug 'chenxuan520/my-vim-dashboard' " function list Plug 'liuchengxu/vista.vim', {'on': 'Vista'} Plug 'preservim/tagbar', {'on': 'Tagbar'} " auto complete Plug 'neoclide/coc.nvim', {'branch': 'release'} " find anything Plug 'Yggdroot/LeaderF', {'do':'./install.sh','tag':'v1.24'} " quick move mouse Plug 'easymotion/vim-easymotion',{'on':['(easymotion-s)','(easymotion-bd-w)']} " pair auto Plug 'jiangmiao/auto-pairs' " file tree left Plug 'preservim/nerdtree', {'on': 'NERDTreeToggle'} " easy align Plug 'godlygeek/tabular', {'on':'Tabularize'} " change surround quick Plug 'tpope/vim-surround' Plug 'tpope/vim-repeat' " quick add comment Plug 'tpope/vim-commentary' " add endif when enter if Plug 'tpope/vim-endwise' " for cpp highlight Plug 'octol/vim-cpp-enhanced-highlight', {'for':'cpp'} " for go highlight Plug 'chenxuan520/vim-go-highlight', {'for':'go'} " for python highlight Plug 'vim-python/python-syntax', {'for':'py'} " statusline of bottom Plug 'vim-airline/vim-airline' " file devicon Plug 'ryanoasis/vim-devicons' " git control Plug 'tpope/vim-fugitive', {'on':['G','Git','GV','GV!']} Plug 'junegunn/gv.vim', {'on':['G','Git','GV','GV!']} " enhance f/t Plug 'rhysd/clever-f.vim' " code snippets Plug 'chenxuan520/vim-snippets' " run shell in async Plug 'skywind3000/asyncrun.vim' " copilot Plug 'exafunction/codeium.vim', {'on': 'Codeium'} " vim-ai Plug 'chenxuan520/vim-ai-doubao', {'on': ['AIChat','AI','AIEdit','AIConfigEdit']} call plug#end() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " plug config setting """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " tokyonight themes set termguicolors let g:tokyonight_style = 'night' " available: night, storm let g:tokyonight_enable_italic = 1 colorscheme tokyonight " onedark themes " let g:onedark_termcolors=256 " colorscheme onedark " set prepare code when new file augroup PreCode autocmd! autocmd BufNewFile *.cpp,*.cc,*.go,*.py,*.sh,*.hpp,*.h,*.html,.config.vim,CMakeLists.txt call VimFastSetPreCode() augroup END " airline let g:airline_theme= "tokyonight" let g:airline_powerline_fonts = 1 let g:airline_extensions = ['tabline' , 'coc', 'branch'] let g:airline_left_sep = '' let g:airline_left_alt_sep = '' let g:airline_right_sep = '' let g:airline_right_alt_sep = '' " nerdtree nnoremap n :NERDTreeToggle nnoremap N :NERDTreeFind let g:NERDTreeFileExtensionHighlightFullName = 1 let g:NERDTreeExactMatchHighlightFullName = 1 let g:NERDTreePatternMatchHighlightFullName = 1 let g:NERDTreeHighlightFolders = 1 let g:NERDTreeHighlightFoldersFullName = 1 let g:NERDTreeDirArrowExpandable='▷' let g:NERDTreeDirArrowCollapsible='▼' let g:NERDTreeWinSize=18 " exit vim if NERDTree is the only window remaining in the only tab. augroup NerdTree autocmd! autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | :bn | endif augroup END " coc.nvim let g:coc_disable_startup_warning = 1 inoremap \ coc#pum#visible() ? coc#pum#next(1): \ CheckBackspace() ? "\" : \ coc#refresh() " seting for diff copilot and coc inoremap \ coc#pum#visible() ? coc#pum#next(1): \ CheckBackspace() ? "\" : \ coc#refresh() " inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" inoremap coc#pum#visible() ? coc#pum#confirm() : "\" inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" function! CheckBackspace() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction " coc find define nmap u (coc-definition) nmap U (coc-type-definition) nmap gd (coc-definition) nmap gD (coc-type-definition) nmap gr (coc-references) nmap gi (coc-implementation) " coc refactor code nmap r (coc-refactor) nmap r (coc-rename) " coc find wrong nmap (coc-diagnostic-prev) nmap (coc-diagnostic-next) nmap [w (coc-diagnostic-prev) nmap ]w (coc-diagnostic-next) nmap -w (coc-fix-current) nnoremap =w :CocList --normal diagnostics nnoremap w :CocList --normal diagnostics " coc text obj xmap if (coc-funcobj-i) omap if (coc-funcobj-i) xmap af (coc-funcobj-a) omap af (coc-funcobj-a) xmap ic (coc-classobj-i) omap ic (coc-classobj-i) xmap ac (coc-classobj-a) omap ac (coc-classobj-a) " coc code action nmap a (coc-codeaction) xmap a (coc-codeaction-selected) nmap l (coc-codelens-action) " coc select range nmap s (coc-range-select) xmap s (coc-range-select) " coc format command! -nargs=0 Format :call CocActionAsync('format') command! -nargs=0 Import :call CocActionAsync('runCommand', 'editor.action.organizeImport') nmap f :Format " coc config nmap c :CocConfig nmap l :CocList --normal extensions nmap j :CocList outline " coc currnt tag nnoremap k :echo CocAction('getCurrentFunctionSymbol') " coc help nnoremap K :call ShowDocumentation() nnoremap gh :call ShowDocumentation() " coc mouse nmap (coc-definition) nmap (coc-definition) nmap :call ShowDocumentation() nmap :call ShowDocumentation() function! ShowDocumentation() if CocAction('hasProvider', 'hover')|call CocActionAsync('doHover') else|call feedkeys('K', 'in') endif endfunction func! g:CocMenu() if &bt == '' nmenu PopUp.Coc\ Define gd nmenu PopUp.Coc\ Refer gr endif endfunc call AddMouseMenu(function('CocMenu')) " vista and tagbar nnoremap t :Vista!! let g:tagbar_width = 22 nnoremap t :Vista!! let g:vista_default_executive = 'ctags' let g:vista#renderer#enable_icon = 0 let g:vista_sidebar_width = 22 let g:vista_echo_cursor = 0 let g:vista_stay_on_open = 0 " exit vim if vista is the only window remaining in the only tab. augroup Vista autocmd! autocmd BufEnter * if ( &ft == 'vista' || &ft == 'vista_markdown' ) && winnr('$') == 1 | call feedkeys(":vsplit|bn\") | endif augroup END " auto pair let g:AutoPairsMapCh = 0 let g:AutoPairsMapSpace = 0 " dash board let g:dashboard_disable_statusline=1 " let g:dashboard_icon_disable=1 " vim-easymotion let g:EasyMotion_smartcase = 1 map w (easymotion-bd-w) map f (easymotion-s) nmap s (easymotion-s) imap s " python-highlight let g:python_highlight_all = 1 " vim-go-highlight let g:go_highlight_functions = 1 let g:go_highlight_extra_types = 1 let g:go_highlight_space_tab_error = 1 let g:go_highlight_trailing_whitespace_error = 1 let g:go_highlight_operators = 1 let g:go_highlight_function_parameters = 1 let g:go_highlight_function_calls = 1 let g:go_highlight_types = 1 let g:go_highlight_build_constraints =1 let g:go_highlight_generate_tags =1 let g:go_highlight_string_spellcheck = 1 let g:go_highlight_fields = 1 " let g:go_highlight_variable_declarations = 1|" let g:go_highlight_variable_assignments = 1|" let g:go_highlight_array_whitespace_error = 1 " dashboard nnoremap S :SessionSave nnoremap s :SessionLoad " leaderF " find file nnoremap f :LeaderfFile " recent file nnoremap F :LeaderfMru " find buffer nnoremap b :LeaderfBuffer nnoremap b :LeaderfBuffer " function list nnoremap t :LeaderfFunction nnoremap T :LeaderfFunctionAll xnoremap t :execute ":Leaderf function --all --input " . GetSelectArea() " find for help nnoremap h :LeaderfHelp nnoremap H :Leaderf help --input key: xnoremap h :execute ":Leaderf help --input " . GetSelectArea() " enhance find nnoremap / :LeaderfLine xnoremap / :execute ":Leaderf line --input " . GetSelectArea() nnoremap ? :LeaderfLineAll xnoremap ? :execute ":Leaderf line --all --input " . GetSelectArea() " find key word nnoremap a :Leaderf rg -i nnoremap A :execute ":Leaderf rg -i --input '" . @+ . "'" xnoremap a :execute ":Leaderf rg -i --input " . GetSelectArea() " tags nnoremap j :LeaderfBufTag nnoremap J :LeaderfBufTagAll " jumps nnoremap k :Leaderf jumps " recall nnoremap l :Leaderf --recall " quickfix jump nnoremap Q :Leaderf quickfix " find color nnoremap :LeaderfColorscheme " set leaderf work dir nnoremap =l :let g:Lf_WorkingDirectoryMode = 'ac' nnoremap \l :let g:Lf_WorkingDirectoryMode = 'c' " set leaderf options let g:Lf_HideHelp = 1 let g:Lf_WindowPosition = 'popup' let g:Lf_StlSeparator = { 'left': '', 'right': ''} let g:Lf_PreviewInPopup = 1 let g:Lf_PreviewResult = {'Function': 1,'Rg': 1,'Line': 1,'BufTag': 1,'Jumps': 1} let g:Lf_CommandMap = {'':['',''],'':['',''],'':[''],'':[''],'':['','']} let g:Lf_UseCache = 0 let g:Lf_WildIgnore = { \ 'dir': ['.svn','.git','.hg','.vscode','.idea','bin','static'], \ 'file': ['*.sw?','~$*','*.bak','*.exe','*.o','*.so','*.py[co]','*.out'] \} " f1 to open help menu,f5 to fresh,tab to normal mode " c-] open in vertical,c-x open in split,c-v paste clip,c-t open in a tab,c-\ ask for open,D to delete buffer " tabular nnoremap T :Tabularize / xnoremap T :Tabularize / " vim-surround let g:surround_no_insert_mappings=1 " vim-smooth-scroll nnoremap :call smooth_scroll#up(&scroll, 0, 2) nnoremap :call smooth_scroll#down(&scroll, 0, 2) nnoremap :call smooth_scroll#up(&scroll*2, 0, 4) nnoremap :call smooth_scroll#down(&scroll*2, 0, 4) " fugitive nnoremap gb :Git blame " gv nnoremap g :GV nnoremap G :GV! nnoremap g :GV? " clever f " nnoremap \ , " map \ (clever-f-repeat-back) " let g:clever_f_chars_match_any_signs=';' let g:clever_f_smart_case=1 nmap ; (clever-f-repeat-forward) nmap { (clever-f-repeat-back) xmap ; (clever-f-repeat-forward) xmap { (clever-f-repeat-back) " asyncrun let g:asyncrun_open = 6 let g:asyncrun_bell = 0 nmap : :AsyncRun " asyncrun ack nnoremap A :AsyncRun ack -i " Copilot cab Codeium Codeium Enable " vim-ai-doubao let g:vim_ai_name="xinhuo" cab aic AIChat cab aie AIEdit cab ai AI func! g:AITranMenu() vnoremenu PopUp.Tran\ Text :AIChat /tran endfunc call AddMouseMenu(function('AITranMenu')) nnoremap i :AIChat xnoremap i :AIChat xnoremap I :AIEdit xnoremap I :AIChat /tran " vim-snippet let g:snips_author = 'chenxuan' let g:snips_email = '1607772321@qq.com'