" Vim Config " Plugins "-------- " 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 autocmd VimEnter * PlugInstall --sync | source ~/.config/nvim/init.vim endif " All plugins call plug#begin('~/.config/nvim/plugged') Plug 'morhetz/gruvbox' " Colorscheme Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Required for fuzzyfinder Plug 'junegunn/fzf.vim' " Actual fuzzyfinder Plug 'tpope/vim-surround' " Enables paren editing Plug 'tpope/vim-commentary' " Use gc or gcc to comment Plug 'sheerun/vim-polyglot' " Syntax for every language Plug 'vimwiki/vimwiki' " Wiki Markdown System 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 Plug 'lambdalisue/fern.vim' " File explorer / project drawer Plug 'christoomey/vim-tmux-navigator' " Hotkeys for tmux panes Plug 'neoclide/coc.nvim', {'branch': 'release'} " Code completion call plug#end() " Basic Settings 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/ " Options 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 set softtabstop=4 " Amount to shift with TAB key 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) set scrolloff=3 " Margin of lines when scrolling set pastetoggle= " Use F3 to enter paste mode set clipboard+=unnamedplus " Uses system clipboard for yanking set updatetime=300 " Faster diagnostics " Neovim only set inccommand=split " Live preview search and replace " Mouse interaction / scrolling set mouse=nv " Remember last position if has("autocmd") au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif endif " 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 set backupdir=~/.config/nvim/dirs/backup set undodir=~/.config/vim/dirs/undo " Create backup directories if they don't exist if !isdirectory(&backupdir) call mkdir(&backupdir, "p") endif if !isdirectory(&undodir) call mkdir(&undodir, "p") endif " Custom commands command Vimrc edit ~/.config/nvim/init.vim " Edit .vimrc (this file) " Custom Keybinds "---------------- " Map the leader key map " Jump to the next occurence of <> and replace it with insert mode nnoremap /<>:nohc2l "This unsets the `last search pattern` register by hitting return nnoremap :noh " Replace all nnoremap S :%s//g " Jump to text in this directory nnoremap / :Rg " Quit vim nnoremap q :quit " Save file nnoremap fs :write " Open file in this directory nnoremap ff :Files " Open a recent file nnoremap fr :History " Switch between multiple open files nnoremap bb :Buffers " Jump to text in this file nnoremap s :BLines " Start Magit buffer nnoremap gs :Magit " Toggle Git gutter (by line numbers) nnoremap ` :GitGutterToggle " Git push nnoremap gp :Git push " Close all other splits nnoremap wm :only " Open file tree noremap t :Fern . -drawer -width=35 -toggle= " CoC Settings "------------- let g:coc_global_extensions = ['coc-rust-analyzer', 'coc-pairs'] " Set tab to completion inoremap \ pumvisible() ? "\" : \ check_back_space() ? "\" : \ coc#refresh() inoremap pumvisible() ? "\" : "\" function! s:check_back_space() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction inoremap pumvisible() ? coc#_select_confirm() \: "\u\\=coc#on_enter()\" " Use `[g` and `]g` to navigate diagnostics " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. nmap [g (coc-diagnostic-prev) nmap ]g (coc-diagnostic-next) " GoTo code navigation. nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) " Use K to show documentation in preview window. nnoremap K :call show_documentation() function! s:show_documentation() if (index(['vim','help'], &filetype) >= 0) execute 'h '.expand('') 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 rn (coc-rename) " Applying codeAction to the selected region. " Example: `aap` for current paragraph xmap a (coc-codeaction-selected) nmap a (coc-codeaction-selected) " Remap keys for applying codeAction to the current buffer. nmap ac (coc-codeaction) " Apply AutoFix to problem on the current line. nmap qf (coc-fix-current) " Use CTRL-S for selections ranges. " Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver nmap (coc-range-select) xmap (coc-range-select) " LaTeX Hotkeys autocmd FileType tex inoremap ;bf \textbf{}i " Autocompile LaTeX on save autocmd BufWritePost *.tex silent! execute "!pdflatex -output-directory=%:p:h % >/dev/null 2>&1" | redraw! " Plugin Settings "---------------- " 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 let g:netrw_altv = 1 " Always split left " Gitgutter plugin let g:gitgutter_enabled = 1 " Enabled on start " Polyglot syntax plugin let g:terraform_fmt_on_save=1 " Formats with terraform plugin let g:rustfmt_autosave = 1 " Formats with rust plugin " VimWiki plugin let g:vimwiki_list = [ \ { \ 'path': $NOTES_PATH, \ 'syntax': 'markdown', \ 'index': 'home', \ 'ext': '.md' \ } \ ] let g:vimwiki_key_mappings = \ { \ 'all_maps': 1, \ 'mouse': 1, \ } let g:vimwiki_auto_chdir = 1 " Lightline status bar plugin let g:lightline = { \ 'colorscheme': 'jellybeans', \ 'active': { \ 'right': [[ 'lineinfo' ]], \ 'left': [[ 'mode', 'paste' ], \ [ 'cocstatus', 'readonly', 'relativepath', 'gitbranch', 'modified' ]] \ }, \ 'component_function': { \ 'gitbranch': 'fugitive#head', \ 'cocstatus': 'coc#status' \ }, \ } " Use autocmd to force lightline update. autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()