wsdjeg / reading-vimrc

vimrc 读书会,帮你提升你的 vimrc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My `.vimrc`

yunlingz opened this issue · comments

"===========================================================================
" SPDX-License-Identifier: Apache-2.0
"
" Copyright 2017-2019 chuling <meetchuling@outlook.com>
"
" Licensed under the Apache License, Version 2.0 (the "License");
" you may not use this file except in compliance with the License.
" You may obtain a copy of the License at
"
" http://www.apache.org/licenses/LICENSE-2.0
"
" Unless required by applicable law or agreed to in writing, software
" distributed under the License is distributed on an "AS IS" BASIS,
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
" See the License for the specific language governing permissions and
" limitations under the License.
"===========================================================================

set nocompatible
call plug#begin('~/.vim/plugged')

Plug 'chuling/vim_equinusocio_material'
Plug 'NLKNguyen/papercolor-theme'
Plug 'morhetz/gruvbox'
Plug 'sheerun/vim-polyglot'
Plug 'itchyny/lightline.vim'
Plug 'mengelbrecht/lightline-bufferline'
Plug 'ycm-core/YouCompleteMe', { 'do': 'python3 ./install.py --clang-completer' }
Plug 'w0rp/ale', { 'for': [ 'python' ] }
Plug 'Chiel92/vim-autoformat'
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/nerdcommenter'
Plug 'jiangmiao/auto-pairs'
Plug 'majutsushi/tagbar'
Plug 'tikhomirov/vim-glsl'
Plug 'rust-lang/rust.vim'
Plug 'mesonbuild/meson', { 'rtp': 'data/syntax-highlighting/vim/' }
" Plug 'ctrlpvim/ctrlp.vim' " in favor of fzf
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'

call plug#end()
command! PU PlugUpdate | PlugUpgrade

" --------------------------------------------------------

" ========================================================
" light color scheme
" --------------------------------------------------------
" syntax on
" set termguicolors
" let g:PaperColor_Theme_Options = {
"   \ 'theme': { 'default.light': { 'override' : {
"   \   'color00' : ['#ffffff', '231'],
"   \   'cursor_fg' : ['#ffffff', '231'],
"   \   'cursorlinenr_bg' : ['#ffffff', '231'],
"   \   'linenumber_bg' : ['#ffffff', '231'],
"   \   'vertsplit_bg' : ['#ffffff', '231'],
"   \   'todo_bg' : ['#ffffff', '231'],
"   \   'visual_fg' : ['#ffffff', '231'],
"   \   'tabline_inactive_fg' : ['#ffffff', '231'],
"   \   'buftabline_active_fg' : ['#ffffff', '231'],
"   \   'buftabline_inactive_fg' : ['#ffffff', '231'],
"   \ }}}}
" set background=light
" colorscheme PaperColor
" ========================================================

" ========================================================
" material dark color scheme
" --------------------------------------------------------
syntax on
set termguicolors
set background=dark
let g:equinusocio_material_style='darker'
let g:equinusocio_material_vertsplit='visible'
colorscheme equinusocio_material
" ========================================================

" ========================================================
" gruvbox color scheme
" --------------------------------------------------------
" syntax on
" set termguicolors
" set background=dark
" colorscheme gruvbox
" highlight! EndOfBuffer ctermfg=235 ctermbg=NONE cterm=NONE guifg=#282828 guibg=NONE gui=NONE
" highlight! VertSplit ctermfg=235 ctermbg=NONE cterm=NONE guifg=#282828 guibg=NONE gui=NONE
" ========================================================

" augroup
augroup cmd_once
  autocmd!
augroup END

" custom settings
set mouse=a
set number
set laststatus=2
set encoding=utf-8
set backspace=indent,eol,start
set whichwrap+=<,>,h,l,[,]
set cursorline
set showtabline=2
set noshowmode
set fillchars+=vert:│
if has("clipboard")
  if has("mac")
    set clipboard=unnamed
  elseif has("unix")
    set clipboard=unnamedplus
  endif
endif

" disable beeping
set noerrorbells visualbell t_vb=
autocmd cmd_once GUIEnter * set visualbell t_vb=

" no automatically wrap
set textwidth=0
set wrapmargin=0
set wrap
set linebreak
set nolist

" simple gui
if has("gui_running")
  set guioptions-=m
  set guioptions-=T
  set guioptions-=r
  set guioptions-=L
  set guioptions-=e
  " disable all blinking
  set guicursor+=a:blinkon0
  if has("gui_macvim")
    set guifont=SF\ Mono:h12
  endif
endif

" performance config
set timeoutlen=1000 ttimeoutlen=0
set lazyredraw
set updatetime=250

" search
set ignorecase
set smartcase
set hlsearch
set incsearch

" ignore
set wildignore+=*~,*.swp,*.o,*.a,*.so,*.pyc,*.zip
set wildignore+=.DS_Store
set wildignore+=*/.git/*
set wildignore+=*/.hg/*
set wildignore+=*/.svn/*
set wildignore+=*/CVS/*
set wildignore+=*/.vscode/*
set wildignore+=*/tmp/*
set wildignore+=*/venv/*
set wildignore+=*/__pycache__/*
set wildignore+=*/.mypy_cache/*
set wildignore+=*/node_modules/*
set wildignore+=*/build/*
set wildignore+=*/target/*

" indentation for global
" indentation by 2 spaces
set expandtab
set softtabstop=2
set shiftwidth=2
set tabstop=8
set autoindent

" ---------------------------------------------------
" indentation
" ---------------------------------------------------
" cindent
autocmd cmd_once FileType c,cpp setlocal cindent
" indentation by 4 spaces
autocmd cmd_once FileType python setlocal expandtab softtabstop=4 shiftwidth=4 tabstop=8
" indentation by 2 spaces
" autocmd cmd_once BufNewFile,BufRead .clang-format setlocal expandtab softtabstop=2 shiftwidth=2 tabstop=8
autocmd cmd_once FileType meson setlocal expandtab softtabstop=2 shiftwidth=2 tabstop=8
" indentation by 1 tab
autocmd cmd_once FileType gitconfig,go setlocal noexpandtab softtabstop=0 shiftwidth=8 tabstop=8

" assumes all *.h files to be pure c/cxx code
autocmd cmd_once BufNewFile,BufRead *.cc,*.h setlocal filetype=cpp

" glsl
autocmd cmd_once BufNewFile,BufRead *.vs,*.fs setlocal filetype=glsl

" automatically remove all trailing whitespace before saving
" autocmd cmd_once FileType c,cpp,meson,json,python,ruby,cmake autocmd cmd_once BufWritePre <buffer> %s/\s\+$//e
" autocmd cmd_once BufWritePre * if &ft != "markdown" | %s/\s\+$//e | endif
autocmd cmd_once BufWritePre * %s/\s\+$//e
" ---------------------------------------------------

" key bindings
inoremap jj <Esc>
nnoremap ; :
nnoremap : ;
vnoremap ; :
vnoremap : ;
let mapleader = " "
nnoremap <Leader>q :bp<Bar>sp<Bar>bn<Bar>bd<CR>
nnoremap <Leader>w :Autoformat<CR>:wa<CR>
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
nnoremap <C-h> <C-w>h

" better python syntax
" let python_highlight_all = 1

" lightline
let g:lightline = {
  \ 'colorscheme': 'equinusocio_material',
  \ 'separator': { 'left': '', 'right': '' },
  \ 'subseparator': { 'left': '', 'right': '' }
  \ }
let g:lightline.tabline = {
  \ 'left': [ [ 'buffers' ] ],
  \ 'right': [ [ 'close' ] ],
  \ }
let g:lightline.component_expand = { 'buffers': 'lightline#bufferline#buffers' }
let g:lightline.component_type   = { 'buffers': 'tabsel' }
let g:lightline#bufferline#number_map = {
  \ '0': ' 0 ',
  \ '1': ' 1 ',
  \ '2': ' 2 ',
  \ '3': ' 3 ',
  \ '4': ' 4 ',
  \ '5': ' 5 ',
  \ '6': ' 6 ',
  \ '7': ' 7 ',
  \ '8': ' 8 ',
  \ '9': ' 9 '
  \ }
let g:lightline#bufferline#show_number = 2
let g:lightline#bufferline#shorten_path = 0
let g:lightline#bufferline#unnamed = '[No Name]'
nmap <Leader>1 <Plug>lightline#bufferline#go(1)
nmap <Leader>2 <Plug>lightline#bufferline#go(2)
nmap <Leader>3 <Plug>lightline#bufferline#go(3)
nmap <Leader>4 <Plug>lightline#bufferline#go(4)
nmap <Leader>5 <Plug>lightline#bufferline#go(5)
nmap <Leader>6 <Plug>lightline#bufferline#go(6)
nmap <Leader>7 <Plug>lightline#bufferline#go(7)
nmap <Leader>8 <Plug>lightline#bufferline#go(8)
nmap <Leader>9 <Plug>lightline#bufferline#go(9)
nmap <Leader>0 <Plug>lightline#bufferline#go(10)

" ycm
" python3 ./install.py --clang-completer
" cp ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/
" echo | clang -v -E -x c++ -
let g:ycm_global_ycm_extra_conf = expand('$HOME/.ycm_extra_conf.py')
let g:ycm_confirm_extra_conf = 0
let g:ycm_python_binary_path = 'python3'
let g:ycm_complete_in_comments = 1
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
" ['re!\w{2}']
let g:ycm_semantic_triggers = {
  \ 'c': ['re!\w{2}'],
  \ 'cpp': ['re!\w{2}'],
  \ 'python': ['re!\w{2}'],
  \ 'rust': ['re!\w{2}'],
  \ }
let g:ycm_extra_conf_globlist = ['!*/build/*', '!*/target/*']
" disable rls lsp
let g:ycm_language_server = [
  \ {
  \   'name': 'rust',
  \   'cmdline': [expand('$HOME/.cargo/bin/rls')],
  \   'filetypes': ['rust'],
  \   'project_root_files': ['Cargo.toml'],
  \ }
  \ ]
nnoremap <C-]> :YcmCompleter GoToImprecise<CR>

" ale
" only lint on save
let g:ale_lint_on_enter = 0
let g:ale_lint_on_filetype_changed = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 0
let g:ale_lint_on_insert_leave = 0
" linters
let g:ale_linters = {
  \ 'python': ['flake8'],
  \ 'rust': ['cargo'],
  \ }
let g:ale_linters_explicit = 1
let g:ale_python_flake8_options = '--ignore=E501'
" custom highlight
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'
" message line
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = 'ALE: [%linter%] %s [%severity%]'

" autoformat
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0
" c/cpp
let g:formatters_c = ['clangformat']
let g:formatters_cpp = ['clangformat']
" python
if !exists('g:formatdef_my_custom_autopep8')
  " let g:formatdef_my_custom_autopep8 = '"autopep8 -a -a -" . (g:DoesRangeEqualBuffer(a:firstline, a:lastline) ? " --line-range " . a:firstline . " " . a:lastline : "")'
  let g:formatdef_my_custom_autopep8 = '"autopep8 -a -a -"'
endif
let g:formatters_python = ['my_custom_autopep8']
" go
if !exists('g:formatdef_my_custom_gofmt')
  let g:formatdef_my_custom_gofmt = '"gofmt"'
endif
let g:formatters_go = ['my_custom_gofmt']
" rust
if !exists('g:formatdef_my_custom_rustfmt')
  let g:formatdef_my_custom_rustfmt = '"rustfmt"'
endif
let g:formatters_rust = ['my_custom_rustfmt']
nnoremap ƒ :Autoformat<CR>
nnoremap <F7> :Autoformat<CR>

" autopairs
autocmd cmd_once FileType vim let b:AutoPairs = {'(':')', '[':']', '{':'}', "'":"'", '`':'`'}
autocmd cmd_once FileType rust let b:AutoPairs = AutoPairsDefine({'\w\zs<': '>'})

" nerdtree
autocmd cmd_once StdinReadPre * let s:std_in=1
autocmd cmd_once VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
autocmd cmd_once BufEnter * nested if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let g:NERDTreeDirArrowExpandable = ''
let g:NERDTreeDirArrowCollapsible = ''
let g:NERDTreeShowHidden = 1
let g:NERDTreeRespectWildIgnore = 1
noremap <C-n> :NERDTreeToggle<CR>

" nerdcommenter
let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
let g:NERDCustomDelimiters = {
  \ 'c': {'left': '//'},
  \ 'cpp': {'left': '//'},
  \ }
let g:NERDCommentEmptyLines = 1
let g:NERDTrimTrailingWhitespace = 1
let g:NERDToggleCheckAllLines = 1

" tagbar
nnoremap <F8> :TagbarToggle<CR>

" ctrlp
" let g:ctrlp_map = '<c-p>'
" let g:ctrlp_cmd = 'CtrlP'
" let g:ctrlp_working_path_mode = 'ra'
" let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
" let g:ctrlp_show_hidden = 1
" let g:ctrlp_use_caching = 0
" let g:ctrlp_clear_cache_on_exit = 0
" if executable('rg')
"   set grepprg=rg\ --color=never
"   let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
" endif

" fzf
nnoremap <C-p> :Files<Cr>
nnoremap <C-g> :Rg<Cr>

很规范呀,基本无可挑剔了,不过 autocmd 建议还是要放到 augroup 里去。不然你重新载入 vimrc 时,这些自动命令又定义了一次。