" basic settings set ts=4 set sw=4 set cc=120 set expandtab set nu set hidden set list set autoindent set confirm set noundofile set nobackup set nowritebackup set hlsearch set noswapfile set ignorecase set smarttab set smartindent set cursorline set incsearch set signcolumn=yes set laststatus=2 set fillchars=vert:\ ,fold:- set clipboard=unnamedplus " system clipboard as default register. for vim to work need installing gvim package set mouse=a set spell filetype plugin indent on syntax on au! BufWritePost $MYVIMRC source % cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap inoremap inoremap inoremap inoremap inoremap inoremap inoremap noremap noremap noremap noremap vnoremap p pgvy nnoremap q :qall nnoremap v nnoremap s :b# nnoremap 1 :b1 nnoremap 2 :b2 nnoremap 3 :b3 nnoremap 4 :b4 nnoremap 5 :b5 nnoremap w :w nnoremap :noh xnoremap y :'<,'>:w !clip.exe nmap "" ysiW" nmap '' ysiW' nmap " ysiw" nmap ' ysiw' nmap `` ysiW` nmap ` ysiw` nmap sb :windo set scrollbind:windo set cursorbind:set mouse=a nmap nsb :windo set noscrollbind:windo set nocursorbind:set mouse= inoremap nmap ss :syntax sync fromstart " // to search highlighted text vnoremap // y/\V=escape(@",'/\') " trailing spaces highlight ExtraWhitespace ctermbg=red guibg=red au ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red au Syntax * match ExtraWhitespace /\s\+$/ nnoremap es :%s/\s\+$//g " location jumping nnoremap n :cnext nnoremap p :cprev " auto install vim-plug if has('nvim') if has('win32') let vim_plug_path = $LOCALAPPDATA . "/nvim/autoload/plug.vim" else let vim_plug_path = expand("~/.config/nvim/autoload/plug.vim") endif else set ttymouse=sgr "map "map let vim_plug_path = expand("~/.vim/autoload/plug.vim") set listchars=eol:\ ,tab:>\ ,trail:~,extends:>,precedes:< endif let vim_plug_just_installed = 0 if !filereadable(vim_plug_path) echo "Installing vim-plug..." :exe "!curl -fLo \"" . vim_plug_path . "\" --create-dirs https://gitee.com/klesh/vim-plug/raw/master/plug.vim" let vim_plug_just_installed = 1 echo "vim-plug installed" endif call plug#begin('~/.vim/plugged') Plug 'editorconfig/editorconfig-vim' Plug 'tpope/vim-surround' Plug 'jiangmiao/auto-pairs' Plug 'posva/vim-vue', { 'for': 'vue' } Plug 'tpope/vim-repeat' Plug 'liuchengxu/eleline.vim' Plug 'klesh/vim-fugitive' " git 功能 Plug 'scrooloose/nerdcommenter' Plug 'mhinz/vim-grepper', { 'on': ['Grepper', '(GrepperOperator)'] } Plug 'morhetz/gruvbox' Plug 'klesh/vim-fish', { 'for': 'fish' } Plug 'alvan/vim-closetag', { 'for': ['vue', 'html', 'xml'] } "Plug 'francoiscabrol/ranger.vim' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' if $VIM_MODE == 'enhanced' if !executable("node") || !executable("yarnpkg") echo "nodejs/yarnpkg must be installed in order to use coc.nvim" else Plug 'neoclide/coc.nvim', {'branch': 'release'} end Plug 'chrisbra/Colorizer' Plug 'tpope/vim-markdown', { 'for': 'markdown' } Plug 'cespare/vim-toml', { 'for': 'toml' } Plug 'vim-scripts/mom.vim' else Plug 'Vimjas/vim-python-pep8-indent', { 'for': 'python' } endif if has('win32') Plug 'zigford/vim-powershell' endif call plug#end() " ==== vim-markdown configuration ==== let g:vim_markdown_folding_disabled = 1 " ==== vim-closetag configuration ==== let g:closetag_filetypes = 'html,xhtml,phtml,vue' if $VIM_MODE == 'enhanced' " ==== coc configuration ==== let g:coc_global_extensions = [ \ 'coc-diagnostic', \ 'coc-clangd' \ ] "let g:coc_disable_startup_warning = 1 set statusline^=%{coc#status()} nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) xmap fs (coc-format-selected) nmap fs (coc-format-selected) nmap fd (coc-format) nmap rn (coc-rename) nmap ne (coc-diagnostic-next-error) nmap pe (coc-diagnostic-prev-error) nmap oi :CocInfo "nmap ol :CocList nmap olr :CocListResume nmap od :call CocAction('doHover') nmap ol (coc-openlink) nmap oc :CocCommand autocmd BufEnter,BufRead,BufNewFile *.js set syntax=typescript " ==== vimspector configuration ==== let g:vimspector_enable_mappings = 'VISUAL_STUDIO' let g:vimspector_install_gadgets = [ 'debugpy', 'vscode-cpptools' ] endif " ==== auto-pairs configuration ==== nmap ap :call AutoPairsToggle() let g:AutoPairsShortcutToggle = '' " ==== grepper configuration ==== " nnoremap sg :Grepper -tool git nnoremap sc :Grepper -tool grep nnoremap sa :Grepper -tool ag " ==== quickfix configuration ==== nnoremap j :cn nnoremap k :cp "" ==== NERDTree configuration ==== "nnoremap fe :NERDTreeToggle " ==== Ranger configuration ==== let g:ranger_map_keys = 0 "nnoremap :Ranger " ==== netrw configuration ==== nnoremap :Explore autocmd BufEnter,BufRead nnoremap cg :call OpenRangerIn(system("git rev-parse --show-toplevel >/dev/null || pwd"), 'edit ') " ==== fugitive configuration ==== nnoremap gs :Gstatus nnoremap gc :Gcommit nnoremap gp :Gpush nnoremap gg :Gpull nnoremap gd :Gdiff nnoremap gb :Gblame nnoremap gl :Glog nnoremap gms :Gvdiffsplit! nnoremap gmh :diffget //2 nnoremap gml :diffget //3 nnoremap gsc :exec "!git switch -c " . input("Enter new branch name:") " ==== functions ====== fu! SilentOK(cmd) let l:output = system(substitute(a:cmd, "%", expand("%"), "g")) if v:shell_error != 0 echo l:output endif endfu fu! SystemOr(cmd, default) let l:output = system(substitute(a:cmd, "%", expand("%"), "g")) if v:shell_error != 0 return a:default endif return trim(l:output) endfu " ==== ctrlp configuration ==== "let g:ctrlp_user_command = ['.git', 'git ls-files -co --exclude-standard'] " ==== fzf configuration ==== " enable for fzf let g:fugitive_no_maps=1 let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -l -g ""' nnoremap :call fzf#vim#files(SystemOr("git rev-parse --show-toplevel", ".")) nnoremap gco :call fzf#run({'source': 'git branch \| cut -c 3-; git tag -l', 'sink': '!git checkout'}) nnoremap gm :call fzf#run({'source': 'git branch \| cut -c 3-', 'sink': '!git merge'}) nnoremap b :Buffers " ==== gruvbox configuration ==== color gruvbox set background=dark " for background transparence to work highlight Normal ctermbg=None highlight CursorLine ctermbg=240 " ==== NERDCommenter for vue ==== let g:ft = '' fu! NERDCommenter_before() if &ft == 'vue' let g:ft = 'vue' let stack = synstack(line('.'), col('.')) if len(stack) > 0 let syn = synIDattr((stack)[0], 'name') if len(syn) > 0 let syn = tolower(syn) exe 'setf '.syn endif endif endif endfu fu! NERDCommenter_after() if g:ft == 'vue' setf vue g:ft endif endfu " ==== groff ==== fu! ToggleGroffMomAutoCompilation() let g:GroffMomAutoCompilation = !get(g:, "GroffMomAutoCompilation", 0) augroup GroffPdf autocmd! augroup END if g:GroffMomAutoCompilation augroup GroffPdf autocmd BufWritePost,FileWritePost *.mom :call SilentOK("groff -Kutf8 -mom % > /tmp/tmp.ps && ps2pdf /tmp/tmp.ps %.pdf") augroup END echo "Auto compilation for groff_mom enabled" else echo "Auto compilation for groff_mom disabled" endif endfu nnoremap ac :call ToggleGroffMomAutoCompilation() autocmd BufEnter,BufRead *.mom :set ft=mom " for yaml need cursorcolumn autocmd FileType yaml :set cursorcolumn " spell highlight highlight clear SpellBad highlight SpellBad cterm=underline highlight SpellBad gui=undercurl