" Sane vim defaults for ArchLabs scriptencoding utf8 " Arch defaults runtime! archlinux.vim " leader key let g:mapleader = "\" " system clipboard (requires +clipboard) set clipboard^=unnamed,unnamedplus " additional settings syntax enable set number " enable line numbers set backup " create backup files in runtimepath/backup/ set undofile " persistent undo files in runtimepath/undo/ set modeline " enable vim modelines set hlsearch " highlight search items set incsearch " searches are performed as you type set confirm " ask confirmation like save before quit. set tabstop=4 " tab is equivalent to how many spaces set softtabstop=4 " tab is equivalent to how many spaces set shiftwidth=4 " amount of spaces for indentation set shortmess+=aAcws " hide or shorten certain messages set wildmenu " tab completion menu when using command mode set wildignore+=*~,*.pyc,*/.git/*,*.so,*.swp,*.o,*.zip,*.zwc,*.png,*.jpg set ttimeout set ttimeoutlen=10 set timeoutlen=600 set updatecount=80 set linebreak breakindent set list listchars=tab:>>,trail:~ set mouse=niv " use the terminal mouse in command mode (:) if has('mouse_sgr') " sgr mouse is better but not every term supports it set ttymouse=sgr endif let g:netrw_altv = 1 let g:netrw_liststyle = 3 let g:netrw_browse_split = 3 if $TERM !=? 'linux' set termguicolors " true colors in terminals (neovim doesn't need this) if !has('nvim') && !($TERM =~? 'xterm' || &term =~? 'xterm') let $TERM = 'xterm-256color' let &term = 'xterm-256color' endif if has('multi_byte') && $TERM !=? 'linux' " ▏│ ┆ ┃ › »» set list listchars=tab:▏\ ,extends:❯,precedes:❮ set fillchars=vert:┃ showbreak=↪ endif endif " set the colorscheme variant.. midnight, night, or day let g:jinx_theme = 'midnight' try colorscheme jinx catch colorscheme evening endtry " change cursor shape for different editing modes, neovim does this by default if !has('nvim') if exists('$TMUX') let &t_SI = "\Ptmux;\\e[5 q\\\" let &t_SR = "\Ptmux;\\e[4 q\\\" let &t_EI = "\Ptmux;\\e[2 q\\\" elseif $TERM ==# 'linux' let &t_SI = "\e[?0c" let &t_EI = "\e[?8c" else let &t_SI = "\e[6 q" let &t_SR = "\e[4 q" let &t_EI = "\e[2 q" endif endif " ------ commands ------ command! D Explore command! R call ranger() command! -bang -complete=buffer -nargs=? Bclose call Bclose(, ) command! -complete=buffer -nargs=? Bselect call Bselect() command! W exec 'silent w !sudo tee % >/dev/null'|edit! " ------ basic maps ------ " visually select the whole file vnoremap aa VGo1G " yank the entire file nnoremap gyy gg"+yG'' vnoremap gyy gg"+yG'' " open ranger as a file chooser using the function below nnoremap r :call ranger() " select buffer from a list nnoremap b :Bselect " close current buffer (and tab if needed) nnoremap q :Bclose:silent tabclosegT " change windows with ctrl+(hjkl) nnoremap nnoremap nnoremap nnoremap " alt defaults nnoremap 0 ^ nnoremap Y y$ nnoremap n nzzzv nnoremap N Nzzzv nnoremap ==1j vnoremap == " re-visual text after changing indent vnoremap > >gv vnoremap < nn :set number! " gj/k but preserve numbered jumps ie: 12j or 45k nmap j v:count ? 'j' : 'gj' nmap k v:count ? 'k' : 'gk' " open a terminal in $PWD nnoremap tt :terminal " toggle folding nnoremap za :set foldenable! " tab control nnoremap :tabmove -1 nnoremap :tabmove +1 nnoremap te :tabnew nnoremap tn :tabnext nnoremap tf :tabfirst nnoremap tp :tabprevious " open a new tab in the current directory with netrw (file browser) nnoremap - :tabedit =expand("%:p:h") " fix syntax highlighting issues nnoremap U :syntax sync fromstart:redraw! " ------ autocmd ------ " when quitting a file save the cursor position and reload if file changed augroup load_changed_file autocmd! autocmd BufReadPost * call setpos(".", getpos("'\"")) autocmd FocusGained,BufEnter * if mode() !=? 'c' | checktime | endif autocmd FileChangedShellPost * echo "Changes loaded from source file" augroup END " make the built-in terminal behave a bit better if has('nvim') augroup open_terminal autocmd! autocmd TermOpen * setlocal nonumber norelativenumber modifiable | startinsert autocmd TermClose * buffer # augroup END elseif has('terminal') augroup open_terminal autocmd! autocmd TerminalOpen * setlocal nonumber norelativenumber augroup END endif " when not running in a linux console toggle some things when in insert mode if $TERM !=# 'linux' augroup active_cursorline autocmd! autocmd InsertEnter * setlocal cursorline listchars-=trail:• autocmd InsertLeave * setlocal nocursorline listchars+=trail:• augroup END else " otherwise disable cursorline set nocursorline endif " ------ adv maps ------ " strip trailing whitespace, ss (strip space) nnoremap ss \ :let b:_p = getpos(".") \ let b:_s = (@/ != '') ? @/ : '' \ %s/\s\+$//e \ let @/ = b:_s \ nohlsearch \ unlet b:_s \ call setpos('.', b:_p) \ unlet b:_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, ll (long lines) let w:longlines = matchadd('ColorColumn', '\%'.&textwidth.'v', &textwidth) nnoremap ll \ :if exists('w:longlines') \ silent! call matchdelete(w:longlines) \ echo 'Long line highlighting disabled' \ unlet w:longlines \ elseif &textwidth > 0 \ let w:longlines = matchadd('ColorColumn', '\%'.&textwidth.'v', &textwidth) \ echo 'Long line highlighting enabled' \ else \ let w:longlines = matchadd('ColorColumn', '\%80v', 81) \ echo 'Long line highlighting enabled' \ 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 function! Bclose(bang, buffer) abort if empty(a:buffer) let l:target = bufnr('%') elseif a:buffer =~? '^\d\+$' let l:target = bufnr(str2nr(a:buffer)) else let l:target = bufnr(a:buffer) endif if l:target < 0 call WarningMsg('No matching buffer for '.a:buffer) return endif if empty(a:bang) && getbufvar(l:target, '&modified') call WarningMsg('No write since last change for buffer '.l:target.' (use :Bclose!)') return endif " Numbers of windows that view target buffer which we will delete. let l:num_wins = filter(range(1, winnr('$')), 'winbufnr(v:val) == l:target') if empty(a:bang) && len(l:num_wins) > 1 call WarningMsg('Buffer is open in multiple windows (use :Bclose!)') return endif let l:cur_win = winnr() for w in l:num_wins execute w.'wincmd w' let prevbuf = bufnr('#') if prevbuf > 0 && buflisted(prevbuf) && prevbuf != w buffer # else bprevious endif if l:target == bufnr('%') " Numbers of listed buffers which are not the target to be deleted. let blisted = filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != l:target') " Listed, not target, and not displayed. let bhidden = filter(copy(blisted), 'bufwinnr(v:val) < 0') " Take the first buffer, if any (could be more intelligent). let bjump = (bhidden + blisted + [-1])[0] if bjump > 0 execute 'buffer '.bjump else execute 'enew'.a:bang endif endif endfor execute 'bdelete'.a:bang.' '.l:target execute l:cur_win.'wincmd w' endfunction function! Bselect(...) abort let l:pattern = a:0 >= 1 ? a:1 : '' if l:pattern ==? '' let l:pattern = input('String match: ') redraw! endif if l:pattern !=# '' let l:bufcount = bufnr('$') let l:currbufnr = 1 let l:nummatches = 0 let l:matchingbufnr = 0 while l:currbufnr <= l:bufcount if bufexists(l:currbufnr) let l:currbufname = bufname(l:currbufnr) if (match(l:currbufname, l:pattern) > -1) echo l:currbufnr . ': ' . l:currbufname let l:nummatches += 1 let l:matchingbufnr = l:currbufnr endif endif let l:currbufnr += 1 endwhile if (l:nummatches == 1) execute ':buffer '.l:matchingbufnr elseif (l:nummatches > 1) let l:desiredbufnr = input('Enter buffer number: ') if (strlen(l:desiredbufnr) != 0) execute ':buffer ' . l:desiredbufnr endif else call WarningMsg('No matching buffers') endif endif endfunction function! ranger() let l:temp = tempname() execute 'silent !xterm -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