This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/nvim/init.vim

189 lines
3.8 KiB
VimL

call plug#begin(stdpath('data') . '/plugged')
Plug 'altercation/vim-colors-solarized'
Plug 'itchyny/lightline.vim'
Plug 'tpope/vim-obsession'
Plug 'dhruvasagar/vim-prosession'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'christoomey/vim-tmux-navigator'
Plug 'tpope/vim-dispatch'
Plug 'RRethy/vim-illuminate'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'Lenovsky/nuake'
Plug 'junegunn/vim-peekaboo'
Plug 'cespare/vim-toml'
Plug 'vimwiki/vimwiki'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" typescript syntax highlighting
Plug 'HerringtonDarkholme/yats.vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
call plug#end()
" tabwidth
set tabstop=4
set shiftwidth=4
" indent with spaces
set expandtab
" scroll offset
set scrolloff=4
" split to right/below
set splitright
set splitbelow
" presistent undo
set undofile
" solarized dark theme
silent! colorscheme solarized
set background=dark
" line numbers
set number
" searching
set ignorecase
set smartcase
" preview commands
set inccommand=split
" reload init.vim on save
augroup InitVimReload
autocmd!
autocmd BufWritePost init.vim source $MYVIMRC
augroup END
" set cursorline in active window
augroup CursorLine
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
augroup END
" terminal mode options
augroup terminal_mode
autocmd!
autocmd TermOpen * startinsert
augroup END
" map esc to exit insert mode in terminal
tnoremap <expr> <esc> (&filetype == "fzf") ? "<esc>" : "<c-\><c-n>"
" git-gutter
highlight SignColumn ctermbg=0
" lightline config
let g:lightline = { 'colorscheme': 'solarized' }
" prosession
let g:prosession_tmux_title = 1
let g:prosession_per_branch = 1
" fzf.vim
nnoremap <C-P> :GFiles<CR>
nnoremap <C-G> :Rg<CR>
nnoremap <C-F> :Rg \b<C-R><C-W>\b<CR>
" vim-illuminate
highlight illuminatedWord ctermbg=23
augroup close_preview
autocmd InsertLeave * silent! pclose!
augroup end
" autoread/checktime timer {{{
set autoread
function! CheckTime(timer)
checktime
endfunction
let timerChecktime = timer_start(4000, 'CheckTime', {'repeat': -1})
" }}}
" nuake console
nnoremap <F4> :Nuake<CR>
inoremap <F4> <C-\><C-n>:Nuake<CR>
tnoremap <F4> <C-\><C-n>:Nuake<CR>
augroup color_column
autocmd!
autocmd Filetype cpp,python,javascript,javascriptreact,typescript,typescriptreact set colorcolumn=101
augroup end
" vimwiki
let g:vimwiki_list = [
\ {'name': 'personal', 'path': '~/vimwiki/personal'},
\ {'name': 'swp', 'path': '~/vimwiki/swp'}
\ ]
let g:vimwiki_table_mappings = 0
let g:vimwiki_global_ext = 0
" coc
set updatetime=300
highlight CocHintSign ctermfg=10
let g:coc_global_extensions = [
\ 'coc-clangd',
\ 'coc-cmake',
\ 'coc-eslint',
\ 'coc-html',
\ 'coc-json',
\ 'coc-prettier',
\ 'coc-python',
\ 'coc-rust-analyzer',
\ 'coc-sh',
\ 'coc-toml',
\ 'coc-tsserver',
\ 'coc-vimlsp',
\ 'coc-yaml',
\ ]
nnoremap <silent> K :call CocAction('doHover')<CR>
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gr <Plug>(coc-references)
nmap <silent> ga <Plug>(coc-codeaction)
nmap <silent> <leader>rn <Plug>(coc-rename)
" use <tab> for trigger completion and navigate to the next complete item {{{
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <silent><expr> <S-Tab>
\ pumvisible() ? "\<C-p>" :
\ <SID>check_back_space() ? "\<S-Tab>" :
\ coc#refresh()
" }}}
" select completion items with enter
inoremap <silent><expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"