" Manage plugins using vim-plug if ! filereadable(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"')) echo "Downloading junegunn/vim-plug to manage plugins..." silent !mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/ silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim autocmd VimEnter * PlugInstall endif call plug#begin(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/plugged"')) "Plug 'jiangmiao/auto-pairs' Plug 'alvan/vim-closetag' Plug 'ap/vim-css-color' Plug 'junegunn/goyo.vim' Plug 'vimwiki/vimwiki' call plug#end() "" Basic options set autochdir " Always change directory to current file set autoindent " Keeps indentation on new lines set hlsearch " Highlight search hits set ignorecase " Case-insensitive search... set linebreak " Word wrap set list " Show whitespace characters defined in listchars set listchars=tab:⇥\ \,space:· " Highlight tabs and spaces set mouse=a " Because sometimes it's just easier to use the mouse set number relativenumber " Enable relative line numbers set smartcase " ...Unless the search term is capital set splitbelow splitright " Open splits on bottom/right instead of top/left set termguicolors " Enable GUI colors for the terminal to get truecolor set wildmode=longest,list,full " Enable file auto-complete syntax on " Enable syntax highlighting " Get rid of the pointless .viminfo files that clutter the home directory let skip_defaults_vim=1 set viminfo="" " Disables automatic commenting on newline: autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o "" Plugin options " Closetag let g:closetag_filenames = '*.html,*.xhtml,*.phtml' " VimWiki let g:vimwiki_list = [{'path': '~/docs/school/arc/docs/wiki/', 'path_html': '~/docs/school/arc/docs/wiki/site/'}] " Filetype options autocmd BufRead,BufNewFile *.tex set filetype=tex au Filetype tex let b:autopairs_enabled = 0 au Filetype tex setlocal indentexpr= au BufRead,BufNewFile *.tssg set filetype=tssg "" Keybindings " Set leader-key to comma let mapleader ="," " Invoke goyo with comma-m nmap m :Goyo 120x " Invoke spellcheck mode with comma-l nmap l :setlocal spell! spelllang=en_us " Set cursorcolumn with comma-c nmap c :set cursorcolumn! " Navigate faster than hjkl with ctrl-hjlk nmap 0 nmap nmap nmap $ " Faster split navigation (leader-wasd, as opposed to ctrl-w + hjlk) map a h map s j map w k map d l " Keys for tab navigation nmap gt nmap t :tabnew nmap :tabnew " Copy and cut with standard bindings map "+y map "+x " Unmap Ex mode map Q " Perform dot commands over visual blocks: vnoremap . :normal . " Save file as sudo on files that require root permission cnoremap w!! execute 'silent! write !doas tee % >/dev/null' edit! " Camel case every word on the line nmap gcc :s/\v<(.)(\w*)/\u\1\L\2/g nmap gCC :%s/\v<(.)(\w*)/\u\1\L\2/g " HTML shortcuts nmap gwp I

l4xA

nmap gwh1 I

l5xA

nmap gwh2 I

l5xA

nmap gwh3 I

l5xA

"" Extra functionality " Colorscheme for root and normal users (since vimrc is just symlinked to the root user's home) if ($USER) == 'root' colorscheme koehler else if empty($DISPLAY) colorscheme koehler else set bg=dark let g:gruvbox_contrast_dark = 'hard' colorscheme gruvbox-timmy endif endif " Functions for changing the terminal emulator's class name to 'Vim' function GetTermPID(temu) let pinfo = ['', getpid(), ''] while !(pinfo[2] =~ a:temu || pinfo[1] == '0') let pinfo = split(system('ps h -o pid,ppid,command= -p' . pinfo[1])) endwhile return pinfo[0] endfunction function SetTermClassName(termpid, name) " Command chaining in xdotool doesn't work here for some reason silent exec "!xdotool set_window --class " . a:name . " $(xdotool search --pid " . a:termpid . ")" endfunction " Behaviors exclusive to either a tty or a graphical terminal emulator if empty($DISPLAY) " Clear the tty screen after exiting vim autocmd VimLeave * :clear else " Highlight current line set cursorline " Change window title autocmd BufEnter * :set title let &titleold="st" " Change class name let temu = "st" let temupid = GetTermPID(temu) if (temupid != 1) autocmd VimEnter * call SetTermClassName(temupid, "Vim") autocmd VimLeave * call SetTermClassName(temupid, temu) endif endif " Automatically deletes all trailing whitespace on save function DelWS() let l:save_view = winsaveview() :%s/\s*$//e call winrestview(l:save_view) endfunction autocmd BufWritePre * call DelWS()