Last active
March 12, 2020 09:40
-
-
Save hengstchon/ea2752a9ec72f7f9b07a85e88d6f4ef0 to your computer and use it in GitHub Desktop.
My vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"======================================================================= | |
" Plugin | |
"======================================================================= | |
call plug#begin('~/.vim/plugged') | |
" colorscheme | |
Plug 'morhetz/gruvbox' | |
Plug 'sainnhe/gruvbox-material' | |
" statusline | |
Plug 'itchyny/lightline.vim' | |
" start page | |
Plug 'mhinz/vim-startify' | |
" icons | |
Plug 'ryanoasis/vim-devicons' | |
" file explorer | |
Plug 'scrooloose/nerdtree' | |
Plug 'tiagofumo/vim-nerdtree-syntax-highlight' | |
" search | |
Plug 'Yggdroot/LeaderF', { 'do': './install.sh' } | |
" show indent line | |
Plug 'Yggdroot/indentLine' | |
" HTML | |
Plug 'mattn/emmet-vim' | |
" comment | |
Plug 'preservim/nerdcommenter' | |
" auto pairs | |
Plug 'jiangmiao/auto-pairs' | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-repeat' | |
" pairs color | |
Plug 'luochen1990/rainbow' | |
" markdown | |
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } | |
" strip whitespace | |
Plug 'ntpeters/vim-better-whitespace' | |
" code format | |
Plug 'prettier/vim-prettier' | |
" JavaScript | |
Plug 'othree/yajs.vim' | |
Plug 'othree/es.next.syntax.vim' | |
Plug 'chemzqm/vim-jsx-improve' | |
" coc | |
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 'neoclide/coc-java', {'do': 'yarn install --frozen-lockfile'} | |
Plug 'neoclide/coc-json', {'do': 'yarn install --frozen-lockfile'} | |
" latex | |
Plug 'lervag/vimtex' | |
call plug#end() | |
"======================================================================= | |
" theme | |
"======================================================================= | |
syntax on | |
colorscheme gruvbox-material | |
set termguicolors | |
set background=dark | |
set t_Co=256 | |
"======================================================================= | |
" base | |
"======================================================================= | |
set nocompatible " don't bother with vi compatibility | |
set history=1000 | |
set autoread " reload files when changed on disk | |
set shortmess=atOI | |
set wildmenu | |
set noswapfile | |
set magic " for regular expressions turn magic on | |
set foldmethod=indent | |
set foldlevel=99 | |
set backspace=indent,eol,start | |
set mouse=a | |
if has("gui_macvim") | |
set macmeta " use option key as meta key | |
endif | |
"======================================================================= | |
" appearence | |
"======================================================================= | |
if has("gui_macvim") | |
set guifont=IosevkaNerdFontCompleteM-Medium:h14 | |
endif | |
set colorcolumn=280 " Highlight Column | |
set linebreak | |
set ruler " show the current row and column | |
set noshowmode | |
set number | |
set relativenumber | |
set showcmd " display incomplete commands | |
set showmode " display current modes | |
set showmatch " jump to matches when entering parentheses | |
set matchtime=2 " tenths of a second to show the matching parenthesis | |
set laststatus=2 | |
" set cursorcolumn " may affect the performance | |
set cursorline | |
set guioptions= | |
set formatoptions+=m " not wait until whitespace to wrap if value of Unicode > 255 | |
set formatoptions+=B " not add whitespace when merge two lines | |
"====================================================================== | |
" search | |
"====================================================================== | |
set hlsearch " highlight searches | |
set incsearch " do incremental searching, search as you type | |
set ignorecase " ignore case when searching | |
set smartcase " no ignorecase if Uppercase char present | |
nnoremap <CR> :noh<CR> | |
"====================================================================== | |
" indent and tab | |
"====================================================================== | |
set autoindent | |
set smartindent | |
set shiftwidth=2 | |
set tabstop=2 | |
set softtabstop=2 " insert mode tab and backspace use 2 spaces | |
set smarttab | |
set expandtab " expand tabs to spaces | |
set shiftround | |
"====================================================================== | |
" key mapping | |
"====================================================================== | |
let mapleader = "\<Space>" | |
nnoremap <m-s> :w<CR> | |
nnoremap <m-q> :q<CR> | |
noremap Y "+y | |
vnoremap < <gv | |
vnoremap > >gv | |
noremap H ^ | |
noremap L $ | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-l> <c-w>l | |
nnoremap <c-h> <c-w>h | |
noremap [b :bp<CR> | |
noremap ]b :bn<CR> | |
inoremap <m-h> <left> | |
inoremap <m-j> <down> | |
inoremap <m-k> <up> | |
inoremap <m-l> <right> | |
" <leader>+数字键 切换tab | |
noremap <silent><leader>1 1gt<cr> | |
noremap <silent><leader>2 2gt<cr> | |
noremap <silent><leader>3 3gt<cr> | |
noremap <silent><leader>4 4gt<cr> | |
noremap <silent><leader>5 5gt<cr> | |
noremap <silent><leader>6 6gt<cr> | |
noremap <silent><leader>7 7gt<cr> | |
noremap <silent><leader>8 8gt<cr> | |
noremap <silent><leader>9 9gt<cr> | |
noremap <silent><leader>0 10gt<cr> | |
" ALT+h/l 快速左右按单词移动(正常模式+插入模式) | |
noremap <m-h> b | |
noremap <m-l> w | |
inoremap <m-h> <c-left> | |
inoremap <m-l> <c-right> | |
" ALT+j/k 逻辑跳转下一行/上一行(按 wrap 逻辑换行进行跳转) | |
noremap <m-j> gj | |
noremap <m-k> gk | |
inoremap <m-j> <c-\><c-o>gj | |
inoremap <m-k> <c-\><c-o>gk | |
"====================================================================== | |
" filetype | |
"====================================================================== | |
" python | |
autocmd FileType python :set tabstop=4 shiftwidth=4 tabstop=4 | |
autocmd BufWinEnter *.py nnoremap <leader>r :w<CR>:!python3 %:p<CR> | |
" java | |
autocmd FileType java :set tabstop=4 shiftwidth=4 tabstop=4 | |
"====================================================================== | |
" plugins | |
"====================================================================== | |
" nerdtree | |
" ---------------------------------------------------------------------- | |
noremap <C-n> :NERDTreeToggle<CR> | |
" emmet-vim | |
" ---------------------------------------------------------------------- | |
let g:user_emmet_settings = { | |
\ 'javascript': { | |
\ 'extends': 'html', | |
\ 'empty_element_suffix': ' />', | |
\ 'snippets': { | |
\ 're': "import React from \"react\"", | |
\ 'f1' : "= (|) => {\n\t|\n}", | |
\ 'f2' : "= (|) => (\n\t|\n)", | |
\ } | |
\ }, | |
\} | |
" nerdcommenter | |
" ---------------------------------------------------------------------- | |
let g:NERDSpaceDelims = 1 | |
" rainbow | |
" ---------------------------------------------------------------------- | |
let g:rainbow_active = 1 | |
let g:rainbow_conf = { | |
\ 'guifgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], | |
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], | |
\ 'separately': { | |
\ 'nerdtree': 0 | |
\ } | |
\} | |
" markdown-preview | |
" ---------------------------------------------------------------------- | |
nmap <C-p> <Plug>MarkdownPreview | |
" vim-prettier | |
" ---------------------------------------------------------------------- | |
let g:prettier#quickfix_enabled = 0 | |
let g:prettier#config#bracket_spacing = 'true' | |
" lightline.vim | |
" ---------------------------------------------------------------------- | |
function! CocCurrentFunction() | |
return get(b:, 'coc_current_function', '') | |
endfunction | |
let g:lightline = { | |
\ 'active': { | |
\ 'left': [ [ 'mode', 'paste' ], | |
\ [ 'cocstatus', 'currentfunction', 'readonly', 'filename', 'modified' ] ] | |
\ }, | |
\ 'component_function': { | |
\ 'cocstatus': 'coc#status', | |
\ 'currentfunction': 'CocCurrentFunction' | |
\ }, | |
\ } | |
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update() | |
" vimtex | |
" ---------------------------------------------------------------------- | |
let g:vimtex_view_method = 'skim' | |
" indentLine | |
" ---------------------------------------------------------------------- | |
let g:indentLine_fileTypeExclude = ['json'] | |
" LeaderF | |
" ---------------------------------------------------------------------- | |
let g:Lf_MruFileExclude = ['*.so', '*.exe', '*.py[co]', '*.sw?', '~$*', '*.bak', '*.tmp', '*.dll'] | |
let g:Lf_WindowPosition = 'popup' | |
let g:Lf_PreviewInPopup = 1 | |
let g:Lf_ShortcutF = "<leader>f" | |
noremap <leader>b :<C-U><C-R>=printf("Leaderf buffer %s", "")<CR><CR> | |
noremap <C-B> :<C-U><C-R>=printf("Leaderf! rg --current-buffer -e %s ", expand("<cword>"))<CR> | |
noremap <C-F> :<C-U><C-R>=printf("Leaderf! rg -e %s ", expand("<cword>"))<CR> | |
" 使用 ESC 键可以直接退出 leaderf 的 normal 模式 | |
let g:Lf_NormalMap = { | |
\ "File": [["<ESC>", ':exec g:Lf_py "fileExplManager.quit()"<CR>']], | |
\ "Buffer": [["<ESC>", ':exec g:Lf_py "bufExplManager.quit()"<cr>']], | |
\ "Mru": [["<ESC>", ':exec g:Lf_py "mruExplManager.quit()"<cr>']], | |
\ "Tag": [["<ESC>", ':exec g:Lf_py "tagExplManager.quit()"<cr>']], | |
\ "BufTag": [["<ESC>", ':exec g:Lf_py "bufTagExplManager.quit()"<cr>']], | |
\ "Function": [["<ESC>", ':exec g:Lf_py "functionExplManager.quit()"<cr>']], | |
\ } | |
" coc | |
" ---------------------------------------------------------------------- | |
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | |
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | |
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
" show suggest | |
inoremap <silent><expr> <c-k> coc#refresh() | |
" navigate diagnostic | |
nmap <silent> [g <Plug>(coc-diagnostic-prev) | |
nmap <silent> ]g <Plug>(coc-diagnostic-next) | |
nmap <silent> gd <Plug>(coc-definition) | |
nmap <silent> gy <Plug>(coc-type-definition) | |
nmap <silent> gi <Plug>(coc-implementation) | |
nmap <silent> gr <Plug>(coc-references) | |
nnoremap <silent> K :call <SID>show_documentation()<CR> | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
else | |
call CocAction('doHover') | |
endif | |
endfunction | |
" Show all diagnostics | |
nnoremap <silent> <space>e :<C-u>CocList diagnostics<cr> | |
" Use `:F` to format current buffer | |
command! -nargs=0 F :call CocAction('format') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment