" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{,}} foldmethod=marker: " basic {{ xnoremap J :m '>+1gv=gv xnoremap K :m '<-2gv=gv " no enter ex mode nnoremap Q xnoremap < >gv inoremap "+]p xnoremap "+y nnoremap n 'Nn'[v:searchforward] nnoremap N 'nN'[v:searchforward] nnoremap k (v:count > 1 ? "m'" . v:count : '') . 'k' nnoremap j (v:count > 1 ? "m'" . v:count : '') . 'j' " yank to end nnoremap Y y$ " no overwrite paste xnoremap p "_dP " clear highlight update diff nnoremap :let @/=''=has('diff')?'diffupdate':'' " some shortcut for git nnoremap gca :Gcommit -a -v nnoremap gcc :Gcommit -v -- =expand('%') nnoremap gp :call gpush() " }} " insert keymap like emacs {{ inoremap diwa inoremap inoremap inoremap u inoremap inoremap inoremap inoremap pumvisible() ? "\" : "\" " window navigate {{ nnoremap l nnoremap h nnoremap j nnoremap k " }} " command line alias {{ cnoremap w!! w !sudo tee % >/dev/null cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap =expand("%:p:h") . "/" " }} " meta keys {{ vnoremap "+y inoremap "+]p nnoremap :qa! nnoremap :wa inoremap :w nnoremap 1gt nnoremap 2gt nnoremap 3gt nnoremap 4gt nnoremap 5gt inoremap 1gt inoremap 2gt inoremap 3gt inoremap 4gt inoremap 5gt " }} " plugins {{ " buftabline nmap 1 1gt nmap 2 2gt nmap 3 3gt nmap 4 4gt nmap 5 5gt nmap 6 6gt nmap 7 7gt nmap 8 8gt " vim-exchange xmap x (Exchange) " coc.nvim nmap (coc-cursors-position) nmap (coc-cursors-word) xmap (coc-cursors-range) nmap (coc-range-select) xmap (coc-range-select) xmap (coc-range-select-backword) xmap (coc-repl-sendtext) nmap s (coc-smartf-forward) nmap S (coc-smartf-backward) nmap [g (coc-git-prevchunk) nmap ]g (coc-git-nextchunk) nmap gs (coc-git-chunkinfo) nmap gb (coc-git-commit) imap (coc-snippets-expand) imap (coc-snippets-expand) xmap (coc-snippets-select) nmap [c (coc-diagnostic-prev) nmap ]c (coc-diagnostic-next) nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) nnoremap K :call show_documentation() " remap for complete to use tab and inoremap \ pumvisible() ? "\" : \ check_back_space() ? "\" : \ coc#refresh() inoremap coc#refresh() inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? coc#_select_confirm() : "\u\\=coc#on_enter()\" " }} " visual search {{ " In visual mode when you press * or # to search for the current selection xnoremap * :call visualSearch('f') xnoremap # :call visualSearch('b') " }} " functions {{ function! s:visualSearch(direction) let l:saved_reg = @" execute 'normal! vgvy' let l:pattern = escape(@", '\\/.*$^~[]') let l:pattern = substitute(l:pattern, "\n$", '', '') if a:direction ==# 'b' execute 'normal! ?' . l:pattern . "\" elseif a:direction ==# 'f' execute 'normal! /' . l:pattern . '^M' endif let @/ = l:pattern let @" = l:saved_reg endfunction function! s:check_back_space() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction function! s:gpush() if empty(get(b:, 'git_dir', '')) | return | endif let branch = system('git --git-dir='.b:git_dir.' rev-parse --abbrev-ref HEAD') if !v:shell_error && !empty(branch) let old_cwd = getcwd() execute 'lcd ' . fnamemodify(b:git_dir, ':h') execute 'Nrun git push origin '.substitute(branch, "\n$", '', ''). ' --force-with-lease' endif endfunction function! s:show_documentation() if &filetype ==# 'vim' execute 'h '.expand('') else call CocAction('doHover') endif endfunction " }} " list {{ nnoremap \r :CocList -N mru -A nnoremap h :CocList helptags nnoremap g :CocList gstatus nnoremap t :CocList buffers nnoremap y :CocList yank nnoremap u :CocList snippets nnoremap w :exe 'CocList -A -I --normal --input='.expand('').' words -w' nnoremap l :CocList locationlist nnoremap q :CocList quickfix nnoremap a :CocList diagnostics nnoremap e :CocList extensions nnoremap c :CocList commands nnoremap o :CocList outline nnoremap s :CocList symbols nnoremap r :CocList mru nnoremap f :CocList files nnoremap j :CocNext nnoremap k :CocPrev nnoremap p :CocListResume function! GetDeleteAction(context) let name = a:context['name'] if name ==# 'mru' return 'delete' elseif name ==# 'buffers' return 'delete' elseif name ==# 'sessions' return 'delete' elseif name ==# 'gstatus' return 'preview' elseif name ==# 'bcommits' || name ==# 'commits' return 'diff' endif return '' endfunction " }}