Last active
December 26, 2021 00:32
-
-
Save hengstchon/e130137381c552d0553e944c5e4206ec to your computer and use it in GitHub Desktop.
init.vim
This file contains hidden or 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
" auto-install vim-plug | |
if empty(glob('~/.config/nvim/autoload/plug.vim')) | |
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs | |
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
autocmd VimEnter * PlugInstall | source $MYVIMRC | |
endif | |
"======================================================================= | |
" Plugin | |
"======================================================================= | |
call plug#begin(expand('~/.config/nvim/plugged')) | |
Plug 'sainnhe/gruvbox-material' " colorscheme | |
Plug 'itchyny/lightline.vim' " statusline | |
Plug 'ryanoasis/vim-devicons' " icons | |
Plug 'scrooloose/nerdtree' " file explorer | |
Plug 'tiagofumo/vim-nerdtree-syntax-highlight' | |
Plug 'preservim/nerdcommenter' " comment | |
Plug 'Yggdroot/indentLine' " show indent line | |
Plug 'machakann/vim-sandwich' " surrouding | |
Plug 'jiangmiao/auto-pairs' | |
Plug 'luochen1990/rainbow' " pairs color | |
Plug 'ntpeters/vim-better-whitespace' " strip whitespace | |
Plug 'mattn/emmet-vim' | |
Plug 'Yggdroot/LeaderF', { 'do': './install.sh' } " search | |
Plug 'tpope/vim-fugitive' " git | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} " coc | |
Plug 'honza/vim-snippets', | |
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } | |
Plug 'lervag/vimtex' " latex | |
Plug 'chemzqm/wxapp.vim' " wxapp | |
Plug 'yuezk/vim-js' | |
Plug 'maxmellon/vim-jsx-pretty' | |
Plug 'leafgarland/typescript-vim' | |
Plug 'peitalin/vim-jsx-typescript' | |
Plug 'brglng/vim-im-select' | |
call plug#end() | |
"======================================================================= | |
" general config | |
"======================================================================= | |
" theme | |
" ---------------------------------------------------------------------- | |
" colorscheme gruvbox | |
set termguicolors | |
set t_Co=256 | |
colorscheme gruvbox-material | |
" base | |
" ---------------------------------------------------------------------- | |
set history=1000 | |
set shortmess+=c | |
set noswapfile | |
set foldmethod=indent | |
set foldlevel=99 | |
set mouse=a | |
set colorcolumn=280 " highlight column | |
set linebreak | |
set number | |
set relativenumber | |
set showcmd " display incomplete commands | |
set noshowmode " not display current modes | |
set showmatch " jump to matches when entering parentheses | |
set smartindent | |
set shiftwidth=2 | |
set tabstop=2 | |
set softtabstop=2 " insert mode tab and backspace use 2 spaces | |
set expandtab " expand tabs to spaces | |
set shiftround | |
set ignorecase " ignore case when searching | |
set smartcase " no ignorecase if Uppercase char present | |
set lazyredraw | |
" key mapping | |
" ---------------------------------------------------------------------- | |
let mapleader = "\<Space>" | |
nnoremap <silent><leader><CR> :noh<CR> | |
noremap Y "+y | |
nnoremap <m-w> :w<CR> | |
nnoremap <m-q> :q<CR> | |
vnoremap < <gv | |
vnoremap > >gv | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-l> <c-w>l | |
nnoremap <c-h> <c-w>h | |
" jump to previous buffer and next buffer | |
noremap [b :bp<CR> | |
noremap ]b :bn<CR> | |
" <leader>+number: change tab | |
noremap <silent><leader>1 1gt<cr> | |
noremap <silent><leader>2 2gt<cr> | |
noremap <silent><leader>3 3gt<cr> | |
" Resize splits with arrow keys | |
noremap <up> :res +5<CR> | |
noremap <down> :res -5<CR> | |
noremap <left> :vertical resize-5<CR> | |
noremap <right> :vertical resize+5<CR> | |
" fix syntax | |
noremap <F3> <Esc>:syntax sync fromstart<CR> | |
" escape temrinal | |
:tnoremap <Esc> <C-\><C-n> | |
" filetype | |
" ---------------------------------------------------------------------- | |
autocmd FileType python :set tabstop=4 shiftwidth=4 softtabstop=4 | |
autocmd FileType java :set tabstop=4 shiftwidth=4 softtabstop=4 | |
autocmd BufWinEnter *.py nnoremap <leader>r :w<CR>:!python3 %:p<CR> | |
autocmd BufWinEnter *.rs nnoremap <leader>r :w<CR>:!cargo run<CR> | |
" autocmd BufWinEnter *.java nnoremap <leader>r :w<CR>:!javac % && java %:r<CR> | |
autocmd BufWinEnter *.java nnoremap <leader>r :w<CR>:!javac %:~:. && java %:~:.:r<CR> | |
"====================================================================== | |
" plugins configurations | |
"====================================================================== | |
" nerdtree | |
" ---------------------------------------------------------------------- | |
noremap <C-n> :NERDTreeToggle<CR> | |
noremap <leader>n :NERDTreeFind<CR> | |
" auto-pairs | |
" ---------------------------------------------------------------------- | |
let g:AutoPairsFlyMode = 1 | |
" nerdcommenter | |
" ---------------------------------------------------------------------- | |
let g:NERDSpaceDelims = 1 | |
let g:NERDTrimTrailingWhitespace = 1 | |
let g:NERDDefaultAlign = 'left' | |
let g:NERDToggleCheckAllLines = 1 | |
" vue comment | |
let g:ft = '' | |
function! 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 | |
exe 'setf ' . tolower(syn) | |
endif | |
else | |
exe 'setf html' | |
endif | |
endif | |
endfunction | |
function! NERDCommenter_after() | |
if g:ft == 'vue' | |
setf vue | |
let g:ft = '' | |
endif | |
endfunction | |
" rainbow | |
" ---------------------------------------------------------------------- | |
let g:rainbow_active = 1 | |
let g:rainbow_conf = { | |
\ 'guifgs': ['#5dbbc7', '#86bf6d', '#d4c772', '#d4948c', '#c182c2', '#9172cf'], | |
\ 'separately': { | |
\ 'nerdtree': 0 | |
\ } | |
\} | |
" markdown-preview | |
" ---------------------------------------------------------------------- | |
nmap <C-p> <Plug>MarkdownPreview | |
" lightline.vim | |
" ---------------------------------------------------------------------- | |
function! CocCurrentFunction() abort | |
return get(b:, 'coc_current_function', '') | |
endfunction | |
function! LightlineCocGit() abort | |
return get(g:, 'coc_git_status', '') .. get(b:, 'coc_git_status', '') | |
endfunction | |
let g:lightline = { | |
\ 'colorscheme': 'gruvbox_material', | |
\ 'active': { | |
\ 'left': [ [ 'mode', 'paste' ], | |
\ ['cocgit', 'cocstatus', 'readonly', 'filename', 'modified'] ] | |
\ }, | |
\ 'component_function': { | |
\ 'cocgit': 'LightlineCocGit', | |
\ 'cocstatus': 'coc#status', | |
\ }, | |
\ } | |
" vimtex | |
" ---------------------------------------------------------------------- | |
" set filetype of all files with tex suffix as tex, see :h vimtex-comment-internal | |
let g:tex_flavor = 'latex' | |
let g:vimtex_view_method = 'skim' | |
" let g:vimtex_view_skim_activate = 1 | |
" let g:vimtex_compiler_progname='nvr' | |
" fugitive | |
" ---------------------------------------------------------------------- | |
nmap <leader>d :Gdiffsplit<CR> | |
" LeaderF | |
" ---------------------------------------------------------------------- | |
let g:Lf_HideHelp = 1 | |
let g:Lf_UseCache = 0 | |
let g:Lf_UseVersionControlTool = 0 | |
let g:Lf_PreviewInPopup = 1 | |
let g:Lf_ShowHidden = 1 | |
let g:Lf_WindowPosition = 'popup' | |
noremap <leader>m :<C-U><C-R>=printf("Leaderf mru %s", "")<CR><CR> | |
noremap <leader>l :<C-U><C-R>=printf("Leaderf line %s", "")<CR><CR> | |
noremap <m-f> :<C-U><C-R>=printf("Leaderf! rg -e ")<CR> | |
noremap <m-s> :<C-U><C-R>=printf("Leaderf! rg -e %s ", expand("<cword>"))<CR> | |
noremap <m-c> :<C-U><C-R>=printf("Leaderf! rg --current-buffer -e %s ", expand("<cword>"))<CR> | |
noremap go :<C-U>Leaderf! --recall<CR> | |
" ignore files and directories | |
let g:Lf_WildIgnore = { | |
\ 'dir': ['.git', 'node_modules'], | |
\ 'file': ['*.sw?','~$*','*.bak','*.exe','*.o','*.so','*.py[co]'] | |
\} | |
" coc | |
" ---------------------------------------------------------------------- | |
let g:coc_global_extensions = [ | |
\ 'coc-highlight', | |
\ 'coc-yank', | |
\ 'coc-snippets', | |
\ 'coc-prettier', | |
\ 'coc-git', | |
\ 'coc-pyright', | |
\ 'coc-tsserver', | |
\ 'coc-html', | |
\ 'coc-css', | |
\ 'coc-json', | |
\ 'coc-vetur', | |
\ 'coc-eslint', | |
\ 'coc-go', | |
\ 'coc-rust-analyzer', | |
\ 'https://github.com/rodrigore/coc-tailwind-intellisense', | |
\] | |
" \ 'coc-java', | |
set hidden | |
set updatetime=100 | |
set signcolumn=yes | |
inoremap <silent><expr> <TAB> | |
\ pumvisible() ? "\<C-n>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" | |
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" | |
function! s:check_back_space() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~# '\s' | |
endfunction | |
" show suggest | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Make <CR> auto-select the first completion item and notify coc.nvim to | |
" format on enter, <cr> could be remapped by other vim plugin | |
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() | |
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
" 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) | |
" `K` to Show documents in vim | |
nnoremap <silent> K :call <SID>show_documentation()<CR> | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
elseif (coc#rpc#ready()) | |
call CocActionAsync('doHover') | |
else | |
execute '!' . &keywordprg . " " . expand('<cword>') | |
endif | |
endfunction | |
" Add `:F` command to format current buffer. | |
command! -nargs=0 F :call CocAction('format') | |
" Add `:OR` command for organize imports of the current buffer. | |
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') | |
" rename | |
nmap <leader>rn <Plug>(coc-rename) | |
" Apply AutoFix to problem on the current line. | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Map function and class text objects | |
" NOTE: Requires 'textDocument.documentSymbol' support from the language server. | |
xmap if <Plug>(coc-funcobj-i) | |
omap if <Plug>(coc-funcobj-i) | |
xmap af <Plug>(coc-funcobj-a) | |
omap af <Plug>(coc-funcobj-a) | |
xmap ic <Plug>(coc-classobj-i) | |
omap ic <Plug>(coc-classobj-i) | |
xmap ac <Plug>(coc-classobj-a) | |
omap ac <Plug>(coc-classobj-a) | |
" Mappings for CoCList | |
" Show all diagnostics. | |
nnoremap <silent><nowait> <leader>a :<C-u>CocList diagnostics<cr> | |
" Manage extensions. | |
nnoremap <silent><nowait> <leader>e :<C-u>CocList extensions<cr> | |
" Show commands. | |
nnoremap <silent><nowait> <leader>h :<C-u>CocList commands<cr> | |
" Find symbol of current document. | |
nnoremap <silent><nowait> <leader>o :<C-u>CocList outline<cr> | |
" Search workspace symbols. | |
nnoremap <silent><nowait> <leader>s :<C-u>CocList -I symbols<cr> | |
" Do default action for next item. | |
nnoremap <silent><nowait> <leader>j :<C-u>CocNext<CR> | |
" Do default action for previous item. | |
nnoremap <silent><nowait> <leader>k :<C-u>CocPrev<CR> | |
" Resume latest coc list. | |
nnoremap <silent><nowait> <leader>p :<C-u>CocListResume<CR> | |
" coc-snippets | |
vmap <C-j> <Plug>(coc-snippets-select) | |
" Use <C-l> for trigger snippet expand. | |
imap <C-l> <Plug>(coc-snippets-expand) | |
" Use <C-j> for both expand and jump (make expand higher priority.) | |
imap <C-j> <Plug>(coc-snippets-expand-jump) | |
" coc-highlight | |
autocmd CursorHold * silent call CocActionAsync('highlight') | |
autocmd BufWinEnter * highlight CocHighlightText ctermbg=239 guibg=#4e4e4e | |
" coc-yank | |
nnoremap <silent> <leader>y :<C-u>CocList -A --normal yank<cr> | |
" coc-git | |
" navigate chunks of current buffer | |
nmap [c <Plug>(coc-git-prevchunk) | |
nmap ]c <Plug>(coc-git-nextchunk) | |
" coc multiple cursors | |
nmap <silent> <C-c> <Plug>(coc-cursors-position) | |
nmap <silent> <C-d> <Plug>(coc-cursors-word) | |
xmap <silent> <C-d> <Plug>(coc-cursors-range) | |
" use normal command like `<leader>xi(` | |
nmap <leader>x <Plug>(coc-cursors-operator) | |
hi CocCursorRange guibg=#b16286 guifg=#ebdbb2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment