dotfiles/nvim.configlink/init.vim

258 lines
8.3 KiB
VimL
Raw Normal View History

2020-07-26 20:15:21 +00:00
" Vim Config
2020-08-02 02:33:54 +00:00
" Plugins
"--------
2020-08-02 02:29:33 +00:00
" Install vim-plugged if not installed
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
2020-08-02 02:33:54 +00:00
autocmd VimEnter * PlugInstall --sync | source ~/.config/nvim/init.vim
2020-08-02 02:29:33 +00:00
endif
2020-08-02 02:33:54 +00:00
" All plugins
2020-07-31 04:02:41 +00:00
call plug#begin('~/.config/nvim/plugged')
2020-08-02 02:29:33 +00:00
Plug 'morhetz/gruvbox' " Colorscheme
2020-07-31 04:02:41 +00:00
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Required for fuzzyfinder
Plug 'junegunn/fzf.vim' " Actual fuzzyfinder
2020-07-31 13:28:06 +00:00
Plug 'tpope/vim-surround' " Enables paren editing
Plug 'tpope/vim-commentary' " Use gc or gcc to comment
2020-08-02 00:06:16 +00:00
Plug 'sheerun/vim-polyglot' " Syntax for every language
Plug 'vimwiki/vimwiki' " Wiki Markdown System
2020-08-01 00:44:02 +00:00
Plug 'jreybert/vimagit' " Git 'gui' buffer
Plug 'airblade/vim-gitgutter' " Git next to line numbers
Plug 'tpope/vim-fugitive' " Other git commands
Plug 'machakann/vim-highlightedyank' " Highlight text when copied
Plug 'itchyny/lightline.vim' " Status bar
Plug 'tpope/vim-vinegar' " Fixes netrw file explorer
2020-08-02 02:29:33 +00:00
Plug 'lambdalisue/fern.vim' " File explorer / project drawer
2020-08-02 00:06:16 +00:00
Plug 'christoomey/vim-tmux-navigator' " Hotkeys for tmux panes
2020-08-02 02:29:33 +00:00
Plug 'neoclide/coc.nvim', {'branch': 'release'} " Code completion
2020-07-31 04:02:41 +00:00
call plug#end()
2020-08-02 00:06:16 +00:00
" Basic Settings
2020-07-31 04:02:41 +00:00
filetype plugin on " Load the plugin for current filetype (vimwiki)
2020-07-26 20:15:21 +00:00
syntax enable " Syntax highlighting
set termguicolors " Set to truecolor
colorscheme gruvbox " Installed in autoload/ and colors/
2020-08-02 00:06:16 +00:00
" Options
2020-08-02 14:19:57 +00:00
set hidden " Don't unload buffers when leaving them
2020-07-26 20:15:21 +00:00
set number " Show line numbers
set relativenumber " Relative numbers instead of absolute
2020-07-31 13:39:17 +00:00
set list " Reveal whitespace with ---
2020-07-26 20:15:21 +00:00
set expandtab " Tabs into spaces
2020-07-27 17:00:26 +00:00
set shiftwidth=4 " Amount to shift with > key
set softtabstop=4 " Amount to shift with TAB key
2020-07-26 20:15:21 +00:00
set ignorecase " Ignore case when searching
set smartcase " Check case when using capitals in search
set incsearch " Search while typing
2020-07-31 04:02:41 +00:00
set visualbell " No sounds
set scrolljump=1 " Scroll more than one line (or 1 line)
set scrolloff=3 " Margin of lines when scrolling
2020-08-02 00:06:16 +00:00
set pastetoggle=<F3> " Use F3 to enter paste mode
2020-07-27 17:00:26 +00:00
set clipboard+=unnamedplus " Uses system clipboard for yanking
2020-08-02 14:19:57 +00:00
set updatetime=300 " Faster diagnostics
2020-07-27 17:00:26 +00:00
2020-08-02 00:06:16 +00:00
" Neovim only
set inccommand=split " Live preview search and replace
2020-08-02 02:29:33 +00:00
" Mouse interaction / scrolling
set mouse=nv
2020-07-26 20:15:21 +00:00
" Remember last position
2020-06-03 14:31:58 +00:00
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
endif
2020-07-26 20:15:21 +00:00
" Better backup, swap and undo storage
set noswapfile " Instead of swaps, create backups (less annoying)
set backup " Easier to recover and more secure
set undofile " Keeps undos after quit
2020-07-31 04:02:41 +00:00
set backupdir=~/.config/nvim/dirs/backup
set undodir=~/.config/vim/dirs/undo
2020-07-26 20:15:21 +00:00
" Create backup directories if they don't exist
2020-06-03 14:31:58 +00:00
if !isdirectory(&backupdir)
call mkdir(&backupdir, "p")
endif
if !isdirectory(&undodir)
call mkdir(&undodir, "p")
endif
2020-08-02 00:06:16 +00:00
" Custom commands
command Vimrc edit ~/.config/nvim/init.vim " Edit .vimrc (this file)
" Custom Keybinds
"----------------
2020-08-01 13:46:48 +00:00
2020-07-31 13:28:06 +00:00
" Map the leader key
map <Space> <Leader>
2020-11-23 04:16:42 +00:00
" Jump to the next occurence of <> and replace it with insert mode
nnoremap <Leader><Space> /<><Esc>:noh<CR>c2l
2020-08-02 00:06:16 +00:00
"This unsets the `last search pattern` register by hitting return
nnoremap <silent> <CR> :noh<CR><CR>
2020-11-23 04:16:42 +00:00
" Replace all
nnoremap <Leader>S :%s//g<Left><Left>
2020-07-31 13:28:06 +00:00
" Jump to text in this directory
2020-08-01 00:44:02 +00:00
nnoremap <Leader>/ :Rg<CR>
2020-07-31 13:28:06 +00:00
2020-08-06 03:13:05 +00:00
" Quit vim
nnoremap <Leader>q :quit<cr>
" Save file
nnoremap <Leader>fs :write<cr>
2020-07-31 13:28:06 +00:00
" Open file in this directory
2020-08-02 14:19:57 +00:00
nnoremap <Leader>ff :Files<cr>
2020-07-31 13:28:06 +00:00
2020-08-02 02:29:33 +00:00
" Open a recent file
2020-08-02 14:19:57 +00:00
nnoremap <Leader>fr :History<cr>
2020-08-02 02:29:33 +00:00
2020-07-31 13:28:06 +00:00
" Switch between multiple open files
2020-08-02 14:19:57 +00:00
nnoremap <Leader>bb :Buffers<cr>
2020-07-31 13:28:06 +00:00
" Jump to text in this file
nnoremap <Leader>s :BLines<cr>
2020-08-01 00:44:02 +00:00
" Start Magit buffer
2020-08-02 14:19:57 +00:00
nnoremap <Leader>gs :Magit<cr>
2020-08-01 00:44:02 +00:00
" Toggle Git gutter (by line numbers)
nnoremap <Leader>` :GitGutterToggle<cr>
" Git push
2020-08-02 14:19:57 +00:00
nnoremap <Leader>gp :Git push<cr>
2020-08-01 00:44:02 +00:00
" Close all other splits
2020-08-02 14:19:57 +00:00
nnoremap <Leader>wm :only<cr>
2020-08-01 00:44:02 +00:00
" Open file tree
2020-11-25 22:56:17 +00:00
noremap <silent> <Leader>ft :Fern . -drawer -width=35 -toggle<CR><C-w>=
2020-06-03 14:31:58 +00:00
2020-08-02 14:19:57 +00:00
" CoC Settings
"-------------
let g:coc_global_extensions = ['coc-rust-analyzer', 'coc-pairs']
" Set tab to completion
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
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)
" 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
" Highlight the symbol and its references when holding the cursor.
" Uses updatetime for delay before showing info.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
2020-11-23 04:16:42 +00:00
" LaTeX Hotkeys
autocmd FileType tex inoremap ;bf \textbf{}<Esc>i
" Autocompile LaTeX on save
autocmd BufWritePost *.tex silent! execute "!pdflatex -output-directory=%:p:h % >/dev/null 2>&1" | redraw!
2020-08-02 00:06:16 +00:00
" Plugin Settings
"----------------
2020-08-01 00:44:02 +00:00
" Built-in explorer plugin
let g:netrw_liststyle = 3 " Change style to 'tree' view
let g:netrw_banner = 0 " Remove useless banner
let g:netrw_winsize = 15 " Explore window takes % of page
let g:netrw_browse_split = 4 " Open in previous window
2020-08-02 02:29:33 +00:00
let g:netrw_altv = 1 " Always split left
2020-08-01 00:44:02 +00:00
" Gitgutter plugin
2020-08-02 14:19:57 +00:00
let g:gitgutter_enabled = 1 " Enabled on start
2020-08-01 00:44:02 +00:00
2020-08-02 02:29:33 +00:00
" Polyglot syntax plugin
let g:terraform_fmt_on_save=1 " Formats with terraform plugin
2020-08-02 14:19:57 +00:00
let g:rustfmt_autosave = 1 " Formats with rust plugin
2020-07-31 04:02:41 +00:00
2020-08-02 02:29:33 +00:00
" VimWiki plugin
let g:vimwiki_list = [
\ {
\ 'path': $NOTES_PATH,
2020-08-02 02:29:33 +00:00
\ 'syntax': 'markdown',
2020-11-25 03:10:54 +00:00
\ 'index': 'home',
2020-08-02 02:29:33 +00:00
\ 'ext': '.md'
\ }
\ ]
2020-11-25 03:10:54 +00:00
let g:vimwiki_key_mappings =
\ {
\ 'all_maps': 1,
\ 'mouse': 1,
\ }
let g:vimwiki_auto_chdir = 1
2020-07-31 04:02:41 +00:00
2020-08-02 02:29:33 +00:00
" Lightline status bar plugin
2020-08-01 00:44:02 +00:00
let g:lightline = {
\ 'colorscheme': 'jellybeans',
\ 'active': {
\ 'right': [[ 'lineinfo' ]],
\ 'left': [[ 'mode', 'paste' ],
2020-08-02 14:19:57 +00:00
\ [ 'cocstatus', 'readonly', 'relativepath', 'gitbranch', 'modified' ]]
2020-08-01 00:44:02 +00:00
\ },
\ 'component_function': {
2020-08-02 14:19:57 +00:00
\ 'gitbranch': 'fugitive#head',
\ 'cocstatus': 'coc#status'
\ },
2020-08-01 00:44:02 +00:00
\ }
2020-08-02 14:19:57 +00:00
" Use autocmd to force lightline update.
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()