" utilities.vim — small editing and config helpers function! s:LocalConfigPath() abort let l:xdg = !empty($XDG_CONFIG_HOME) && $XDG_CONFIG_HOME =~# '^/' \ ? $XDG_CONFIG_HOME \ : '~/.config' return expand(get(g:, 'chopsticks_resolved_local_config', \ get(g:, 'chopsticks_local_config', l:xdg . '/chopsticks.vim'))) endfunction function! s:EditLocalConfig() abort let l:path = s:LocalConfigPath() let l:new_file = !filereadable(l:path) let l:dir = fnamemodify(l:path, ':h') if !isdirectory(l:dir) call mkdir(l:dir, 'p') endif execute 'edit ' . fnameescape(l:path) setlocal filetype=vim if l:new_file && line('$') == 1 && getline(1) ==# '' call setline(1, [ \ '" chopsticks local preferences', \ "let g:chopsticks_profile = 'engineer'", \ "let g:chopsticks_keymap_style = 'space'", \ '', \ '" Optional habits:', \ '" let g:chopsticks_enable_jk_escape = 1', \ '" let g:chopsticks_enable_ctrl_s_save = 1', \ '" let g:chopsticks_enable_auto_pairs = 1', \ ]) setlocal nomodified endif endfunction function! s:ReloadChopsticks() abort unlet! g:chopsticks_loaded execute 'source ' . fnameescape($MYVIMRC) echo 'chopsticks reloaded' endfunction command! ChopsticksConfig call s:EditLocalConfig() command! ChopsticksReload call s:ReloadChopsticks() if get(g:, 'chopsticks_enable_reindent_file', 0) if g:chopsticks_space_keymaps nnoremap c= gg=G`` else nnoremap F gg=G`` endif endif if g:chopsticks_space_keymaps vnoremap = = else vnoremap F = nnoremap wa :wa endif if !g:chopsticks_space_keymaps nnoremap = :exe "resize " . (winheight(0) * 3/2) nnoremap - :exe "resize " . (winheight(0) * 2/3) endif if g:chopsticks_space_keymaps nnoremap else nnoremap endif if g:chopsticks_space_keymaps nnoremap cW :%s/\s\+$//:let @/='' vnoremap cW :s/\s\+$//:let @/=''gv else nnoremap W :%s/\s\+$//:let @/='' vnoremap W :s/\s\+$//:let @/=''gv endif if g:chopsticks_space_keymaps nnoremap fc :ChopsticksConfig nnoremap fv :edit $MYVIMRC nnoremap fV :ChopsticksReload else nnoremap ec :ChopsticksConfig nnoremap ev :edit $MYVIMRC nnoremap sv :ChopsticksReload endif if g:chopsticks_space_keymaps nnoremap sr :%s/\<\>//g vnoremap sr :s///g else nnoremap * :%s/\<\>//g vnoremap * :s///g endif if has('clipboard') if g:chopsticks_space_keymaps nnoremap fp :let @+ = expand("%:p"):echo "Copied: " . expand("%:p") nnoremap fn :let @+ = expand("%:t"):echo "Copied: " . expand("%:t") else nnoremap cp :let @+ = expand("%:p"):echo "Copied: " . expand("%:p") nnoremap cf :let @+ = expand("%:t"):echo "Copied: " . expand("%:t") endif endif if get(g:, 'chopsticks_enable_sudo_save_bang', 0) cnoremap w!! w !sudo tee > /dev/null % endif