dotfiles/nvim.configlink/init.vim

280 lines
8.6 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')
2021-04-10 15:56:38 +00:00
" Core plugins
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
2021-04-10 15:56:38 +00:00
Plug 'sheerun/vim-polyglot' " Syntax for every language
Plug 'airblade/vim-gitgutter' " Git next to line numbers
2020-07-31 13:28:06 +00:00
Plug 'tpope/vim-commentary' " Use gc or gcc to comment
2021-04-10 15:56:38 +00:00
Plug 'godlygeek/tabular' " Spacing and alignment
" Ancillary plugins
2021-03-10 16:41:29 +00:00
Plug 'unblevable/quick-scope' " Hints for f and t
2020-08-02 00:06:16 +00:00
Plug 'vimwiki/vimwiki' " Wiki Markdown System
2020-08-01 00:44:02 +00:00
Plug 'jreybert/vimagit' " Git 'gui' buffer
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
2021-04-10 15:56:38 +00:00
2021-04-10 17:15:19 +00:00
" CoC (Language Server Protocol, requires NodeJS)
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-12-07 00:24:26 +00:00
filetype plugin on " Load the plugin for current filetype (vimwiki)
syntax enable " Syntax highlighting
set termguicolors " Set to truecolor
colorscheme gruvbox " Installed in autoload/ and colors/
2020-07-26 20:15:21 +00:00
2020-08-02 00:06:16 +00:00
" Options
2020-12-07 00:24:26 +00:00
set hidden " Don't unload buffers when leaving them
set number " Show line numbers
set relativenumber " Relative numbers instead of absolute
set list " Reveal whitespace with ---
set expandtab " Tabs into spaces
set shiftwidth=4 " Amount to shift with > key
2021-04-10 17:15:19 +00:00
set softtabstop=4 " Amount to shift with <TAB> key
2020-12-07 00:24:26 +00:00
set ignorecase " Ignore case when searching
set smartcase " Check case when using capitals in search
set incsearch " Search while typing
set visualbell " No sounds
set scrolljump=1 " Scroll more than one line (or 1 line)
2021-04-10 17:15:19 +00:00
set scrolloff=3 " Margin of lines when to start scrolling
set pastetoggle=<F3> " Use F3 to enter raw paste mode
2020-12-07 00:24:26 +00:00
set clipboard+=unnamedplus " Uses system clipboard for yanking
set updatetime=300 " Faster diagnostics
2021-04-10 17:15:19 +00:00
set mouse=nv " Mouse interaction / scrolling
2020-07-27 17:00:26 +00:00
2020-08-02 00:06:16 +00:00
" Neovim only
2021-04-10 17:15:19 +00:00
set inccommand=split " Live preview search and replace
2020-08-02 00:06:16 +00:00
2021-04-10 17:15:19 +00:00
" Remember last position when reopening file
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
2020-12-07 00:24:26 +00:00
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
2021-04-10 17:15:19 +00:00
set undodir=~/.config/nvim/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
2021-04-10 17:15:19 +00:00
" Custom Commands
"----------------
2020-08-02 00:06:16 +00:00
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-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>
2021-04-10 17:15:19 +00:00
" Make file executable
nnoremap <silent> <Leader>fe :!chmod 755 %<cr><cr>
" Make file normal permissions
nnoremap <silent> <Leader>fn :!chmod 644 %<cr><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
" Change directory to this file
nnoremap <silent> <Leader>fd :lcd %:p:h<cr>
" Back up directory
nnoremap <silent> <Leader>fu :lcd ..<cr>
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
2021-04-10 15:56:38 +00:00
" Split window
nnoremap <Leader>ws :vsplit<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
2021-04-10 15:56:38 +00:00
" LaTeX Settings
"---------------
2020-11-23 04:16:42 +00:00
" LaTeX Hotkeys
autocmd FileType tex inoremap ;bf \textbf{}<Esc>i
" Jump to the next occurence of <> and replace it with insert mode
autocmd FileType tex nnoremap <Leader><Space> /<><Esc>:noh<CR>c2l
2020-11-23 04:16:42 +00:00
" 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
2021-04-10 17:15:19 +00:00
" Built-in file explorer plugin
2021-04-10 15:56:38 +00:00
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
let g:netrw_altv = 1 " Always split left
2020-08-02 02:29:33 +00:00
2020-08-01 00:44:02 +00:00
" Gitgutter plugin
2021-04-10 15:56:38 +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
2021-04-10 15:56:38 +00:00
let g:terraform_fmt_on_save=1 " Formats with terraform plugin
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
2021-03-10 16:41:29 +00:00
" Quickscope only highlight on keypress
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
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
2021-04-10 17:15:19 +00:00
" CoC Settings
"-------------
" Extensions to auto-install and enable
let g:coc_global_extensions = [
\ 'coc-rust-analyzer',
\ 'coc-pairs',
\ 'coc-diagnostic',
\ ]
" 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)
" 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-08-02 14:19:57 +00:00
" Use autocmd to force lightline update.
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()