From 76922c395db1d9745e2a47f8c0584545958a3fee Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 22 May 2024 13:57:46 +0800 Subject: Update --- vim/init/basic.vim | 279 ++++++++++++++++++++ vim/init/config.vim | 182 +++++++++++++ vim/init/keymaps.vim | 448 ++++++++++++++++++++++++++++++++ vim/init/plugins.vim | 719 +++++++++++++++++++++++++++++++++++++++++++++++++++ vim/init/style.vim | 291 +++++++++++++++++++++ vim/init/tabsize.vim | 44 ++++ 6 files changed, 1963 insertions(+) create mode 100644 vim/init/basic.vim create mode 100644 vim/init/config.vim create mode 100644 vim/init/keymaps.vim create mode 100644 vim/init/plugins.vim create mode 100644 vim/init/style.vim create mode 100644 vim/init/tabsize.vim (limited to 'vim/init') diff --git a/vim/init/basic.vim b/vim/init/basic.vim new file mode 100644 index 0000000..4c6cd45 --- /dev/null +++ b/vim/init/basic.vim @@ -0,0 +1,279 @@ +"====================================================================== +" +" init-basic.vim - Need vim tiny compatible +" +" Used for general usecases. No keymap and personal preference +" +" Use '*' to search for: +" VIM_BEHAVIOR +" VISUAL +" EDIT +" JUMP +" SEARCH +" SYNTAX_HIGHLIGHT +" BUFFERS +" ENCODING_PREFERENCE +" FOLDING +" MISC +"====================================================================== + + +"---------------------------------------------------------------------- +" VIM_BEHAVIOR +"---------------------------------------------------------------------- + +let mapleader = "," " Always use comma as leader key +set nocompatible " Disable vi compatible, today is 20XX +set autochdir " Automatically cd to current file +set path=.,** " Allow :find with completion +set mouse= " Disable mouse selection +set winaltkeys=no " Allow alt key for mapping +set cursorline + +" Turn persistent undo on +" means that you can undo even when you close a buffer/VIM +set undofile +set undodir=~/.vim/.undodir +set conceallevel=1 + +" Apply plugin and indent by filetype +filetype plugin indent on + + +"---------------------------------------------------------------------- +" VISUAL +"---------------------------------------------------------------------- + +colorscheme desert " I like desert! +" In most of the cases, it is overrides by lightline.vim +set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c +set showmatch " Show pairing brackets + +set number relativenumber " Use relativenumber +set wrap " Disable wrap by default +set scrolloff=3 " Leave some buffer when scrolling down +set ruler " Show cursor position +set laststatus=2 " Always show the status line +set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20 + + +"---------------------------------------------------------------------- +" EDIT +"---------------------------------------------------------------------- + +set backspace=eol,start,indent " Set Backspace behaviors +set autoindent " If current line has indent, automatically set indent for next line +set cindent +set ttimeout +set ttimeoutlen=50 +set updatetime=250 + +imap l +" Change IM to US when exit to Normal mode +autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true + + +"---------------------------------------------------------------------- +" JUMP +"---------------------------------------------------------------------- + +set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file) +set suffixesadd=.md " Enable reference markdown file without extension + + +"---------------------------------------------------------------------- +" SEARCH +"---------------------------------------------------------------------- +set ignorecase " Search case without case sensation +set smartcase +set hlsearch " Hilight all matched texts +set incsearch " Show matched strings when typing + + +"---------------------------------------------------------------------- +" SYNTAX_HIGHLIGHT +"---------------------------------------------------------------------- + +syntax enable + +function! GetHighlightGroupName() + let l:syntaxID = synID(line('.'), col('.'), 1) + let l:groupName = synIDattr(l:syntaxID, 'name') + echo "Highlight Group Name: " . l:groupName +endfunction + +" Defualt highlight for matched parenthesis is so weird in many colorscheme +" Why the background color is lighter than my caret !? +highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE +highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE + +" Show trailing spaces +highlight ExtraWhitespace ctermbg=red guibg=red +match ExtraWhitespace /\s\+$/ + +" Persist visualized lines +" define line highlight color +highlight MultiLineHighlight ctermbg=LightYellow guibg=LightYellow ctermfg=Black guifg=Black +" highlight the current line +nnoremap h :call matchadd('MultiLineHighlight', '\%'.line('.').'l') +" clear all the highlighted lines +nnoremap H :call clearmatches() + + +"---------------------------------------------------------------------- +" BUFFERS +"---------------------------------------------------------------------- + +" Set to auto read when a file is changed from the outside +" Unnamed buffer like CmdWindows should prevent this +set autoread +autocmd FocusGained,BufEnter .* checktime + +let g:quitVimWhenPressingCtrlC = 1 +function! ToggleQuit() + let g:quitVimWhenPressingCtrlC = g:quitVimWhenPressingCtrlC ? 0 : 1 + let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock" + echo message +endfunction + +nnoremap gl :call ToggleQuit() + +" Simply exit when closing the last buffer +function! Bye() + " Delete current buffer if working on special filetype + let specialFileTypes = ['help', 'netrw', 'vim-plug', 'nerdtree'] + if index(specialFileTypes, &filetype) != -1 + :bdelete + " Delete current buffer if more than one buffers + elseif len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) != 1 + :bdelete + elseif g:quitVimWhenPressingCtrlC + " Otherwise, quit vim + :silent! qall + else + :echo "Press gl to allow quit with " + endif +endfunction + +" Ctrl-C rules!!! +nnoremap :call Bye() + +" Don't unload a buffer when no longer shown in a window +" This allows you open a new buffer and leaves current buffer modified +set hidden + + +" Put these in an autocmd group, so that you can revert them with: +" ":augroup vimStartup | au! | augroup END" +augroup vimStartup +au! + +" When editing a file, always jump to the last known cursor position. +" Don't do it when the position is invalid, when inside an event handler +" (happens when dropping a file on gvim) and for a commit message +" (it's likely a different one than last time). +autocmd BufReadPost * + \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' + \ | exe "normal! g`\"" + \ | endif +augroup END + +" Set filetype for beancount +autocmd BufRead,BufNewFile *.bean call PrepareBean() +function PrepareBean() + set filetype=beancount + silent !setsid fava ~/bean/main.bean &>/dev/null + autocmd VimLeave * silent !killall fava +endfunction + +" Set filetype for index.html +autocmd BufWrite *.html,*.js,*.css call ReloadServer() +function ReloadServer() + silent !browser-sync reload &>/dev/null +endfunction + +" Hide the first line of a file if editing password file +" TODO a better way to determine a file is related to password-store, now use +" files under /dev/shm as filter +autocmd BufRead /dev/shm/*.txt call SetPasswordFile() +function SetPasswordFile() + setlocal foldminlines=0 + setlocal foldmethod=manual + setlocal foldtext= + norm! ggzfl +endfunction + + + +"---------------------------------------------------------------------- +" ENCODING_PREFERENCE +"---------------------------------------------------------------------- +if has('multi_byte') + set encoding=utf-8 + set fileencoding=utf-8 + " Try encodings by this order + set fileencodings=utf-8,big5,ucs-bom,gbk,gb18030,euc-jp,latin1 +endif + + +"---------------------------------------------------------------------- +" FOLDING +"---------------------------------------------------------------------- +set foldenable " Allow fold +set foldmethod=indent " Fold contents by indent +set foldlevel=99 " Expand all by default + + +"---------------------------------------------------------------------- +" MISC +"---------------------------------------------------------------------- + +" 顯示括號匹配的時間 +set matchtime=2 + +" 顯示最後一行 +set display=lastline + +" 允許下方顯示目錄 +set wildmenu + +" Improve performance +set lazyredraw + +" Format of error message +set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m + +" 顯示分隔符號 +set listchars=tab:\|\ ,trail:.,extends:>,precedes:< + +" 遇到Unicode值大於255的文本,不必等到空格再折行 +set formatoptions+=m + +" 合併兩行中文時,不在中間加空格 +set formatoptions+=B + +" Use Unix way to add newline +set ffs=unix,dos,mac + + +"---------------------------------------------------------------------- +" Ignore these suffixes when find/complete +"---------------------------------------------------------------------- +set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.pyc,.pyo,.egg-info,.class + +set wildignore=*.o,*.obj,*~,*.exe,*.a,*.pdb,*.lib "stuff to ignore when tab completing +set wildignore+=*.so,*.dll,*.swp,*.egg,*.jar,*.class,*.pyc,*.pyo,*.bin,*.dex +set wildignore+=*.zip,*.7z,*.rar,*.gz,*.tar,*.gzip,*.bz2,*.tgz,*.xz " MacOSX/Linux +set wildignore+=*DS_Store*,*.ipch +set wildignore+=*.gem +set wildignore+=*.png,*.jpg,*.gif,*.bmp,*.tga,*.pcx,*.ppm,*.img,*.iso +set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/.rbenv/** +set wildignore+=*/.nx/**,*.app,*.git,.git +set wildignore+=*.wav,*.mp3,*.ogg,*.pcm +set wildignore+=*.mht,*.suo,*.sdf,*.jnlp +set wildignore+=*.chm,*.epub,*.pdf,*.mobi,*.ttf +set wildignore+=*.mp4,*.avi,*.flv,*.mov,*.mkv,*.swf,*.swc +set wildignore+=*.ppt,*.pptx,*.docx,*.xlt,*.xls,*.xlsx,*.odt,*.wps +set wildignore+=*.msi,*.crx,*.deb,*.vfd,*.apk,*.ipa,*.bin,*.msu +set wildignore+=*.gba,*.sfc,*.078,*.nds,*.smd,*.smc +set wildignore+=*.linux2,*.win32,*.darwin,*.freebsd,*.linux,*.android diff --git a/vim/init/config.vim b/vim/init/config.vim new file mode 100644 index 0000000..7e08ebf --- /dev/null +++ b/vim/init/config.vim @@ -0,0 +1,182 @@ +"====================================================================== +" +" init-config.vim - 正常模式下的配置,在 init-basic.vim 后调用 +" +" Created by skywind on 2018/05/30 +" Last Modified: 2018/05/30 19:20:46 +" +"====================================================================== +" vim: set ts=4 sw=4 tw=78 noet : + +" Open help page in a new tab +autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif + + +"---------------------------------------------------------------------- +" 有 tmux 何没有的功能键超时(毫秒) +"---------------------------------------------------------------------- +if $TMUX != '' + set ttimeoutlen=30 +elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0 + set ttimeoutlen=80 +endif + + +"---------------------------------------------------------------------- +" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 +" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面) +"---------------------------------------------------------------------- +if has('nvim') == 0 && has('gui_running') == 0 + function! s:metacode(key) + exec "set =\e".a:key + endfunc + for i in range(10) + call s:metacode(nr2char(char2nr('0') + i)) + endfor + for i in range(26) + call s:metacode(nr2char(char2nr('a') + i)) + call s:metacode(nr2char(char2nr('A') + i)) + endfor + for c in [',', '.', '/', ';', '{', '}'] + call s:metacode(c) + endfor + for c in ['?', ':', '-', '_', '+', '=', "'"] + call s:metacode(c) + endfor +endif + + +"---------------------------------------------------------------------- +" 终端下功能键设置 +"---------------------------------------------------------------------- +function! s:key_escape(name, code) + if has('nvim') == 0 && has('gui_running') == 0 + exec "set ".a:name."=\e".a:code + endif +endfunc + + +"---------------------------------------------------------------------- +" 功能键终端码矫正 +"---------------------------------------------------------------------- +call s:key_escape('', 'OP') +call s:key_escape('', 'OQ') +call s:key_escape('', 'OR') +call s:key_escape('', 'OS') +call s:key_escape('', '[1;2P') +call s:key_escape('', '[1;2Q') +call s:key_escape('', '[1;2R') +call s:key_escape('', '[1;2S') +call s:key_escape('', '[15;2~') +call s:key_escape('', '[17;2~') +call s:key_escape('', '[18;2~') +call s:key_escape('', '[19;2~') +call s:key_escape('', '[20;2~') +call s:key_escape('', '[21;2~') +call s:key_escape('', '[23;2~') +call s:key_escape('', '[24;2~') + + +"---------------------------------------------------------------------- +" 防止tmux下vim的背景色显示异常 +" Refer: http://sunaku.github.io/vim-256color-bce.html +"---------------------------------------------------------------------- +if &term =~ '256color' && $TMUX != '' + " disable Background Color Erase (BCE) so that color schemes + " render properly when inside 256-color tmux and GNU screen. + " see also http://snk.tuxfamily.org/log/vim-256color-bce.html + set t_ut= +endif + + +"---------------------------------------------------------------------- +" 备份设置 +"---------------------------------------------------------------------- + +" 允许备份 +set backup + +" 保存时备份 +set writebackup + +" 备份文件地址,统一管理 +set backupdir=~/.vim/tmp + +" 备份文件扩展名 +set backupext=.bak + +" 禁用交换文件 +set noswapfile + +" 创建目录,并且忽略可能出现的警告 +silent! call mkdir(expand('~/.vim/tmp'), "p", 0755) + + +"---------------------------------------------------------------------- +" 配置微调 +"---------------------------------------------------------------------- + +" 修正 ScureCRT/XShell 以及某些终端乱码问题,主要原因是不支持一些 +" 终端控制命令,比如 cursor shaping 这类更改光标形状的 xterm 终端命令 +" 会令一些支持 xterm 不完全的终端解析错误,显示为错误的字符,比如 q 字符 +" 如果你确认你的终端支持,不会在一些不兼容的终端上运行该配置,可以注释 +if has('nvim') + set guicursor= +elseif (!has('gui_running')) && has('terminal') && has('patch-8.0.1200') + let g:termcap_guicursor = &guicursor + let g:termcap_t_RS = &t_RS + let g:termcap_t_SH = &t_SH + set guicursor= + set t_RS= + set t_SH= +endif + +" 打开文件时恢复上一次光标所在位置 +autocmd BufReadPost * + \ if line("'\"") > 1 && line("'\"") <= line("$") | + \ exe "normal! g`\"" | + \ endif + +" 定义一个 DiffOrig 命令用于查看文件改动 +if !exists(":DiffOrig") + command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis + \ | wincmd p | diffthis +endif + + + +"---------------------------------------------------------------------- +" 文件类型微调 +"---------------------------------------------------------------------- +augroup InitFileTypesGroup + + " 清除同组的历史 autocommand + au! + + " C/C++ 文件使用 // 作为注释 + au FileType c,cpp setlocal commentstring=//\ %s + + " markdown 允许自动换行 + au FileType markdown setlocal wrap + + " lisp 进行微调 + au FileType lisp setlocal ts=8 sts=2 sw=2 et + + " scala 微调 + au FileType scala setlocal sts=4 sw=4 noet + + " haskell 进行微调 + au FileType haskell setlocal et + + " quickfix 隐藏行号 + au FileType qf setlocal nonumber + + " 强制对某些扩展名的 filetype 进行纠正 + au BufNewFile,BufRead *.as setlocal filetype=actionscript + au BufNewFile,BufRead *.pro setlocal filetype=prolog + au BufNewFile,BufRead *.es setlocal filetype=erlang + au BufNewFile,BufRead *.asc setlocal filetype=asciidoc + au BufNewFile,BufRead *.vl setlocal filetype=verilog + au BufRead /tmp/mutt-* set tw=72 + +augroup END diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim new file mode 100644 index 0000000..5e472d2 --- /dev/null +++ b/vim/init/keymaps.vim @@ -0,0 +1,448 @@ +"====================================================================== +" +" Only for key mapping +" +" - COMMON_MAPPING +" - LINKS +" - MOVING_WITH_READLINE +" - JUMP_TO_TABS_WITH_ALT +" - MANAGE_TABS +" - MANAGE_BUFFERS +" - SURROURD_WITH_CHAR +" - REDIRECTION_WITH_BUFFER +" - 终端支持 +" - 编译运行 +" - 符号搜索 +" +"====================================================================== +" vim: set ts=4 sw=4 tw=78 noet : + +"---------------------------------------------------------------------- +" COMMON_MAPPING +"---------------------------------------------------------------------- + +" Space for searching +map / + +" j/k will move virtual lines (lines that wrap) +noremap j (v:count == 0 ? 'gj' : 'j') +noremap k (v:count == 0 ? 'gk' : 'k') + +" Search for selected test +vnoremap * y/\V=escape(@",'/\') + +" Disable highlight when is pressed +map :nohlsearch + +" Quick move in a line +noremap 30h +noremap 30l + +" Paste register 0 +nnoremap "0p + +" Fast saving +nmap w :w! + +" Fast quit with error +nmap cq :cc + +" Switch wrap +nmap W :set wrap! + +" :W sudo saves the file +" (useful for handling the permission-denied error) +command! W execute 'w !sudo -S tee %' edit! + +" New tab like browser +nmap n :tabnew +nmap c :tabclose +nmap m :tabmove +nmap o :tabonly + +" Enter to open file +nnoremap gf +nnoremap gF :e +augroup vimrc_CRfix + au! + " Quickfix, Location list, &c. remap to work as expected + autocmd BufReadPost quickfix nnoremap + autocmd CmdwinEnter * nnoremap + autocmd CmdwinEnter * nnoremap +augroup END + +" Open terminal +nnoremap , :.terminal ++noclose +vnoremap , :terminal + +" Toggle paste mode on and off +map pp :setlocal paste! + +" Switch CWD to the directory of the open buffer +map cd :cd %:p:h:pwd + +" Move one line up and down +nnoremap ddp +nnoremap ddkP + +" In case ALT key is not working +" execute "set =\e1" +" execute "set =\e2" +" execute "set =\e3" +" execute "set =\e4" +" execute "set =\e5" +" execute "set =\e6" +" execute "set =\e7" +" execute "set =\e8" +" execute "set =\e9" +" execute "set =\e0" +" execute "set =\ef" +" execute "set =\eb" +" execute "set =\ed" +" execute "set =\el" +" execute "set =\eh" + +" Copy from system clipboard +nnoremap P :r !xsel -ob +vnoremap Y :w !xsel -ib + +" Spell +nnoremap ts :set spell! +nnoremap ss ]s +nnoremap S [s + +" Show full path by default +nnoremap 1 + +" Translate by Google API +vnoremap Tz :!trans -t zh-TW -b +vnoremap Te :!trans -t en-US -b + +" source .vimrc +nnoremap so V:so +nnoremap so :source ~/.vimrc +vnoremap so :source + + +"---------------------------------------------------------------------- +" => Fast editing and reloading of vimrc configs +"---------------------------------------------------------------------- +nnoremap e :edit $MYVIMRC +autocmd! bufwritepost $MYVIMRC source $MYVIMRC + + +"---------------------------------------------------------------------- +" MOVING_WITH_READLINE +"---------------------------------------------------------------------- +inoremap +inoremap +inoremap 0 +inoremap $ +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap + +set cedit= +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap d$ +cnoremap de + +" Moving with wrap +noremap gj +noremap gk +inoremap gj +inoremap gk + + +"---------------------------------------------------------------------- +" JUMP_TO_TABS_WITH_ALT +"---------------------------------------------------------------------- +noremap :tabn 1 +noremap :tabn 2 +noremap :tabn 3 +noremap :tabn 4 +noremap :tabn 5 +noremap :tabn 6 +noremap :tabn 7 +noremap :tabn 8 +noremap :tablast +inoremap :tabn 1 +inoremap :tabn 2 +inoremap :tabn 3 +inoremap :tabn 4 +inoremap :tabn 5 +inoremap :tabn 6 +inoremap :tabn 7 +inoremap :tabn 8 +inoremap :tablast + + +"---------------------------------------------------------------------- +" MANAGE_TABS +"---------------------------------------------------------------------- + +" Useful mappings for managing tabs +map tn :tabnew +map to :tabonly +map tc :tabclose +map tm :tabmove +noremap :call Tab_MoveLeft() +noremap :call Tab_MoveRight() + +" Let tl toggle between this and the last accessed tab +let g:lasttab = 1 +nmap tl :exe "tabn ".g:lasttab +autocmd TabLeave * let g:lasttab = tabpagenr() + +" Opens a new tab with the current buffer's path +" Super useful when editing files in the same directory +map te :tabedit =expand("%:p:h")/ + +" Tab move functions +function! Tab_MoveLeft() + let l:tabnr = tabpagenr() - 2 + if l:tabnr >= 0 + exec 'tabmove '.l:tabnr + endif +endfunc +function! Tab_MoveRight() + let l:tabnr = tabpagenr() + 1 + if l:tabnr <= tabpagenr('$') + exec 'tabmove '.l:tabnr + endif +endfunc + + +"---------------------------------------------------------------------- +" MANAGE_BUFFERS +"---------------------------------------------------------------------- + +" Open a new buffer +nmap O :e /tmp/buffer + +" Next buffer +noremap l :bn + +" Let l toggle between this and the last accessed buffer +let g:lastbuffer = 1 +noremap :exe "buffer ".g:lastbuffer +au BufLeave * let g:lastbuffer = bufnr() + +"---------------------------------------------------------------------- +" SURROURD_WITH_CHAR +"---------------------------------------------------------------------- +vnoremap S sa +vnoremap ' ``>la' +vnoremap q ``>la" +vnoremap ( ``>la) +vnoremap [ ``>la] +vnoremap { ``>la} +vnoremap ` ``>la` +vnoremap ``>la +vnoremap z ``>la」 + + +"---------------------------------------------------------------------- +" REDIRECTION_WITH_BUFFER +"---------------------------------------------------------------------- +" Usage: +" :Redir hi ............. show the full output of command ':hi' in a scratch window +" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window +" +function! Redir(cmd) + for win in range(1, winnr('$')) + if getwinvar(win, 'scratch') + execute win . 'windo close' + endif + endfor + if a:cmd =~ '^!' + let output = system(matchstr(a:cmd, '^!\zs.*')) + else + redir => output + execute a:cmd + redir END + endif + vnew + let w:scratch = 1 + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile + call setline(1, split(output, "\n")) +endfunction + +command! -nargs=1 -complete=command Redir silent call Redir() +nnoremap rr :Redir + +"---------------------------------------------------------------------- +" Markdown items (temproray solution) +"---------------------------------------------------------------------- + +" Toggle list item in markdown: "- [ ] XXX" -> "XXX" -> "- XXX" -> "- [ ] XXX" +autocmd FileType markdown nnoremap i V:!sed -E '/^ *- \[.\]/ { s/^( *)- \[.\] */\1/; q; }; /^ *[^[:space:]-]/ { s/^( *)/\1- /; q; }; /^ *- / { s/^( *)- /\1- [ ] /; q; }' +autocmd FileType markdown nnoremap I V:!sed -E 's/^( *)/\1- [ ] /' + +" Toggle task status: "- [ ] " -> "- [x]" -> "- [.] " -> "- [ ] " +nnoremap x V:!sed -E '/^ *- \[ \]/ { s/^( *)- \[ \]/\1- [x]/; q; }; /^ *- \[\x\]/ { s/^( *)- \[\x\]/\1- [.]/; q; }; /^ *- \[\.\]/ { s/^( *)- \[\.\]/\1- [ ]/; q; }' + + +"---------------------------------------------------------------------- +" Common command +"---------------------------------------------------------------------- +" Show date selector +nnoremap dd :r !sh -c 'LANG=en zenity --calendar --date-format="\%Y.\%m.\%d" 2>/dev/null' +nnoremap dD :r !sh -c 'LANG=en zenity --calendar --date-format="\%a \%b \%d" 2>/dev/null' +nnoremap dt :r !date +\%H:\%mA + + +"---------------------------------------------------------------------- +" 窗口切换:ALT+SHIFT+hjkl +" 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在 +" bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的 +"---------------------------------------------------------------------- +noremap h +noremap l +noremap j +noremap k +inoremap h +inoremap l +inoremap j +inoremap k + +if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1') + " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 + " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? + " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 + set termwinkey= + tnoremap h + tnoremap l + tnoremap j + tnoremap k + tnoremap +elseif has('nvim') + " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 + tnoremap h + tnoremap l + tnoremap j + tnoremap k + tnoremap +endif + + + +"---------------------------------------------------------------------- +" 编译运行 C/C++ 项目 +" 详细见:http://www.skywind.me/blog/archives/2084 +"---------------------------------------------------------------------- + +" 自动打开 quickfix window ,高度为 6 +let g:asyncrun_open = 6 + +" 任务结束时候响铃提醒 +let g:asyncrun_bell = 1 + +" 设置 F10 打开/关闭 Quickfix 窗口 +nnoremap :call asyncrun#quickfix_toggle(6) + +" F9 编译 C/C++ 文件 +nnoremap :AsyncRun gcc -Wall -O2 "$(VIM_FILEPATH)" -o "$(VIM_FILEDIR)/$(VIM_FILENOEXT)" + +" F5 运行文件 +nnoremap :call ExecuteFile() + +" F7 编译项目 +nnoremap :AsyncRun -cwd= make + +" F8 运行项目 +nnoremap :AsyncRun -cwd= -raw make run + +" F6 测试项目 +nnoremap :AsyncRun -cwd= -raw make test + +" 更新 cmake +nnoremap :AsyncRun -cwd= cmake . + +" Windows 下支持直接打开新 cmd 窗口运行 +if has('win32') || has('win64') + nnoremap :AsyncRun -cwd= -mode=4 make run +endif + + +"---------------------------------------------------------------------- +" F5 运行当前文件:根据文件类型判断方法,并且输出到 quickfix 窗口 +"---------------------------------------------------------------------- +function! ExecuteFile() + let cmd = '' + if index(['c', 'cpp', 'rs', 'go'], &ft) >= 0 + " native 语言,把当前文件名去掉扩展名后作为可执行运行 + " 写全路径名是因为后面 -cwd=? 会改变运行时的当前路径,所以写全路径 + " 加双引号是为了避免路径中包含空格 + let cmd = '"$(VIM_FILEDIR)/$(VIM_FILENOEXT)"' + elseif &ft == 'python' + let $PYTHONUNBUFFERED=1 " 关闭 python 缓存,实时看到输出 + let cmd = 'python "$(VIM_FILEPATH)"' + elseif &ft == 'javascript' + let cmd = 'node "$(VIM_FILEPATH)"' + elseif &ft == 'perl' + let cmd = 'perl "$(VIM_FILEPATH)"' + elseif &ft == 'ruby' + let cmd = 'ruby "$(VIM_FILEPATH)"' + elseif &ft == 'php' + let cmd = 'php "$(VIM_FILEPATH)"' + elseif &ft == 'lua' + let cmd = 'lua "$(VIM_FILEPATH)"' + elseif &ft == 'zsh' + let cmd = 'zsh "$(VIM_FILEPATH)"' + elseif &ft == 'ps1' + let cmd = 'powershell -file "$(VIM_FILEPATH)"' + elseif &ft == 'vbs' + let cmd = 'cscript -nologo "$(VIM_FILEPATH)"' + elseif &ft == 'sh' + let cmd = 'bash "$(VIM_FILEPATH)"' + else + return + endif + " Windows 下打开新的窗口 (-mode=4) 运行程序,其他系统在 quickfix 运行 + " -raw: 输出内容直接显示到 quickfix window 不匹配 errorformat + " -save=2: 保存所有改动过的文件 + " -cwd=$(VIM_FILEDIR): 运行初始化目录为文件所在目录 + if has('win32') || has('win64') + exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=4 '. cmd + else + exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=0 '. cmd + endif +endfunc + + + +"---------------------------------------------------------------------- +" F2 在项目目录下 Grep 光标下单词,默认 C/C++/Py/Js ,扩展名自己扩充 +" 支持 rg/grep/findstr ,其他类型可以自己扩充 +" 不是在当前目录 grep,而是会去到当前文件所属的项目目录 project root +" 下面进行 grep,这样能方便的对相关项目进行搜索 +"---------------------------------------------------------------------- +if executable('rg') + noremap :AsyncRun! -cwd= rg -n --no-heading + \ --color never -g *.h -g *.c* -g *.py -g *.js -g *.vim + \ "" +elseif has('win32') || has('win64') + noremap :AsyncRun! -cwd= findstr /n /s /C:"" + \ "\%CD\%\*.h" "\%CD\%\*.c*" "\%CD\%\*.py" "\%CD\%\*.js" + \ "\%CD\%\*.vim" + \ +else + noremap :AsyncRun! -cwd= grep -n -s -R + \ --include='*.h' --include='*.c*' --include='*.py' + \ --include='*.js' --include='*.vim' + \ '' +endif diff --git a/vim/init/plugins.vim b/vim/init/plugins.vim new file mode 100644 index 0000000..5b05c8e --- /dev/null +++ b/vim/init/plugins.vim @@ -0,0 +1,719 @@ +"====================================================================== +" +" init-plugins.vim +" +" Created by skywind on 2018/05/31 +" Last Modified: 2018/06/10 23:11 +" +"====================================================================== +" vim: set ts=4 sw=4 tw=78 noet : + +call plug#begin('~/.vim/plugged') + +"""""""""""""""""""""""""""""" +" => Set statusline +"""""""""""""""""""""""""""""" +Plug 'itchyny/lightline.vim' +let g:lightline = { 'colorscheme': 'wombat' } + +"""""""""""""""""""""""""""""" +" => MRU plugin +"""""""""""""""""""""""""""""" +Plug 'yegappan/mru' +let MRU_Max_Entries = 400 +nnoremap f :MRU + +"""""""""""""""""""""""""""""" +" => Goyo for focus +"""""""""""""""""""""""""""""" +Plug 'junegunn/goyo.vim' +nnoremap z :Goyo + +let g:goyo_width = 80 +let g:goyo_height = "85%" +let g:goyo_linenr = 0 + + +function! s:goyo_enter() + let b:quitting = 0 + let b:quitting_bang = 0 + autocmd QuitPre let b:quitting = 1 + cabbrev q! let b:quitting_bang = 1 q! +endfunction + +function! s:goyo_leave() + " Quit Vim if this is the only remaining buffer + if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 + if b:quitting_bang + qa! + else + qa + endif + endif +endfunction + +autocmd! User GoyoEnter call goyo_enter() +autocmd! User GoyoLeave call goyo_leave() + + +"""""""""""""""""""""""""""""" +" => bufExplorer plugin +"""""""""""""""""""""""""""""" +Plug 'jlanzarotta/bufexplorer' +let g:bufExplorerDefaultHelp=0 +let g:bufExplorerShowRelativePath=1 +let g:bufExplorerFindActive=1 +let g:bufExplorerSortBy='name' +map q ::BufExplorer +map Q ::BufExplorerVerticalSplit + + +"""""""""""""""""""""""""""""" +" => Auto set tabline (tal) +"""""""""""""""""""""""""""""" +Plug 'webdevel/tabulous' + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Nerd Tree +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +Plug 'preservim/nerdtree' +let g:NERDTreeWinPos = "left" +let NERDTreeShowHidden=0 +let NERDTreeQuitOnOpen=1 +let NERDTreeIgnore = ['\.pyc$', '__pycache__'] +let g:NERDTreeWinSize=35 +map :NERDTreeToggle +map nb :NERDTreeFromBookmark +map nf :NERDTreeFind + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => vim-surrounded +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +Plug 'tpope/vim-surround' +vmap [ S[ + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Markdown +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +Plug 'godlygeek/tabular' +Plug 'preservim/vim-markdown' + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => ALE (Asynchronous Lint Engine) +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +Plug 'dense-analysis/ale' +let g:ale_sign_column_always = 1 +let g:ale_sign_error = '>>' +let g:ale_sign_warning = '--' + +" show errors or warnings in my statusline +let g:airline#extensions#ale#enabled = 1 + +" use quickfix list instead of the loclist +let g:ale_set_loclist = 0 +let g:ale_set_quickfix = 1 + + +""---------------------------------------------------------------------- +"" 默认情况下的分组,可以再前面覆盖之 +""---------------------------------------------------------------------- +"if !exists('g:bundle_group') +" let g:bundle_group = ['basic', 'tags', 'enhanced', 'filetypes', 'textobj'] +" let g:bundle_group += ['tags', 'airline', 'nerdtree', 'ale', 'echodoc'] +" let g:bundle_group += ['leaderf'] +"endif +" +" +""---------------------------------------------------------------------- +"" 计算当前 vim-init 的子路径 +""---------------------------------------------------------------------- +"let s:home = fnamemodify(resolve(expand(':p')), ':h:h') +" +"function! s:path(path) +" let path = expand(s:home . '/' . a:path ) +" return substitute(path, '\\', '/', 'g') +"endfunc +" +" +""---------------------------------------------------------------------- +"" 在 ~/.vim/bundles 下安装插件 +""---------------------------------------------------------------------- +"call plug#begin(get(g:, 'bundle_home', '~/.vim/bundles')) +" +" +""---------------------------------------------------------------------- +"" 默认插件 +""---------------------------------------------------------------------- +" +"" 全文快速移动,f{char} 即可触发 +"Plug 'easymotion/vim-easymotion' +" +"" 文件浏览器,代替 netrw +"Plug 'justinmk/vim-dirvish' +" +"" 表格对齐,使用命令 Tabularize +"Plug 'godlygeek/tabular', { 'on': 'Tabularize' } +" +"" Diff 增强,支持 histogram / patience 等更科学的 diff 算法 +"Plug 'chrisbra/vim-diff-enhanced' +" +" +""---------------------------------------------------------------------- +"" Dirvish 设置:自动排序并隐藏文件,同时定位到相关文件 +"" 这个排序函数可以将目录排在前面,文件排在后面,并且按照字母顺序排序 +"" 比默认的纯按照字母排序更友好点。 +""---------------------------------------------------------------------- +"function! s:setup_dirvish() +" if &buftype != 'nofile' && &filetype != 'dirvish' +" return +" endif +" if has('nvim') +" return +" endif +" " 取得光标所在行的文本(当前选中的文件名) +" let text = getline('.') +" if ! get(g:, 'dirvish_hide_visible', 0) +" exec 'silent keeppatterns g@\v[\/]\.[^\/]+[\/]?$@d _' +" endif +" " 排序文件名 +" exec 'sort ,^.*[\/],' +" let name = '^' . escape(text, '.*[]~\') . '[/*|@=|\\*]\=\%($\|\s\+\)' +" " 定位到之前光标处的文件 +" call search(name, 'wc') +" noremap ~ :Dirvish ~ +" noremap % :e % +"endfunc +" +"augroup MyPluginSetup +" autocmd! +" autocmd FileType dirvish call s:setup_dirvish() +"augroup END +" +" +""---------------------------------------------------------------------- +"" 基础插件 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'basic') >= 0 +" +" " 展示开始画面,显示最近编辑过的文件 +" Plug 'mhinz/vim-startify' +" +" " 一次性安装一大堆 colorscheme +" Plug 'flazz/vim-colorschemes' +" +" " 支持库,给其他插件用的函数库 +" Plug 'xolox/vim-misc' +" +" " 用于在侧边符号栏显示 marks (ma-mz 记录的位置) +" Plug 'kshenoy/vim-signature' +" +" " 用于在侧边符号栏显示 git/svn 的 diff +" Plug 'mhinz/vim-signify' +" +" " 根据 quickfix 中匹配到的错误信息,高亮对应文件的错误行 +" " 使用 :RemoveErrorMarkers 命令或者 ha 清除错误 +" Plug 'mh21/errormarker.vim' +" +" " 使用 ALT+e 会在不同窗口/标签上显示 A/B/C 等编号,然后字母直接跳转 +" Plug 't9md/vim-choosewin' +" +" " 提供基于 TAGS 的定义预览,函数参数预览,quickfix 预览 +" Plug 'skywind3000/vim-preview' +" +" " Git 支持 +" Plug 'tpope/vim-fugitive' +" +" " 使用 ALT+E 来选择窗口 +" nmap (choosewin) +" +" " 默认不显示 startify +" let g:startify_disable_at_vimenter = 1 +" let g:startify_session_dir = '~/.vim/session' +" +" " 使用 ha 清除 errormarker 标注的错误 +" noremap ha :RemoveErrorMarkers +" +" " signify 调优 +" let g:signify_vcs_list = ['git', 'svn'] +" let g:signify_sign_add = '+' +" let g:signify_sign_delete = '_' +" let g:signify_sign_delete_first_line = '‾' +" let g:signify_sign_change = '~' +" let g:signify_sign_changedelete = g:signify_sign_change +" +" " git 仓库使用 histogram 算法进行 diff +" let g:signify_vcs_cmds = { +" \ 'git': 'git diff --no-color --diff-algorithm=histogram --no-ext-diff -U0 -- %f', +" \} +"endif +" +" +""---------------------------------------------------------------------- +"" 增强插件 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'enhanced') >= 0 +" +" " 用 v 选中一个区域后,ALT_+/- 按分隔符扩大/缩小选区 +" Plug 'terryma/vim-expand-region' +" +" " 快速文件搜索 +" Plug 'junegunn/fzf' +" +" " 给不同语言提供字典补全,插入模式下 c-x c-k 触发 +" Plug 'asins/vim-dict' +" +" " 使用 :FlyGrep 命令进行实时 grep +" Plug 'wsdjeg/FlyGrep.vim' +" +" " 使用 :CtrlSF 命令进行模仿 sublime 的 grep +" Plug 'dyng/ctrlsf.vim' +" +" " 配对括号和引号自动补全 +" Plug 'Raimondi/delimitMate' +" +" " 提供 gist 接口 +" Plug 'lambdalisue/vim-gista', { 'on': 'Gista' } +" +" " ALT_+/- 用于按分隔符扩大缩小 v 选区 +" map (expand_region_expand) +" map (expand_region_shrink) +"endif +" +" +""---------------------------------------------------------------------- +"" 自动生成 ctags/gtags,并提供自动索引功能 +"" 不在 git/svn 内的项目,需要在项目根目录 touch 一个空的 .root 文件 +"" See https://zhuanlan.zhihu.com/p/36279445 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'tags') >= 0 +" +" " 提供 ctags/gtags 后台数据库自动更新功能 +" Plug 'ludovicchabant/vim-gutentags' +" +" " 提供 GscopeFind 命令并自动处理好 gtags 数据库切换 +" " 支持光标移动到符号名上:cg 查看定义,cs 查看引用 +" Plug 'skywind3000/gutentags_plus' +" +" " 设定项目目录标志:除了 .git/.svn 外,还有 .root 文件 +" let g:gutentags_project_root = ['.root'] +" let g:gutentags_ctags_tagfile = '.tags' +" +" " 默认生成的数据文件集中到 ~/.cache/tags 避免污染项目目录,好清理 +" let g:gutentags_cache_dir = expand('~/.cache/tags') +" +" " 默认禁用自动生成 +" let g:gutentags_modules = [] +" +" " 如果有 ctags 可执行就允许动态生成 ctags 文件 +" if executable('ctags') +" let g:gutentags_modules += ['ctags'] +" endif +" +" " 如果有 gtags 可执行就允许动态生成 gtags 数据库 +" if executable('gtags') && executable('gtags-cscope') +" let g:gutentags_modules += ['gtags_cscope'] +" endif +" +" " 设置 ctags 的参数 +" let g:gutentags_ctags_extra_args = [] +" 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'] +" +" " 使用 universal-ctags 的话需要下面这行,请反注释 +" " let g:gutentags_ctags_extra_args += ['--output-format=e-ctags'] +" +" " 禁止 gutentags 自动链接 gtags 数据库 +" let g:gutentags_auto_add_gtags_cscope = 0 +"endif +" +" +""---------------------------------------------------------------------- +"" 文本对象:textobj 全家桶 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'textobj') >= 0 +" +" " 基础插件:提供让用户方便的自定义文本对象的接口 +" Plug 'kana/vim-textobj-user' +" +" " indent 文本对象:ii/ai 表示当前缩进,vii 选中当缩进,cii 改写缩进 +" Plug 'kana/vim-textobj-indent' +" +" " 语法文本对象:iy/ay 基于语法的文本对象 +" Plug 'kana/vim-textobj-syntax' +" +" " 函数文本对象:if/af 支持 c/c++/vim/java +" Plug 'kana/vim-textobj-function', { 'for':['c', 'cpp', 'vim', 'java'] } +" +" " 参数文本对象:i,/a, 包括参数或者列表元素 +" Plug 'sgur/vim-textobj-parameter' +" +" " 提供 python 相关文本对象,if/af 表示函数,ic/ac 表示类 +" Plug 'bps/vim-textobj-python', {'for': 'python'} +" +" " 提供 uri/url 的文本对象,iu/au 表示 +" Plug 'jceb/vim-textobj-uri' +"endif +" +" +""---------------------------------------------------------------------- +"" 文件类型扩展 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'filetypes') >= 0 +" +" " powershell 脚本文件的语法高亮 +" Plug 'pprovost/vim-ps1', { 'for': 'ps1' } +" +" " lua 语法高亮增强 +" Plug 'tbastos/vim-lua', { 'for': 'lua' } +" +" " C++ 语法高亮增强,支持 11/14/17 标准 +" Plug 'octol/vim-cpp-enhanced-highlight', { 'for': ['c', 'cpp'] } +" +" " 额外语法文件 +" Plug 'justinmk/vim-syntax-extra', { 'for': ['c', 'bison', 'flex', 'cpp'] } +" +" " python 语法文件增强 +" Plug 'vim-python/python-syntax', { 'for': ['python'] } +" +" " rust 语法增强 +" Plug 'rust-lang/rust.vim', { 'for': 'rust' } +" +" " vim org-mode +" Plug 'jceb/vim-orgmode', { 'for': 'org' } +"endif +" +" +""---------------------------------------------------------------------- +"" airline +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'airline') >= 0 +" Plug 'vim-airline/vim-airline' +" Plug 'vim-airline/vim-airline-themes' +" let g:airline_left_sep = '' +" let g:airline_left_alt_sep = '' +" let g:airline_right_sep = '' +" let g:airline_right_alt_sep = '' +" let g:airline_powerline_fonts = 0 +" let g:airline_exclude_preview = 1 +" let g:airline_section_b = '%n' +" let g:airline_theme='deus' +" let g:airline#extensions#branch#enabled = 0 +" let g:airline#extensions#syntastic#enabled = 0 +" let g:airline#extensions#fugitiveline#enabled = 0 +" let g:airline#extensions#csv#enabled = 0 +" let g:airline#extensions#vimagit#enabled = 0 +"endif +" +" +""---------------------------------------------------------------------- +"" NERDTree +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'nerdtree') >= 0 +" Plug 'scrooloose/nerdtree', {'on': ['NERDTree', 'NERDTreeFocus', 'NERDTreeToggle', 'NERDTreeCWD', 'NERDTreeFind'] } +" Plug 'tiagofumo/vim-nerdtree-syntax-highlight' +" let g:NERDTreeMinimalUI = 1 +" let g:NERDTreeDirArrows = 1 +" let g:NERDTreeHijackNetrw = 0 +" noremap nn :NERDTree +" noremap no :NERDTreeFocus +" noremap nm :NERDTreeMirror +" noremap nt :NERDTreeToggle +"endif +" +" +""---------------------------------------------------------------------- +"" LanguageTool 语法检查 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'grammer') >= 0 +" Plug 'rhysd/vim-grammarous' +" noremap rg :GrammarousCheck --lang=en-US --no-move-to-first-error --no-preview +" map rr (grammarous-open-info-window) +" map rv (grammarous-move-to-info-window) +" map rs (grammarous-reset) +" map rx (grammarous-close-info-window) +" map rm (grammarous-remove-error) +" map rd (grammarous-disable-rule) +" map rn (grammarous-move-to-next-error) +" map rp (grammarous-move-to-previous-error) +"endif +" +" +""---------------------------------------------------------------------- +"" ale:动态语法检查 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'ale') >= 0 +" Plug 'w0rp/ale' +" +" " 设定延迟和提示信息 +" let g:ale_completion_delay = 500 +" let g:ale_echo_delay = 20 +" let g:ale_lint_delay = 500 +" let g:ale_echo_msg_format = '[%linter%] %code: %%s' +" +" " 设定检测的时机:normal 模式文字改变,或者离开 insert模式 +" " 禁用默认 INSERT 模式下改变文字也触发的设置,太频繁外,还会让补全窗闪烁 +" let g:ale_lint_on_text_changed = 'normal' +" let g:ale_lint_on_insert_leave = 1 +" +" " 在 linux/mac 下降低语法检查程序的进程优先级(不要卡到前台进程) +" if has('win32') == 0 && has('win64') == 0 && has('win32unix') == 0 +" let g:ale_command_wrapper = 'nice -n5' +" endif +" +" " 允许 airline 集成 +" let g:airline#extensions#ale#enabled = 1 +" +" " 编辑不同文件类型需要的语法检查器 +" let g:ale_linters = { +" \ 'c': ['gcc', 'cppcheck'], +" \ 'cpp': ['gcc', 'cppcheck'], +" \ 'python': ['flake8', 'pylint'], +" \ 'lua': ['luac'], +" \ 'go': ['go build', 'gofmt'], +" \ 'java': ['javac'], +" \ 'javascript': ['eslint'], +" \ } +" +" +" " 获取 pylint, flake8 的配置文件,在 vim-init/tools/conf 下面 +" function s:lintcfg(name) +" let conf = s:path('tools/conf/') +" let path1 = conf . a:name +" let path2 = expand('~/.vim/linter/'. a:name) +" if filereadable(path2) +" return path2 +" endif +" return shellescape(filereadable(path2)? path2 : path1) +" endfunc +" +" " 设置 flake8/pylint 的参数 +" let g:ale_python_flake8_options = '--conf='.s:lintcfg('flake8.conf') +" let g:ale_python_pylint_options = '--rcfile='.s:lintcfg('pylint.conf') +" let g:ale_python_pylint_options .= ' --disable=W' +" let g:ale_c_gcc_options = '-Wall -O2 -std=c99' +" let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14' +" let g:ale_c_cppcheck_options = '' +" let g:ale_cpp_cppcheck_options = '' +" +" let g:ale_linters.text = ['textlint', 'write-good', 'languagetool'] +" +" " 如果没有 gcc 只有 clang 时(FreeBSD) +" if executable('gcc') == 0 && executable('clang') +" let g:ale_linters.c += ['clang'] +" let g:ale_linters.cpp += ['clang'] +" endif +"endif +" +" +""---------------------------------------------------------------------- +"" echodoc:搭配 YCM/deoplete 在底部显示函数参数 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'echodoc') >= 0 +" Plug 'Shougo/echodoc.vim' +" set noshowmode +" let g:echodoc#enable_at_startup = 1 +"endif +" +" +""---------------------------------------------------------------------- +"" LeaderF:CtrlP / FZF 的超级代替者,文件模糊匹配,tags/函数名 选择 +""---------------------------------------------------------------------- +"if index(g:bundle_group, 'leaderf') >= 0 +" " 如果 vim 支持 python 则启用 Leaderf +" if has('python') || has('python3') +" Plug 'Yggdroot/LeaderF' +" +" " CTRL+p 打开文件模糊匹配 +" let g:Lf_ShortcutF = '' +" +" " ALT+n 打开 buffer 模糊匹配 +" let g:Lf_ShortcutB = '' +" +" " CTRL+n 打开最近使用的文件 MRU,进行模糊匹配 +" noremap :LeaderfMru +" +" " ALT+p 打开函数列表,按 i 进入模糊匹配,ESC 退出 +" noremap :LeaderfFunction! +" +" " ALT+SHIFT+p 打开 tag 列表,i 进入模糊匹配,ESC退出 +" noremap :LeaderfBufTag! +" +" " ALT+n 打开 buffer 列表进行模糊匹配 +" noremap :LeaderfBuffer +" +" " ALT+m 全局 tags 模糊匹配 +" noremap :LeaderfTag +" +" " 最大历史文件保存 2048 个 +" let g:Lf_MruMaxFiles = 2048 +" +" " ui 定制 +" let g:Lf_StlSeparator = { 'left': '', 'right': '', 'font': '' } +" +" " 如何识别项目目录,从当前文件目录向父目录递归知道碰到下面的文件/目录 +" let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git'] +" let g:Lf_WorkingDirectoryMode = 'Ac' +" let g:Lf_WindowHeight = 0.30 +" let g:Lf_CacheDirectory = expand('~/.vim/cache') +" +" " 显示绝对路径 +" let g:Lf_ShowRelativePath = 0 +" +" " 隐藏帮助 +" let g:Lf_HideHelp = 1 +" +" " 模糊匹配忽略扩展名 +" let g:Lf_WildIgnore = { +" \ 'dir': ['.svn','.git','.hg'], +" \ 'file': ['*.sw?','~$*','*.bak','*.exe','*.o','*.so','*.py[co]'] +" \ } +" +" " MRU 文件忽略扩展名 +" let g:Lf_MruFileExclude = ['*.so', '*.exe', '*.py[co]', '*.sw?', '~$*', '*.bak', '*.tmp', '*.dll'] +" let g:Lf_StlColorscheme = 'powerline' +" +" " 禁用 function/buftag 的预览功能,可以手动用 p 预览 +" let g:Lf_PreviewResult = {'Function':0, 'BufTag':0} +" +" " 使用 ESC 键可以直接退出 leaderf 的 normal 模式 +" let g:Lf_NormalMap = { +" \ "File": [["", ':exec g:Lf_py "fileExplManager.quit()"']], +" \ "Buffer": [["", ':exec g:Lf_py "bufExplManager.quit()"']], +" \ "Mru": [["", ':exec g:Lf_py "mruExplManager.quit()"']], +" \ "Tag": [["", ':exec g:Lf_py "tagExplManager.quit()"']], +" \ "BufTag": [["", ':exec g:Lf_py "bufTagExplManager.quit()"']], +" \ "Function": [["", ':exec g:Lf_py "functionExplManager.quit()"']], +" \ } +" +" else +" " 不支持 python ,使用 CtrlP 代替 +" Plug 'ctrlpvim/ctrlp.vim' +" +" " 显示函数列表的扩展插件 +" Plug 'tacahiroy/ctrlp-funky' +" +" " 忽略默认键位 +" let g:ctrlp_map = '' +" +" " 模糊匹配忽略 +" let g:ctrlp_custom_ignore = { +" \ 'dir': '\v[\/]\.(git|hg|svn)$', +" \ 'file': '\v\.(exe|so|dll|mp3|wav|sdf|suo|mht)$', +" \ 'link': 'some_bad_symbolic_links', +" \ } +" +" " 项目标志 +" let g:ctrlp_root_markers = ['.project', '.root', '.svn', '.git'] +" let g:ctrlp_working_path = 0 +" +" " CTRL+p 打开文件模糊匹配 +" noremap :CtrlP +" +" " CTRL+n 打开最近访问过的文件的匹配 +" noremap :CtrlPMRUFiles +" +" " ALT+p 显示当前文件的函数列表 +" noremap :CtrlPFunky +" +" " ALT+n 匹配 buffer +" noremap :CtrlPBuffer +" endif +"endif +" +" +""---------------------------------------------------------------------- +"" 结束插件安装 +""---------------------------------------------------------------------- +"call plug#end() +" +" +" +""---------------------------------------------------------------------- +"" YouCompleteMe 默认设置:YCM 需要你另外手动编译安装 +""---------------------------------------------------------------------- +" +"" 禁用预览功能:扰乱视听 +"let g:ycm_add_preview_to_completeopt = 0 +" +"" 禁用诊断功能:我们用前面更好用的 ALE 代替 +"let g:ycm_show_diagnostics_ui = 0 +"let g:ycm_server_log_level = 'info' +"let g:ycm_min_num_identifier_candidate_chars = 2 +"let g:ycm_collect_identifiers_from_comments_and_strings = 1 +"let g:ycm_complete_in_strings=1 +"let g:ycm_key_invoke_completion = '' +"set completeopt=menu,menuone,noselect +" +"" noremap +" +"" 两个字符自动触发语义补全 +"let g:ycm_semantic_triggers = { +" \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'], +" \ 'cs,lua,javascript': ['re!\w{2}'], +" \ } +" +" +""---------------------------------------------------------------------- +"" Ycm 白名单(非名单内文件不启用 YCM),避免打开个 1MB 的 txt 分析半天 +""---------------------------------------------------------------------- +"let g:ycm_filetype_whitelist = { +" \ "c":1, +" \ "cpp":1, +" \ "objc":1, +" \ "objcpp":1, +" \ "python":1, +" \ "java":1, +" \ "javascript":1, +" \ "coffee":1, +" \ "vim":1, +" \ "go":1, +" \ "cs":1, +" \ "lua":1, +" \ "perl":1, +" \ "perl6":1, +" \ "php":1, +" \ "ruby":1, +" \ "rust":1, +" \ "erlang":1, +" \ "asm":1, +" \ "nasm":1, +" \ "masm":1, +" \ "tasm":1, +" \ "asm68k":1, +" \ "asmh8300":1, +" \ "asciidoc":1, +" \ "basic":1, +" \ "vb":1, +" \ "make":1, +" \ "cmake":1, +" \ "html":1, +" \ "css":1, +" \ "less":1, +" \ "json":1, +" \ "cson":1, +" \ "typedscript":1, +" \ "haskell":1, +" \ "lhaskell":1, +" \ "lisp":1, +" \ "scheme":1, +" \ "sdl":1, +" \ "sh":1, +" \ "zsh":1, +" \ "bash":1, +" \ "man":1, +" \ "markdown":1, +" \ "matlab":1, +" \ "maxima":1, +" \ "dosini":1, +" \ "conf":1, +" \ "config":1, +" \ "zimbu":1, +" \ "ps1":1, +" \ } + + +call plug#end() diff --git a/vim/init/style.vim b/vim/init/style.vim new file mode 100644 index 0000000..8d056b0 --- /dev/null +++ b/vim/init/style.vim @@ -0,0 +1,291 @@ +"====================================================================== +" +" init-style.vim - 显示样式设置 +" +" Created by skywind on 2018/05/30 +" Last Modified: 2018/05/30 20:29:07 +" +"====================================================================== +" vim: set ts=4 sw=4 tw=78 noet : + + +"---------------------------------------------------------------------- +" 显示设置 +"---------------------------------------------------------------------- + +" 总是显示状态栏 +set laststatus=2 + +" 总是显示行号 +set number + +" 总是显示侧边栏(用于显示 mark/gitdiff/诊断信息) +set signcolumn=yes + +" 总是显示标签栏 +set showtabline=2 + +" 设置显示制表符等隐藏字符 +set list + +" 右下角显示命令 +set showcmd + +" 插入模式在状态栏下面显示 -- INSERT --, +" 先注释掉,默认已经为真了,如果这里再设置一遍会影响 echodoc 插件 +" set showmode + +" 水平切割窗口时,默认在右边显示新窗口 +set splitright + + +"---------------------------------------------------------------------- +" 颜色主题:色彩文件位于 colors 目录中 +"---------------------------------------------------------------------- + +" 设置黑色背景 +set background=dark + +" 允许 256 色 +set t_Co=256 + +" 设置颜色主题,会在所有 runtimepaths 的 colors 目录寻找同名配置 +" color desert256 + + +"---------------------------------------------------------------------- +" 状态栏设置 +"---------------------------------------------------------------------- +set statusline= " 清空状态了 +set statusline+=\ %F " 文件名 +set statusline+=\ [%1*%M%*%n%R%H] " buffer 编号和状态 +set statusline+=%= " 向右对齐 +set statusline+=\ %y " 文件类型 + +" 最右边显示文件编码和行号等信息,并且固定在一个 group 中,优先占位 +set statusline+=\ %0(%{&fileformat}\ [%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %v:%l/%L%) + + +"---------------------------------------------------------------------- +" 更改样式 +"---------------------------------------------------------------------- + +" 更清晰的错误标注:默认一片红色背景,语法高亮都被搞没了 +" 只显示红色或者蓝色下划线或者波浪线 +hi! clear SpellBad +hi! clear SpellCap +hi! clear SpellRare +hi! clear SpellLocal +if has('gui_running') + hi! SpellBad gui=undercurl guisp=red + hi! SpellCap gui=undercurl guisp=blue + hi! SpellRare gui=undercurl guisp=magenta + hi! SpellRare gui=undercurl guisp=cyan +else + hi! SpellBad term=standout ctermfg=1 term=underline cterm=underline + hi! SpellCap term=underline cterm=underline + hi! SpellRare term=underline cterm=underline + hi! SpellLocal term=underline cterm=underline +endif + +" 去掉 sign column 的白色背景 +hi! SignColumn guibg=NONE ctermbg=NONE + +" 修改行号为浅灰色,默认主题的黄色行号很难看,换主题可以仿照修改 +highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE + \ gui=NONE guifg=DarkGrey guibg=NONE + +" 修正补全目录的色彩:默认太难看 +hi! Pmenu guibg=gray guifg=black ctermbg=gray ctermfg=black +hi! PmenuSel guibg=gray guifg=brown ctermbg=brown ctermfg=gray + + +"---------------------------------------------------------------------- +" 终端设置,隐藏行号和侧边栏 +"---------------------------------------------------------------------- +if has('terminal') && exists(':terminal') == 2 + if exists('##TerminalOpen') + augroup VimUnixTerminalGroup + au! + au TerminalOpen * setlocal nonumber signcolumn=no + augroup END + endif +endif + + +"---------------------------------------------------------------------- +" quickfix 设置,隐藏行号 +"---------------------------------------------------------------------- +augroup VimInitStyle + au! + au FileType qf setlocal nonumber +augroup END + + +"---------------------------------------------------------------------- +" 标签栏文字风格:默认为零,GUI 模式下空间大,按风格 3显示 +" 0: filename.txt +" 2: 1 - filename.txt +" 3: [1] filename.txt +"---------------------------------------------------------------------- +if has('gui_running') + let g:config_vim_tab_style = 3 +endif + + +"---------------------------------------------------------------------- +" 终端下的 tabline +"---------------------------------------------------------------------- +function! Vim_NeatTabLine() + let s = '' + for i in range(tabpagenr('$')) + " select the highlighting + if i + 1 == tabpagenr() + let s .= '%#TabLineSel#' + else + let s .= '%#TabLine#' + endif + + " set the tab page number (for mouse clicks) + let s .= '%' . (i + 1) . 'T' + + " the label is made by MyTabLabel() + let s .= ' %{Vim_NeatTabLabel(' . (i + 1) . ')} ' + endfor + + " after the last tab fill with TabLineFill and reset tab page nr + let s .= '%#TabLineFill#%T' + + " right-align the label to close the current tab page + if tabpagenr('$') > 1 + let s .= '%=%#TabLine#%999XX' + endif + + return s +endfunc + + +"---------------------------------------------------------------------- +" 需要显示到标签上的文件名 +"---------------------------------------------------------------------- +function! Vim_NeatBuffer(bufnr, fullname) + let l:name = bufname(a:bufnr) + if getbufvar(a:bufnr, '&modifiable') + if l:name == '' + return '[No Name]' + else + if a:fullname + return fnamemodify(l:name, ':p') + else + let aname = fnamemodify(l:name, ':p') + let sname = fnamemodify(aname, ':t') + if sname == '' + let test = fnamemodify(aname, ':h:t') + if test != '' + return '<'. test . '>' + endif + endif + return sname + endif + endif + else + let l:buftype = getbufvar(a:bufnr, '&buftype') + if l:buftype == 'quickfix' + return '[Quickfix]' + elseif l:name != '' + if a:fullname + return '-'.fnamemodify(l:name, ':p') + else + return '-'.fnamemodify(l:name, ':t') + endif + else + endif + return '[No Name]' + endif +endfunc + + +"---------------------------------------------------------------------- +" 标签栏文字,使用 [1] filename 的模式 +"---------------------------------------------------------------------- +function! Vim_NeatTabLabel(n) + let l:buflist = tabpagebuflist(a:n) + let l:winnr = tabpagewinnr(a:n) + let l:bufnr = l:buflist[l:winnr - 1] + let l:fname = Vim_NeatBuffer(l:bufnr, 0) + let l:num = a:n + let style = get(g:, 'config_vim_tab_style', 0) + if style == 0 + return l:fname + elseif style == 1 + return "[".l:num."] ".l:fname + elseif style == 2 + return "".l:num." - ".l:fname + endif + if getbufvar(l:bufnr, '&modified') + return "[".l:num."] ".l:fname." +" + endif + return "[".l:num."] ".l:fname +endfunc + + +"---------------------------------------------------------------------- +" GUI 下的标签文字,使用 [1] filename 的模式 +"---------------------------------------------------------------------- +function! Vim_NeatGuiTabLabel() + let l:num = v:lnum + let l:buflist = tabpagebuflist(l:num) + let l:winnr = tabpagewinnr(l:num) + let l:bufnr = l:buflist[l:winnr - 1] + let l:fname = Vim_NeatBuffer(l:bufnr, 0) + let style = get(g:, 'config_vim_tab_style', 0) + if style == 0 + return l:fname + elseif style == 1 + return "[".l:num."] ".l:fname + elseif style == 2 + return "".l:num." - ".l:fname + endif + if getbufvar(l:bufnr, '&modified') + return "[".l:num."] ".l:fname." +" + endif + return "[".l:num."] ".l:fname +endfunc + + + +"---------------------------------------------------------------------- +" 设置 GUI 标签的 tips: 显示当前标签有哪些窗口 +"---------------------------------------------------------------------- +function! Vim_NeatGuiTabTip() + let tip = '' + let bufnrlist = tabpagebuflist(v:lnum) + for bufnr in bufnrlist + " separate buffer entries + if tip != '' + let tip .= " \n" + endif + " Add name of buffer + let name = Vim_NeatBuffer(bufnr, 1) + let tip .= name + " add modified/modifiable flags + if getbufvar(bufnr, "&modified") + let tip .= ' [+]' + endif + if getbufvar(bufnr, "&modifiable")==0 + let tip .= ' [-]' + endif + endfor + return tip +endfunc + + +"---------------------------------------------------------------------- +" 标签栏最终设置 +"---------------------------------------------------------------------- +set tabline=%!Vim_NeatTabLine() +set guitablabel=%{Vim_NeatGuiTabLabel()} +set guitabtooltip=%{Vim_NeatGuiTabTip()} + + + diff --git a/vim/init/tabsize.vim b/vim/init/tabsize.vim new file mode 100644 index 0000000..b383b80 --- /dev/null +++ b/vim/init/tabsize.vim @@ -0,0 +1,44 @@ +"====================================================================== +" +" init-tabsize.vim - 大部分人对 tabsize 都有自己的设置,改这里即可 +" +" Created by skywind on 2018/05/30 +" Last Modified: 2018/05/30 22:05:44 +" +"====================================================================== +" vim: set ts=4 sw=4 tw=78 noet : + + +"---------------------------------------------------------------------- +" 默认缩进模式(可以后期覆盖) +"---------------------------------------------------------------------- + +set expandtab +set shiftwidth=2 +set autoindent +set tabstop=4 +set softtabstop=0 +set smartindent + +" 设置缩进宽度 +"set sw=4 + +" 设置 TAB 宽度 +set ts=4 + +" 禁止展开 tab (noexpandtab) +"set noet + +" 如果后面设置了 expandtab 那么展开 tab 为多少字符 +set tabstop=4 +set softtabstop=0 + + +augroup PythonTab + au! + " 如果你需要 python 里用 tab,那么反注释下面这行字,否则vim会在打开py文件 + " 时自动设置成空格缩进。 + "au FileType python setlocal shiftwidth=4 tabstop=4 noexpandtab +augroup END + + -- cgit v1.2.3-70-g09d2