dotfiles

Cross platform dotfiles for linux, mac and windows
git clone git@getsh.org:dotfiles.git
Log | Files | Refs

keybindings.vim (5155B)


      1 " General keybindings
      2 nnoremap <leader>co :copen<cr>
      3 nnoremap <leader>cd :cdo<space>s/
      4 nnoremap <leader>cs :cdo<space>s/
      5 nnoremap <leader>ec :edit $HOME/.vimrc<cr>
      6 nnoremap <leader>ek :edit $XDG_DATA_HOME/vim/keybindings.vim<cr>
      7 nnoremap <leader>et :set expandtab<cr>
      8 nnoremap <leader>fa :find *
      9 nnoremap <leader>ff :find *
     10 nnoremap <leader>lb :ls<cr>:b<space>
     11 nnoremap <leader>ld :ldo<space>s/
     12 nnoremap <leader>lo :lopen<cr>
     13 nnoremap <leader>ls :ldo<space>s/
     14 nnoremap <leader>pp :Rg<cr>
     15 nnoremap <leader>pv :packadd vimspector<cr>
     16 nnoremap <leader>sc :source $XDG_CONFIG_HOME/vim/vimrc<cr>
     17 nnoremap <leader>so :source %<cr>
     18 nnoremap <leader>spp :set paste<cr>
     19 nnoremap <leader>spa :set path+=**<cr>
     20 nnoremap <leader>tt :tabnew<cr>
     21 nnoremap <leader>ta :tab *
     22 nnoremap <leader>vg :vimgrep<space>
     23 nnoremap <leader>/ :cdo %s/
     24 
     25 " Buffer Creation
     26 nnoremap <leader>sc :source $XDG_CONFIG_HOME/vim/vimrc<cr>
     27 nnoremap <leader>ss :split<cr>
     28 nnoremap <leader>vv :vsplit<cr>
     29 nnoremap <leader>wd :call DiffWithSaved()<cr>
     30 
     31 fun! SaveAndSuspend()
     32     :w
     33     :suspend
     34 endfun
     35 
     36 nnoremap <silent> <leader>zj :call NextClosedFold('j')<cr>
     37 nnoremap <silent> <leader>zk :call NextClosedFold('k')<cr>
     38 
     39 function! NextClosedFold(dir)
     40     let cmd = 'norm!z'..a:dir
     41     let view = winsaveview()
     42     let [l0, l, open] = [0, view.lnum, 1]
     43     while l != l0 && open
     44         exe cmd
     45         let [l0, l] = [l, line('.')]
     46         let open = foldclosed(l) < 0
     47     endwhile
     48     if open
     49         call winrestview(view)
     50     endif
     51 endfunction
     52 
     53 
     54 " Control
     55 nnoremap <c-z> :call SaveAndSuspend()<cr>
     56 inoremap <c-z> :call SaveAndSuspend()<cr>
     57 
     58 nnoremap <c-f> :bnext<cr>
     59 nnoremap <c-b> :bprevious<cr>
     60 
     61 " Accessible completions
     62 inoremap <c-f> <c-x><c-f>
     63 inoremap <c-l> <c-x><c-l>
     64 " Emacs line navigation in insert mode
     65 inoremap <c-a> <c-o>0
     66 inoremap <c-e> <c-o>A
     67 " Behave vim
     68 nnoremap Y y$
     69 nnoremap Q :noh<cr>
     70 
     71 " development
     72 nnoremap <leader>oc :grepadd /:: %
     73 nnoremap <leader>oh :grepadd /:: %
     74 
     75 nnoremap <leader>fb :b *
     76 
     77 nnoremap <c-p> :call FZYFiles()<cr>
     78 " TODO reflect on whether <leader><leader> is productive, I keep hitting it
     79 " accidentally
     80 "nnoremap <leader><leader> :Rg<cr>
     81 " TODO setup this up with fzf
     82 nnoremap \g :Ggrep<cr>
     83 
     84 fun! SetupCommandAlias(from, to)
     85   exec 'cnoreabbrev <expr> '.a:from
     86         \ .' ((getcmdtype() is# ":" && getcmdline() is# "'.a:from.'")'
     87         \ .'? ("'.a:to.'") : ("'.a:from.'"))'
     88 endfun
     89 call SetupCommandAlias("W","w")
     90 call SetupCommandAlias("Wq","wq")
     91 call SetupCommandAlias("man","help")
     92 
     93 nnoremap <leader>tb :call ToggleBackground()<CR>
     94 nnoremap <leader>tl :call ToggleList()<CR>
     95 
     96 " useful
     97 nnoremap <leader>nn :set number<cr>
     98 
     99 " development
    100 nnoremap <leader>bb :call SaveAndBuild()<CR>
    101 nnoremap <leader>bc :Make clean<CR>
    102 
    103 nnoremap <leader>fmv :call FileMvHelper()<CR>
    104 
    105 " Quick save and write
    106 nnoremap <leader>wq :wq<cr>
    107 nnoremap <leader>ww :w<cr>
    108 nnoremap <leader>qq :q<cr>
    109 
    110 " vim-fugitive
    111 nnoremap <leader>gb :G blame<cr>
    112 nnoremap <leader>gd :Gvdiff<CR>
    113 nnoremap <leader>gg :Ggrep<space>
    114 nnoremap <leader>gr :G reset %<cr>
    115 nnoremap <leader>gwq :Gwq<cr>
    116 nnoremap <leader>lg :Glgrep<space>
    117 
    118 
    119 " Generate ctags
    120 nnoremap<leader>gt :!sh -c "ctags `git ls-files`"<CR>
    121 
    122 nnoremap <CR> :noh<CR><CR>:<backspace>
    123 
    124 " Markdown - Add checkbox mode?
    125 nnoremap <leader>cc :ChecklistToggleCheckbox<cr>
    126 nnoremap <leader>ct :ChecklistToggleCheckbox<cr>
    127 nnoremap <leader>ce :ChecklistEnableCheckbox<cr>
    128 "nnoremap <leader>cd :ChecklistDisableCheckbox<cr>
    129 
    130 let g:gutentags_file_list_command = 'rg --files'
    131 
    132 " vim-fugitive
    133 nnoremap <leader>gg :Ggrep<space>
    134 nnoremap <leader>lg :Glgrep<space>
    135 
    136 autocmd FileType markdown set cursorline
    137 
    138 " Hide and format markdown elements like **bold**
    139 autocmd FileType markdown set conceallevel=2
    140 
    141 nnoremap <leader>h1 :call QuickUnderline(1)<cr>
    142 nnoremap <leader>h2 :call QuickUnderline(2)<cr>
    143 
    144 fun! GotoWindow(id)
    145     call win_gotoid(a:id)
    146 endfun
    147 
    148 " Debugger remaps
    149 nnoremap <leader>dd :call vimspector#Launch()<CR>
    150 nnoremap <leader>dc :call GotoWindow(g:vimspector_session_windows.code)<CR>
    151 nnoremap <leader>dt :call GotoWindow(g:vimspector_session_windows.tagpage)<CR>
    152 nnoremap <leader>dv :call GotoWindow(g:vimspector_session_windows.variables)<CR>
    153 nnoremap <leader>dw :call GotoWindow(g:vimspector_session_windows.watches)<CR>
    154 nnoremap <leader>ds :call GotoWindow(g:vimspector_session_windows.stack_trace)<CR>
    155 nnoremap <leader>do :call GotoWindow(g:vimspector_session_windows.output)<CR>
    156 nnoremap <leader>de :call vimspector#Reset()<CR>
    157 
    158 nnoremap <leader>dtcb :call vimspector#CleanLineBreakpoint()<CR>
    159 
    160 nmap <leader>dl <Plug>VimspectorStepInto
    161 nmap <leader>dj <Plug>VimspectorStepOver
    162 nmap <leader>dk <Plug>VimspectorStepOut
    163 nmap <leader>d_ <Plug>VimspectorRestart
    164 nnoremap <leader>d<space> :call vimspector#Continue()<CR>
    165 
    166 nmap <leader>drc <Plug>VimspectorRunToCursor
    167 nmap <leader>dbp <Plug>VimspectorToggleBreakpoint
    168 nmap <leader>dcbp <Plug>VimspectorToggleConditionalBreakpoint
    169 
    170 " nb
    171 " TODO open a fuzzy finder quickly. Even better use fuzzy finder without chdir
    172 nnoremap <leader>nb :chdir $NB_PATH<cr>
    173 
    174 nnoremap cn *``cgn
    175 nnoremap cN *``cgN
    176 let g:mc = "y/\\V\<C-r>=escape(@\", '/')\<CR>\<CR>"
    177 vnoremap <expr> cn g:mc . "``cgn"
    178 
    179