2017-12-13 13:08:26 +00:00
|
|
|
|
2019-10-18 12:56:42 +00:00
|
|
|
" Function to source only if file exists {
|
|
|
|
function! SourceIfExists(file)
|
|
|
|
if filereadable(expand(a:file))
|
|
|
|
exe 'source' a:file
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
" }
|
|
|
|
|
2020-06-14 16:04:12 +00:00
|
|
|
let g:rc_files = {
|
2020-06-14 13:35:30 +00:00
|
|
|
\ 'early': '~/.config/vim/early.vimrc',
|
|
|
|
\ 'pre': '~/.config/vim/pre-plug.vimrc',
|
|
|
|
\ 'plug': '~/.config/vim/plug.vimrc',
|
|
|
|
\ 'post': '~/.config/vim/post-plug.vimrc',
|
2020-06-14 15:11:35 +00:00
|
|
|
\ 'late': '~/.config/vim/late.vimrc',
|
|
|
|
\ 'my': $MYVIMRC
|
2020-06-14 13:35:30 +00:00
|
|
|
\ }
|
|
|
|
|
|
|
|
" Edit source files
|
|
|
|
function! EditVimRcFiles()
|
2020-06-14 16:04:12 +00:00
|
|
|
for l:rc_key in keys(g:rc_files)
|
|
|
|
let l:ex_file = expand(g:rc_files[l:rc_key])
|
|
|
|
if filereadable(l:ex_file)
|
|
|
|
exe 'tabedit' l:ex_file
|
2020-06-14 13:35:30 +00:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2020-06-14 16:04:12 +00:00
|
|
|
call SourceIfExists(g:rc_files['early'])
|
2020-06-12 19:05:48 +00:00
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
" Hide buffers don't close them
|
|
|
|
set hidden
|
2020-07-11 14:59:08 +00:00
|
|
|
" set path+=**
|
2020-06-09 20:41:11 +00:00
|
|
|
|
|
|
|
" File indent opts
|
|
|
|
set shiftwidth=2
|
|
|
|
set tabstop=8
|
|
|
|
set softtabstop=2
|
|
|
|
set expandtab
|
2020-06-14 15:11:35 +00:00
|
|
|
set encoding=utf-8
|
2020-06-14 16:07:27 +00:00
|
|
|
set listchars=trail:▭,extends:↲,precedes:↱,nbsp:▂,tab:╙─╖
|
2020-06-14 15:11:35 +00:00
|
|
|
set list
|
2020-06-14 15:18:25 +00:00
|
|
|
set ignorecase
|
|
|
|
set infercase
|
2020-06-09 20:41:11 +00:00
|
|
|
filetype plugin indent on
|
|
|
|
|
|
|
|
" Set completion messages off
|
|
|
|
set shortmess+=c
|
|
|
|
|
|
|
|
" Preview window + menu for autocompletions
|
|
|
|
set completeopt+=preview
|
|
|
|
set completeopt+=menuone
|
|
|
|
set completeopt+=longest
|
|
|
|
|
|
|
|
" Lower update time (Default 4000)
|
|
|
|
set updatetime=300
|
|
|
|
|
|
|
|
" Always show the signcolumn, otherwise it would shift the text each time
|
|
|
|
" diagnostics appear/become resolved.
|
|
|
|
try
|
|
|
|
" Vim 8.2 only
|
|
|
|
set signcolumn=number
|
|
|
|
catch
|
|
|
|
set signcolumn=yes:1
|
|
|
|
endtry
|
|
|
|
set number
|
|
|
|
set relativenumber
|
2019-10-18 12:56:42 +00:00
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
if exists('+termguicolors')
|
|
|
|
set termguicolors
|
|
|
|
endif
|
2019-10-18 12:56:42 +00:00
|
|
|
|
2020-06-14 16:04:12 +00:00
|
|
|
exec "set rtp=$VIMHOME," . &rtp
|
2017-12-13 13:08:26 +00:00
|
|
|
|
2020-05-01 13:04:55 +00:00
|
|
|
" (Optional) Multi-entry selection UI.
|
|
|
|
|
2020-06-14 16:04:12 +00:00
|
|
|
call SourceIfExists(g:rc_files['pre'])
|
2018-05-02 12:51:32 +00:00
|
|
|
call plug#begin("$VIMHOME/plugged")
|
2020-06-14 15:11:35 +00:00
|
|
|
Plug 'junegunn/vim-easy-align'
|
2017-12-13 13:08:26 +00:00
|
|
|
Plug 'tpope/vim-sensible'
|
|
|
|
Plug 'tpope/vim-fugitive'
|
2020-06-09 20:41:11 +00:00
|
|
|
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
|
|
|
Plug 'Xuyuanp/nerdtree-git-plugin', { 'on': 'NERDTreeToggle' }
|
2017-12-13 13:08:26 +00:00
|
|
|
Plug 'scrooloose/syntastic'
|
|
|
|
Plug 'scrooloose/nerdcommenter'
|
|
|
|
Plug 'scrooloose/vim-statline'
|
|
|
|
Plug 'vim-perl/vim-perl', { 'for': 'perl', 'do': 'make clean carp dancer highlight-all-pragmas moose test-more try-tiny' }
|
2020-06-09 20:41:11 +00:00
|
|
|
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
|
|
|
|
Plug 'pearofducks/ansible-vim', { 'for': ['yaml', 'yml'] }
|
2019-01-15 11:36:11 +00:00
|
|
|
Plug 'luochen1990/rainbow'
|
2020-06-09 20:41:11 +00:00
|
|
|
Plug 'jremmen/vim-ripgrep', { 'on': ['Rg', 'RgRoot'] }
|
|
|
|
Plug 'junegunn/fzf', { 'on': ['FZF', '<Plug>fzf#run', '<Plug>fzf#wrap'] }
|
2020-05-01 13:04:55 +00:00
|
|
|
Plug 'sheerun/vim-polyglot'
|
2020-06-09 20:41:11 +00:00
|
|
|
Plug 'adelarsq/vim-matchit'
|
|
|
|
Plug 'vim-airline/vim-airline'
|
|
|
|
Plug 'vim-airline/vim-airline-themes'
|
|
|
|
Plug 'airblade/vim-gitgutter'
|
2020-06-14 15:11:35 +00:00
|
|
|
Plug 'rakr/vim-one'
|
|
|
|
Plug 'mox-mox/vim-localsearch'
|
2020-06-09 20:41:11 +00:00
|
|
|
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
|
2020-07-11 14:59:08 +00:00
|
|
|
Plug 'romainl/vim-cool'
|
|
|
|
Plug 'christoomey/vim-tmux-navigator', { 'on': ['TmuxNavigateLeft', 'TmuxNavigateDown', 'TmuxNavigateUp', 'TmuxNavigateRight', 'TmuxNavigatePrevious'] }
|
2020-06-14 16:04:12 +00:00
|
|
|
call SourceIfExists(g:rc_files['plug'])
|
2018-08-09 19:22:57 +00:00
|
|
|
if has('nvim')
|
|
|
|
Plug 'roxma/nvim-yarp'
|
|
|
|
Plug 'roxma/vim-hug-neovim-rpc'
|
|
|
|
endif
|
2017-12-13 13:08:26 +00:00
|
|
|
call plug#end()
|
2020-07-11 14:59:08 +00:00
|
|
|
|
2020-06-14 16:04:12 +00:00
|
|
|
call SourceIfExists(g:rc_files['post'])
|
2017-12-13 13:08:26 +00:00
|
|
|
|
|
|
|
execute ':silent !mkdir -p ~/.vimbackup'
|
|
|
|
|
2020-06-14 16:04:12 +00:00
|
|
|
set backupdir=~/.vimbackup
|
2017-12-13 13:08:26 +00:00
|
|
|
set directory=~/.vimbackup
|
|
|
|
set hlsearch
|
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
" Airline
|
2020-06-14 15:11:35 +00:00
|
|
|
" Airline replaces showmode
|
|
|
|
set noshowmode
|
2020-06-09 20:41:11 +00:00
|
|
|
let g:airline#extensions#branch#format = 2
|
|
|
|
let g:airline#extensions#branch#displayed_head_limit = 16
|
2020-06-14 15:11:35 +00:00
|
|
|
let g:airline#extensions#tabline#enabled = 1
|
|
|
|
let g:airline#extensions#tabline#left_alt_sep = '|'
|
|
|
|
let g:airline_powerline_fonts = 1
|
|
|
|
let g:airline_theme='one'
|
|
|
|
if !exists('g:airline_symbols')
|
|
|
|
let g:airline_symbols = {}
|
|
|
|
endif
|
2020-06-09 20:41:11 +00:00
|
|
|
|
2017-12-13 13:08:26 +00:00
|
|
|
" Commenting
|
|
|
|
let g:NERDSpaceDelims = 1
|
|
|
|
let g:NERDCompactSexyComs = 1
|
|
|
|
let g:NERDDefaultAlign = 'left'
|
|
|
|
let g:NERDCommentEmptyLines = 1
|
|
|
|
let g:NERDTrimTrailingWhitespace = 1
|
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
augroup PsoxNERDTree
|
|
|
|
autocmd!
|
|
|
|
" Autoquit if nerdtree is last open window
|
|
|
|
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
|
|
|
|
|
|
|
|
" Open nerdtree if opening a directory
|
|
|
|
autocmd StdinReadPre * let s:std_in=1
|
|
|
|
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
2017-12-13 13:08:26 +00:00
|
|
|
" Syntastic Settings
|
2020-06-09 20:41:11 +00:00
|
|
|
" Note that airline automatically configures these
|
2017-12-13 13:08:26 +00:00
|
|
|
let g:syntastic_always_populate_loc_list = 1
|
|
|
|
let g:syntastic_enable_signs = 1
|
|
|
|
let g:syntastic_auto_loc_list = 1
|
|
|
|
let g:syntastic_check_on_open = 1
|
|
|
|
let g:syntastic_check_on_wq = 0
|
|
|
|
" Syntastic enable specific checkers
|
|
|
|
let g:syntastic_enable_zsh_checker = 1
|
|
|
|
let g:syntastic_enable_bash_checker = 1
|
|
|
|
|
2019-09-11 09:09:50 +00:00
|
|
|
" ripgrep settings
|
2019-09-11 09:51:26 +00:00
|
|
|
let g:rg_highlight = 'true'
|
|
|
|
let g:rg_derive_root = 'true'
|
2019-09-11 09:09:50 +00:00
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
" Other
|
|
|
|
let g:rainbow_active = 1
|
|
|
|
augroup PsoxFileAutos
|
|
|
|
autocmd!
|
|
|
|
autocmd FileType rust let g:autofmt_autosave = 1
|
|
|
|
autocmd FileType yaml setlocal indentkeys-=<:> ts=8 sts=2 sw=2 expandtab
|
|
|
|
" Tidy nerdtree windiw
|
|
|
|
autocmd FileType nerdtree setlocal nocursorcolumn nonumber norelativenumber signcolumn=no
|
2020-07-11 14:59:08 +00:00
|
|
|
autocmd VimEnter *
|
|
|
|
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
|
|
|
|
\| PlugInstall --sync
|
|
|
|
\| q
|
|
|
|
\| colorscheme one
|
|
|
|
\| endif
|
2020-06-09 20:41:11 +00:00
|
|
|
augroup END
|
|
|
|
|
|
|
|
" Set bindings for coc.nvim
|
|
|
|
if has_key(plugs, 'coc.nvim')
|
2020-07-16 10:14:58 +00:00
|
|
|
if !exists("g:coc_global_extensions")
|
|
|
|
let g:coc_global_extensions=[]
|
|
|
|
endif
|
2020-07-11 14:59:08 +00:00
|
|
|
let g:coc_global_extensions+=[ 'coc-yank' ]
|
|
|
|
let g:coc_global_extensions+=[ 'coc-spell-checker' ]
|
|
|
|
let g:coc_global_extensions+=[ 'coc-actions' ]
|
|
|
|
let g:coc_global_extensions+=[ 'coc-vimlsp' ]
|
|
|
|
let g:coc_global_extensions+=[ 'coc-rust-analyzer' ]
|
|
|
|
let g:coc_global_extensions+=[ 'coc-json' ]
|
|
|
|
let g:coc_global_extensions+=[ 'coc-markdownlint' ]
|
|
|
|
let g:coc_global_extensions+=[ 'coc-yaml' ]
|
2020-06-09 20:41:11 +00:00
|
|
|
" Use tab for trigger completion with characters ahead and navigate.
|
|
|
|
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
|
|
|
|
" other plugin before putting this into your config.
|
2020-07-11 14:59:08 +00:00
|
|
|
inoremap <silent><expr> <TAB>
|
2020-06-09 20:41:11 +00:00
|
|
|
\ pumvisible() ? "\<C-n>" :
|
|
|
|
\ <SID>check_back_space() ? "\<TAB>" :
|
|
|
|
\ coc#refresh()
|
2020-07-11 14:59:08 +00:00
|
|
|
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
|
2020-06-09 20:41:11 +00:00
|
|
|
|
|
|
|
function! s:check_back_space() abort
|
|
|
|
let col = col('.') - 1
|
|
|
|
return !col || getline('.')[col - 1] =~# '\s'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Use <c-space> to trigger completion.
|
2020-07-11 14:59:08 +00:00
|
|
|
inoremap <silent><expr> <c-space> coc#refresh()
|
2020-06-09 20:41:11 +00:00
|
|
|
|
|
|
|
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
|
|
|
|
" position. Coc only does snippet and additional edit on confirm.
|
|
|
|
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
|
|
|
|
if exists('*complete_info')
|
2020-07-11 14:59:08 +00:00
|
|
|
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
|
2020-06-09 20:41:11 +00:00
|
|
|
else
|
2020-07-11 14:59:08 +00:00
|
|
|
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
|
2020-06-09 20:41:11 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
" Use `[g` and `]g` to navigate diagnostics
|
2020-07-11 14:59:08 +00:00
|
|
|
nmap <silent> [g <Plug>(coc-diagnostic-prev)
|
|
|
|
nmap <silent> ]g <Plug>(coc-diagnostic-next)
|
|
|
|
|
|
|
|
" Use K to show documentation in preview window.
|
|
|
|
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
|
2020-06-14 16:04:12 +00:00
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
" Remap for do codeAction of selected region
|
|
|
|
function! s:cocActionsOpenFromSelected(type) abort
|
|
|
|
execute 'CocCommand actions.open ' . a:type
|
|
|
|
endfunction
|
2020-07-11 14:59:08 +00:00
|
|
|
xmap <silent> <leader>a :<C-u>execute 'CocCommand actions.open ' . visualmode()<CR>
|
|
|
|
nmap <silent> <leader>a :<C-u>set operatorfunc=<SID>cocActionsOpenFromSelected<CR>g@
|
|
|
|
nmap <silent> <leader>. :CocCommand actions.open<CR>
|
|
|
|
|
|
|
|
nnoremap <silent> <C-Y> :<C-u>CocList -A --normal yank<CR>
|
|
|
|
endif
|
2020-06-09 20:41:11 +00:00
|
|
|
|
2020-07-11 14:59:08 +00:00
|
|
|
" Vim Tmux unified movement
|
|
|
|
if has_key(plugs, 'vim-tmux-navigator')
|
|
|
|
let g:tmux_navigator_no_mappings = 1
|
|
|
|
let g:tmux_navigator_disable_when_zoomed = 1
|
|
|
|
|
|
|
|
nnoremap <silent> <C-h> :TmuxNavigateLeft<cr>
|
|
|
|
nnoremap <silent> <C-j> :TmuxNavigateDown<cr>
|
|
|
|
nnoremap <silent> <C-k> :TmuxNavigateUp<cr>
|
|
|
|
nnoremap <silent> <C-l> :TmuxNavigateRight<cr>
|
2020-06-09 20:41:11 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
" NERDTree Toggle
|
|
|
|
nnoremap <F2> :NERDTreeToggle<CR>
|
|
|
|
|
2020-07-11 14:59:08 +00:00
|
|
|
" NERDComment settings
|
|
|
|
" nnoremap <silent> <C-/> :call NERDComment('n', 'toggle')<CR>
|
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
" Workaround for writing readonly files
|
2020-06-14 16:04:12 +00:00
|
|
|
cnoremap w!! w !sudo tee % > /dev/null
|
2020-06-09 20:41:11 +00:00
|
|
|
|
2020-06-14 15:11:35 +00:00
|
|
|
" Key Remapping
|
2020-06-14 16:04:12 +00:00
|
|
|
nnoremap <Leader>ve :call EditVimRcFiles()<cr>
|
2020-06-14 15:11:35 +00:00
|
|
|
nnoremap <Leader>vs :source $MYVIMRC<cr>
|
|
|
|
nmap <leader>/ <Plug>localsearch_toggle
|
|
|
|
|
2020-06-09 20:41:11 +00:00
|
|
|
" Toggles all gutter items
|
|
|
|
nnoremap <silent> <leader>N :call ToggleGutter()<CR>
|
|
|
|
|
|
|
|
function! ToggleGutter() abort
|
|
|
|
if &number
|
|
|
|
exec "set nonumber norelativenumber signcolumn=no"
|
|
|
|
else
|
|
|
|
exec "set number relativenumber"
|
|
|
|
try | set signcolumn=number | catch | set signcolumn=yes:1 | endtry
|
|
|
|
endif
|
|
|
|
endfunction
|
2019-10-18 12:56:42 +00:00
|
|
|
|
2020-06-14 15:11:35 +00:00
|
|
|
" Default colorscheme
|
2020-06-15 22:46:49 +00:00
|
|
|
let g:one_allow_italics=1
|
2020-06-14 15:11:35 +00:00
|
|
|
colorscheme one
|
2020-06-15 22:22:01 +00:00
|
|
|
highlight Comment cterm=italic gui=italic
|
2020-06-14 15:11:35 +00:00
|
|
|
|
2020-05-01 13:04:55 +00:00
|
|
|
set exrc
|
|
|
|
set secure
|
2018-06-14 13:58:34 +00:00
|
|
|
set modeline
|
|
|
|
set modelines=7
|
|
|
|
|
2020-06-14 16:04:12 +00:00
|
|
|
call SourceIfExists(g:rc_files['late'])
|
2017-12-13 13:08:26 +00:00
|
|
|
" vim: ts=8 sw=2 si
|