init.vim (7609B)
1 let mapleader ="," 2 3 if ! filereadable(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"')) 4 echo "Downloading junegunn/vim-plug to manage plugins..." 5 silent !mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/ 6 silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim 7 autocmd VimEnter * PlugInstall 8 endif 9 10 map ,, :keepp /<++><CR>ca< 11 imap ,, <esc>:keepp /<++><CR>ca< 12 13 call plug#begin(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/plugged"')) 14 Plug 'tpope/vim-surround' 15 Plug 'preservim/nerdtree' 16 Plug 'junegunn/goyo.vim' 17 Plug 'jreybert/vimagit' 18 Plug 'vimwiki/vimwiki' 19 Plug 'vim-airline/vim-airline' 20 Plug 'tpope/vim-commentary' 21 Plug 'ap/vim-css-color' 22 Plug 'rmehri01/onenord.nvim', { 'branch': 'main' } 23 Plug 'neovim/nvim-lspconfig' 24 " Autocompletion engine 25 Plug 'hrsh7th/nvim-cmp' 26 Plug 'hrsh7th/cmp-nvim-lsp' 27 Plug 'hrsh7th/cmp-buffer' 28 Plug 'hrsh7th/cmp-path' 29 Plug 'L3MON4D3/LuaSnip' 30 Plug 'saadparwaiz1/cmp_luasnip' 31 Plug 'lewis6991/gitsigns.nvim' 32 Plug 'nvim-lualine/lualine.nvim' 33 call plug#end() 34 35 lua << EOF 36 require('lualine').setup() 37 require('onenord').setup({ 38 disable = { 39 background = true, 40 }, 41 }) 42 -- Completion setup 43 local cmp = require'cmp' 44 45 cmp.setup({ 46 snippet = { 47 expand = function(args) 48 require('luasnip').lsp_expand(args.body) 49 end, 50 }, 51 mapping = cmp.mapping.preset.insert({ 52 ['<C-Space>'] = cmp.mapping.complete(), 53 ['<CR>'] = cmp.mapping.confirm({ select = true }), 54 ['<Tab>'] = cmp.mapping(function(fallback) 55 if cmp.visible() then 56 cmp.select_next_item() 57 else 58 fallback() 59 end 60 end, { 'i', 's' }), 61 }), 62 sources = cmp.config.sources({ 63 { name = 'nvim_lsp' }, 64 { name = 'luasnip' }, 65 }, { 66 { name = 'buffer' }, 67 { name = 'path' }, 68 }) 69 }) 70 71 -- LSP setup 72 local lspconfig = require'lspconfig' 73 74 -- Attach capabilities for nvim-cmp to LSP 75 local capabilities = require('cmp_nvim_lsp').default_capabilities() 76 77 -- Enable language servers 78 lspconfig.clangd.setup { 79 capabilities = capabilities, 80 } 81 require('lspconfig').rust_analyzer.setup({ 82 settings = { 83 ["rust-analyzer"] = { 84 cargo = { allFeatures = true }, 85 } 86 } 87 }) 88 lspconfig.html.setup { 89 capabilities = capabilities, 90 } 91 lspconfig.cssls.setup { 92 capabilities = capabilities, 93 } 94 lspconfig.jsonls.setup { 95 capabilities = capabilities, 96 } 97 require('gitsigns').setup({ 98 signs = { 99 add = { text = '+' }, 100 change = { text = '~' }, 101 delete = { text = '_' }, 102 topdelete = { text = '‾' }, 103 changedelete = { text = '~' }, 104 }, 105 current_line_blame = false, -- optional: shows inline blame 106 }) 107 EOF 108 109 set title 110 set mouse=a 111 set nohlsearch 112 set clipboard+=unnamedplus 113 set noshowmode 114 set noruler 115 set laststatus=0 116 set noshowcmd 117 colorscheme onenord 118 set expandtab 119 set tabstop=2 120 set shiftwidth=2 121 122 " Some basics: 123 nnoremap c "_c 124 filetype plugin on 125 syntax on 126 set encoding=utf-8 127 set number relativenumber 128 " Enable autocompletion: 129 set wildmode=longest,list,full 130 " Disables automatic commenting on newline: 131 autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o 132 " Perform dot commands over visual blocks: 133 vnoremap . :normal .<CR> 134 " Goyo plugin makes text more readable when writing prose: 135 map <leader>f :Goyo \| set bg=light \| set linebreak<CR> 136 " Spell-check set to <leader>o, 'o' for 'orthography': 137 map <leader>o :setlocal spell! spelllang=en_us<CR> 138 " Splits open at the bottom and right, which is non-retarded, unlike vim defaults. 139 set splitbelow splitright 140 141 " Nerd tree 142 map <leader>n :NERDTreeToggle<CR> 143 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif 144 let NERDTreeBookmarksFile = stdpath('data') . '/NERDTreeBookmarks' 145 146 " vim-airline 147 if !exists('g:airline_symbols') 148 let g:airline_symbols = {} 149 endif 150 let g:airline_symbols.colnr = ' C:' 151 let g:airline_symbols.linenr = ' L:' 152 let g:airline_symbols.maxlinenr = ' ' 153 let g:airline#extensions#whitespace#symbol = '!' 154 155 " Shortcutting split navigation, saving a keypress: 156 map <C-h> <C-w>h 157 map <C-j> <C-w>j 158 map <C-k> <C-w>k 159 map <C-l> <C-w>l 160 161 " Replace ex mode with gq 162 map Q gq 163 164 " Check file in shellcheck: 165 map <leader>s :!clear && shellcheck -x %<CR> 166 167 " Open my bibliography file in split 168 map <leader>b :vsp<space>$BIB<CR> 169 map <leader>r :vsp<space>$REFER<CR> 170 171 " Replace all is aliased to S. 172 nnoremap S :%s//g<Left><Left> 173 174 " Compile document, be it groff/LaTeX/markdown/etc. 175 map <leader>c :w! \| !compiler "%:p"<CR> 176 177 " Open corresponding .pdf/.html or preview 178 map <leader>p :!opout "%:p"<CR> 179 180 " Runs a script that cleans out tex build files whenever I close out of a .tex file. 181 autocmd VimLeave *.tex !latexmk -c % 182 183 " Ensure files are read as what I want: 184 let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'} 185 map <leader>v :VimwikiIndex<CR> 186 let g:vimwiki_list = [{'path': '~/.local/share/nvim/vimwiki', 'syntax': 'markdown', 'ext': '.md'}] 187 autocmd BufRead,BufNewFile /tmp/calcurse*,~/.calcurse/notes/* set filetype=markdown 188 autocmd BufRead,BufNewFile *.ms,*.me,*.mom,*.man set filetype=groff 189 autocmd BufRead,BufNewFile *.tex set filetype=tex 190 191 " Save file as sudo on files that require root permission 192 cabbrev w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit! 193 194 " Enable Goyo by default for mutt writing 195 autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo 80 | call feedkeys("jk") 196 autocmd BufRead,BufNewFile /tmp/neomutt* map ZZ :Goyo!\|x!<CR> 197 autocmd BufRead,BufNewFile /tmp/neomutt* map ZQ :Goyo!\|q!<CR> 198 199 " Automatically deletes all trailing whitespace and newlines at end of file on save. & reset cursor position 200 autocmd BufWritePre * let currPos = getpos(".") 201 autocmd BufWritePre * %s/\s\+$//e 202 autocmd BufWritePre * %s/\n\+\%$//e 203 autocmd BufWritePre *.[ch] %s/\%$/\r/e " add trailing newline for ANSI C standard 204 autocmd BufWritePre *neomutt* %s/^--$/-- /e " dash-dash-space signature delimiter in emails 205 autocmd BufWritePre * cal cursor(currPos[1], currPos[2]) 206 207 " When shortcut files are updated, renew bash and ranger configs with new material: 208 autocmd BufWritePost bm-files,bm-dirs !shortcuts 209 " Run xrdb whenever Xdefaults or Xresources are updated. 210 autocmd BufRead,BufNewFile Xresources,Xdefaults,xresources,xdefaults set filetype=xdefaults 211 autocmd BufWritePost Xresources,Xdefaults,xresources,xdefaults !xrdb % 212 " Recompile dwmblocks on config edit. 213 autocmd BufWritePost ~/.local/src/dwmblocks/config.h !cd ~/.local/src/dwmblocks/; sudo make install && { killall -q dwmblocks;setsid -f dwmblocks } 214 215 " Turns off highlighting on the bits of code that are changed, so the line that is changed is highlighted but the actual text that has changed stands out on the line and is readable. 216 if &diff 217 highlight! link DiffText MatchParen 218 endif 219 220 " Function for toggling the bottom statusbar: 221 let s:hidden_all = 0 222 function! ToggleHiddenAll() 223 if s:hidden_all == 0 224 let s:hidden_all = 1 225 set noshowmode 226 set noruler 227 set laststatus=0 228 set noshowcmd 229 else 230 let s:hidden_all = 0 231 set showmode 232 set ruler 233 set laststatus=2 234 set showcmd 235 endif 236 endfunction 237 nnoremap <leader>h :call ToggleHiddenAll()<CR> 238 " Load command shortcuts generated from bm-dirs and bm-files via shortcuts script. 239 " Here leader is ";". 240 " So ":vs ;cfz" will expand into ":vs /home/<user>/.config/zsh/.zshrc" 241 " if typed fast without the timeout. 242 silent! source ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/shortcuts.vim