" auto install vim-plug let vim_plug_just_installed = 0 let vim_plug_path = expand('~/.vim/autoload/plug.vim') if !filereadable(vim_plug_path) echo "Installing Vim-plug..." echo "" silent !mkdir -p ~/.vim/autoload silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://github.com/junegunn/vim-plug/raw/master/plug.vim let vim_plug_just_installed = 1 endif " manually load vim-plug the first time if vim_plug_just_installed :execute 'source '.fnameescape(vim_plug_path) endif if !has('nvim') set mouse=a set ttymouse=xterm2 endif set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set termencoding=utf-8 set encoding=utf-8 let s:uname = system("uname -s") let s:nix = s:uname =~ '\(Darwin\|Linux\)\n' if s:nix call plug#begin() else set rtp+=$VIM/bundle/Vundle.vim/ " 把 Vundle 加入搜索路径 call plug#begin('$VIM/bundle/') language messages zh_CN.utf-8 set langmenu=zh_CN.utf-8 set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set guioptions-=T source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim endif Plug 'terryma/vim-multiple-cursors' Plug 'jiangmiao/auto-pairs' "Plug 'scrooloose/syntastic' "Plug 'w0rp/ale' Plug 'scrooloose/nerdtree' Plug 'alvan/vim-closetag' "Plug 'AndrewRadev/tagalong.vim' Plug 'tpope/vim-repeat' Plug 'tpope/vim-fugitive' " git 功能 Plug 'tpope/vim-surround' "Plug 'vim-airline/vim-airline' "Plug 'vim-airline/vim-airline-themes' Plug 'scrooloose/nerdcommenter' Plug 'editorconfig/editorconfig-vim' Plug 'mhinz/vim-grepper', { 'on': ['Grepper', '(GrepperOperator)'] } Plug 'ctrlpvim/ctrlp.vim' Plug 'lunaru/vim-less' Plug 'posva/vim-vue' Plug 'othree/html5.vim' Plug 'mtscout6/syntastic-local-eslint.vim' Plug 'pangloss/vim-javascript' Plug 'klesh/vim-fakeclip' Plug 'dag/vim-fish' Plug 'digitaltoad/vim-pug' "Plug 'ludovicchabant/vim-gutentags' Plug 'godlygeek/tabular' Plug 'plasticboy/vim-markdown' Plug 'triglav/vim-visual-increment' Plug 'jvirtanen/vim-octave' Plug 'vim-python/python-syntax' Plug 'mgedmin/coverage-highlight.vim' Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'neoclide/coc-python', {'do': 'yarn install --frozen-lockfile'} Plug 'neoclide/coc-tsserver', {'do': 'yarn install --frozen-lockfile'} Plug 'morhetz/gruvbox' Plug 'peitalin/vim-jsx-typescript' call plug#end() " coc configuration, may need to run `yarn` in ~/.vim/coc-python folder " $ pip install --user python-language-server jedi rope " Remap keys for gotos nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) " Highlight symbol under cursor on CursorHold autocmd CursorHold * silent call CocActionAsync('highlight') " Use K to show documentation in preview window nnoremap K :call show_documentation() " Remap for rename current word nmap rn (coc-rename) " Remap for format selected region xmap f (coc-format-selected) nmap f (coc-format-selected) function! s:show_documentation() if (index(['vim','help'], &filetype) >= 0) execute 'h '.expand('') else call CocAction('doHover') endif endfunction " markdown let g:vim_markdown_folding_disabled = 1 let g:vim_markdown_math = 1 " nerdtree let NERDTreeDirArrowExpandable = "+" let NERDTreeDirArrowCollapsible = "-" " python let g:python_highlight_all = 1 " airline let g:airline_theme='bubblegum' let g:airline_left_sep = '' let g:airline_right_sep = '' "let g:airline_left_sep = ' ' "let g:airline_right_sep = ' ' let g:airline_symbols#crypt = '🔒' let g:airline_symbols#linenr = '¶' let g:airline_symbols#maxlinenr = '☰' let g:airline_symbols#branch = '' "let g:airline_symbols#paste = 'ρ' let g:airline_symbols#paste = 'Þ' "let g:airline_symbols#paste = '∥' "let g:airline_symbols#spell = 'Ꞩ' "let g:airline_symbols#notexists = '∄' "let g:airline_symbols#whitespace = 'Ξ' " "let g:airline_theme='luna' " CtrlP let g:ctrlp_user_command = ['.git', 'git ls-files -co --exclude-standard'] "let g:ctrlp_map = '' " NERDTree let NERDTreeIgnore = ['\.pyc$', '__pycache__'] " syntastic " let g:syntastic_javascript_checkers = ['eslint'] "let g:ale_python_pylint_change_directory = 0 let g:ale_linters = { \ 'python': ['flake8'] \} " vue-vim " 解决跳到尾部时语法高亮不正常的问题 autocmd FileType vue syntax sync fromstart " 利用现有的插件对语法进行高亮 "autocmd BufRead,BufNewFile *.vue setlocal filetype=vue.html5.javascript.less autocmd BufRead,BufNewFile *.vue setlocal filetype=vue " vim set ts=4 set sw=4 set listchars=eol:$,tab:->,extends:>,precedes:<,space:., set list set nu set expandtab set hidden set autoindent set confirm set noundofile set nobackup set ruler " 开启游标右下角行、列显示 set noswapfile " 关闭临时文件 set hlsearch set lazyredraw set noshowmatch set laststatus=2 let html_no_rendering=1 set fillchars=vert:\ ,fold:- "highlight VertSplit guibg=Orange guifg=Black ctermbg=None ctermfg=033 hi StatusLine cterm=NONE " keybindings " 从系统剪贴板复制/粘贴 "inoremap "+pa "nnoremap "+p "vnoremap "+p "vnoremap "+y vmap (fakeclip-y) inoremap ::wa nnoremap ::w "nnoremap :CtrlP nnoremap n :NERDTreeToggle nnoremap g :Grepper -tool git nnoremap :noh nnoremap o :only nnoremap w nnoremap q :qall vnoremap p "_dP nnoremap e :%s/\s\+$//g nnoremap s :syntax sync fromstart nnoremap c ::set cursorcolumn! nnoremap h h nnoremap j j nnoremap k k nnoremap l l nnoremap m :vertical resize +5 nnoremap , :vertical resize -5 nnoremap . :resize +5 nnoremap / :resize -5 nnoremap d :vs nnoremap [ :lprev nnoremap ] :lnext vnoremap m c=trim(@") . '=' . trim(system('math ' . shellescape(@"))) " 行尾空格高亮 highlight ExtraWhitespace ctermbg=red guibg=red au ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red au Syntax * match ExtraWhitespace /\s\+$/ " iterm2 插入模式时backspace不works set backspace=indent,eol,start function! ReadClipboardWsl() let text = system('powershell.exe -Command Get-Clipboard') let text = substitute(text, "\r\n", '', 'g') return text endfunction function! TabNewFromClipboard() exec ':tabnew ' . ReadClipboardWsl() endfunction function! Jsonpp() "exec ':%!python -m json.tool' exec ':%!json_pp' endfunction function! DecodeHtml() exec ':%s/
/```\r/g'
  exec ':%s/<\/pre>/\r```/g'
  exec ':%s/<//g'
  exec ':%s/&/\&/g'
endfunction

cnoremap  
cnoremap  
cnoremap  
cnoremap  
cnoremap  
cnoremap  
cnoremap  

inoremap  
inoremap  
inoremap  
inoremap  
inoremap  
inoremap  
inoremap  

noremap  
noremap  
noremap  
noremap  
noremap  
noremap  

function! MathAndLiquid()
  "" Define certain regions
  " Block math. Look for "$$[anything]$$"
  syn region math start=/\$\$/ end=/\$\$/
  " inline math. Look for "$[not $][anything]$"
  syn match math_block '\$[^$].\{-}\$'

  " Liquid single line. Look for "{%[anything]%}"
  syn match liquid '{%.*%}'
  " Liquid multiline. Look for "{%[anything]%}[anything]{%[anything]%}"
  syn region highlight_block start='{% highlight .*%}' end='{%.*%}'
  " Fenced code blocks, used in GitHub Flavored Markdown (GFM)
  syn region highlight_block start='```' end='```'

  "" Actually highlight those regions.
  hi link math Statement
  hi link liquid Statement
  hi link highlight_block Function
  hi link math_block Function
endfunction

" Call everytime we open a Markdown file
"autocmd BufRead,BufNewFile,BufEnter *.md,*.markdown call MathAndLiquid()

" \vm 2 4\
" \begin{vmatrix}
" <++> & <++> & <++> & <++> \\
" <++> & <++> & <++> & <++ > \\
" \end{vmatrix}<++>
"
function! Tex()
  let mark = '\'
  let sepr = ' '
  let tags = {'vm': 'vmatrix', 'bm': 'bmatrix', 'mt': 'matrix', 'cs': 'cases', 'ad': 'aligned', 'al': 'align', 'ar': 'array'}
  let text = getline('.')
  let end = col('.')
  let start = strridx(text, mark, end)
  if start > -1
    let params = strpart(text, start+1, end - start - 1)
    let params = split(params, sepr)
    let abbr = params[0]
    if strlen(abbr) == 0 || !has_key(tags, abbr)
      return
    endif
    let rc = params[1]
    if !(rc>0)
      return
    endif
    if len(params)>2
      let cc = params[2]
      if !(cc>0)
        return
      endif
    else
      let cc = 1
    end

    let prefix = repeat(' ', start)

    let thecols = []
    let i = 0
    while i < cc
      call add(thecols, '<++>')
      let i += 1
    endwhile
    let columnsText = prefix . '  '. join(thecols, ' & ') . ' \\'

    let lines = []
    let i = 0
    while i < rc
      call add(lines, columnsText)
      let i += 1
    endwhile
    call add(lines, prefix . '\end{' . tags[abbr] . '}<++>')

    let leftPart = strpart(text, 0, start)
    let rightPart = strpart(text, end)
    if strlen(rightPart) > 0
      call add(lines, prefix . rightPart)
    endif
    call setline(line('.'), leftPart . '\begin{' . tags[abbr] . '}')
    call append(line('.'), lines)
    "call append(line('.'), lines)
  endif
endfunction

" autocmd FileType markdown
inoremap  :call Tex()a
" Navigating with guides
inoremap  /<++>"_c4l
vnoremap  /<++>"_c4l
map  /<++>"_c4l
nmap    NERDCommenterToggle
vmap    NERDCommenterTogglegv

" Markdown setup
autocmd FileType markdown inoremap \cs \begin{cases}\end{cases}<++>F\i
autocmd FileType markdown inoremap \fr \frac{<++>}{<++>}<++>F\i
autocmd FileType markdown inoremap ` `$$`<++>F$i
autocmd FileType markdown inoremap $ $$$$<++>kO
autocmd FileType markdown inoremap \{ \{\}<++>F{a
autocmd FileType markdown vnoremap b c__"__
autocmd FileType json nnoremap f %!json_pp

function! HTML5()
  let html = []
  call setline(1, '')
  call add(html, '')
  call add(html, ' ')
  call add(html, '   ')
  call add(html, '   <++>')
  call add(html, ' ')
  call add(html, ' ')
  call add(html, ' <++>')
  call add(html, ' ')
  call add(html, '')
  call append(1, html)
endfunction

color gruvbox
set background=dark
highlight Normal ctermbg=None

" closetag
" dict
" Disables auto-close if not in a "valid" region (based on filetype)
let g:closetag_regions = {
    \ 'typescript.tsx': 'jsxRegion,tsxRegion',
    \ 'javascript.jsx': 'jsxRegion',
    \ }
let g:closetag_shortcut = '>'
let g:closetag_filenames = "*.html,*.xhtml,*.phtml,*.js,*.vue,*.tsx"
"
"let g:tagalong_additional_filetypes = ['typescript.tsx']

fu! NERDCommenter_before()
  if &ft == 'vue'
    let b:isvue = 1
    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 exists('b:isvue') && b:isvue
    setf vue
    let b:isvue = 0
  endif
endfu
"

"fu! NERDCommenter_before()
  "setf javascript
"endfu


"fu! NERDCommenter_after()
  "setf vue
"endfu