" Sane vim defaults for ArchLabs " Arch defaults runtime! archlinux.vim set modeline " enable vim modelines set clipboard^=unnamedplus " system clipboard (requires +clipboard) set number " enable line numbers set confirm " ask confirmation for some things, like save before quit, etc. set wildmenu " Tab completion menu when using command mode set expandtab " Tab key inserts spaces not tabs set softtabstop=4 " spaces to enter for each tab set shiftwidth=4 " amount of spaces for indentation set shortmess+=aAcIws " Hide or shorten certain messages " ------ leader mapping ------ let g:mapleader = ',' map , " ------ enable additional features ------ " enable mouse set mouse=a if has('mouse_sgr') " sgr mouse is better but not every term supports it set ttymouse=sgr endif " syntax highlighting syntax enable if has('termguicolors') && $DISPLAY !=? '' " true color in the terminal set termguicolors " fix true color in some terminals (nvim doesn't have this issue) if !has('nvim') && !($TERM =~? 'xterm' || &term =~? 'xterm') let $TERM = 'xterm-256color' let &term = 'xterm-256color' endif endif " change cursor shape for different editing modes (nvim does this by default) if !has('nvim') && exists('$TMUX') let &t_SI = "\Ptmux;\\e[5 q\\\" let &t_SR = "\Ptmux;\\e[4 q\\\" let &t_EI = "\Ptmux;\\e[2 q\\\" elseif !has('nvim') let &t_SI = "\e[6 q" let &t_SR = "\e[4 q" let &t_EI = "\e[2 q" endif " ------ basic maps ------ " open ranger as a file chooser using the function below nnoremap r :call ranger() " paste while in insert mode inoremap :set pastea+:set nopastea " alt defaults nnoremap 0 ^ nnoremap Y y$ nnoremap n nzzzv nnoremap N Nzzzv nnoremap ==j " re-visual text after changing indent vnoremap > >gv vnoremap < j v:count ? 'j' : 'gj' nnoremap k v:count ? 'k' : 'gk' " ------ autocmd ------ " Reload changes if file changed outside of vim requires autoread augroup load_changed_file autocmd! autocmd FocusGained,BufEnter * if mode() !=? 'c' | checktime | endif autocmd FileChangedShellPost * echo "Changes loaded from file" augroup END " when quitting a file, save the cursor position augroup save_cursor_position autocmd! autocmd BufReadPost * call setpos(".", getpos("'\"")) augroup END " ------ adv maps ------ " toggle line numbers nnoremap nn \ :if &number \ set nonumber \ else \ set number \ endif " strip trailing whitespace nnoremap ss \ :let _p = getpos(".") \ let _s = (@/ != '') ? @/ : '' \ %s/\s\+$//e \ let @/ = _s \ nohlsearch \ unlet _s \ call setpos('.', _p) \ unlet _p " global replace vnoremap sw "hy \ :let b:sub = input('global replacement: ') \ if b:sub !=? '' \ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') \ execute '%s/'.b:rep."/".b:sub.'/g' \ unlet b:sub b:rep \ endif nnoremap sw \ :let b:sub = input('global replacement: ') \ if b:sub !=? '' \ execute "%s//".b:sub.'/g' \ unlet b:sub \ endif " prompt before each replace vnoremap cw "hy \ :let b:sub = input('interactive replacement: ') \ if b:sub !=? '' \ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') \ execute '%s/'.b:rep.'/'.b:sub.'/gc' \ unlet b:sub b:rep \ endif nnoremap cw \ :let b:sub = input('interactive replacement: ') \ if b:sub !=? '' \ execute "%s//".b:sub.'/gc' \ unlet b:sub \ endif " highlight long lines let w:longlines = matchadd('ColorColumn', '\%'.&tw.'v', &tw) nnoremap ll \ :if exists('w:longlines') \ silent! call matchdelete(w:longlines) \ unlet w:longlines \ elseif &textwidth > 0 \ let w:longlines = matchadd('ColorColumn', '\%'.&textwidth.'v', &textwidth) \ else \ let w:longlines = matchadd('ColorColumn', '\%80v', 80) \ endif " local keyword jump nnoremap fw \ [I:let b:jump = input('Go To: ') \ if b:jump !=? '' \ execute "normal! ".b:jump."[\t" \ unlet b:jump \ endif " open ranger as a file chooser function! ranger() let l:temp = tempname() execute 'silent !st -e ranger --choosefiles='.shellescape(l:temp).' $PWD' if !filereadable(temp) redraw! return endif let l:names = readfile(l:temp) if empty(l:names) redraw! return endif execute 'edit '.fnameescape(l:names[0]) for l:name in l:names[1:] execute 'argadd '.fnameescape(l:name) endfor redraw! endfunction