dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | Submodules | README | LICENSE

keybinds.vim (4543B)


      1 """ Keyboard shortcuts
      2 
      3 " use space instead of \ as leader
      4 let mapleader="\<Space>"
      5 
      6 " Shortcut to reload .vimrc and ~/.vim/plugin/*.vim
      7 nnoremap <leader>R :source $MYVIMRC<cr>:runtime! plugin/*.vim<cr>:echo "Configuration reloaded"<cr>
      8 
      9 nnoremap <Leader>w :w<cr>
     10 nnoremap <Leader>W :wa<cr>
     11 nnoremap <Leader>q :q<cr>
     12 nnoremap <leader>Q :qa<cr>
     13 nnoremap <Leader>x :x<cr>
     14 
     15 " toggle spelling
     16 nnoremap <leader>s :set spell!<cr>
     17 
     18 " toggle line numbering
     19 nnoremap <leader>N :set number!<cr>
     20 
     21 " toggle relative line numbering
     22 nnoremap <leader>n :set relativenumber!<cr>
     23 
     24 " netrw
     25 nnoremap <leader>d :Lex<cr>
     26 
     27 " https://www.vi-improved.org/recommendations/
     28 "" add files with wildcards
     29 nnoremap <leader>a :argadd <c-r>=fnameescape(expand('%:p:h'))<cr>/*<c-d>
     30 "" go to file open prompt
     31 nnoremap <leader>e :e **/
     32 nnoremap <leader>g :grep<space>
     33 "" ilist function from qlist, make ilist go into quickfix window
     34 nnoremap <leader>i :Ilist<space>
     35 nnoremap <leader>m :make<cr>
     36 autocmd VimEnter * if exists(":Make") |
     37             \ exe "nnoremap <leader>m :Make<cr>" |
     38             \ endif
     39 
     40 "" strip trailing whitespace
     41 nnoremap <leader>s :call StripTrailingWhitespace()<cr>
     42 "" go to last used buffer
     43 nnoremap <leader><tab> :b#<cr>
     44 
     45 nnoremap <leader>% :vsplit<space>
     46 nnoremap <leader>" :split<space>
     47 
     48 " shortcuts to commonly used files
     49 nnoremap <leader>CC :e $MYVIMRC<cr>
     50 nnoremap <leader>CO :e ~/.vim/plugin/
     51 nnoremap <leader>CK :e ~/.vim/plugin/keybinds.vim<cr>
     52 nnoremap <leader>CA :e ~/.vim/plugin/appearance.vim<cr>
     53 nnoremap <leader>CG :e ~/.vim/plugin/00-general.vim<cr>
     54 nnoremap <leader>CP :e ~/.vim/plugins.vim<cr>
     55 nnoremap <leader>T :e ~/doc/todo.md<cr>
     56 nnoremap <leader>B :e $BIB \| :windo normal G<cr>
     57 
     58 nnoremap <leader>r :read !scholarref<space>
     59 
     60 " insert date and time
     61 nnoremap <leader>D :read !date +"\# \%Y-\%m-\%d \%T \%Z (\%z UTC)"<cr>
     62 
     63 " toggle x mark in checklist fields
     64 nnoremap <leader>X :s/\[[x ]\]/\=submatch(0) == '[x]' ? '[ ]': '[x]'/<cr>:noh<cr>
     65 
     66 if exists(':tnoremap')
     67     " escape from terminal mode
     68     tnoremap <Esc> <C-\><C-n>
     69 
     70     " send escape to terminal
     71     tnoremap <M-[> <Esc>
     72     tnoremap <C-v><Esc> <Esc>
     73 
     74     " navigate away from terminals
     75     tnoremap <C-h> <C-\><C-n><C-w>h
     76     tnoremap <C-j> <C-\><C-n><C-w>j
     77     tnoremap <C-k> <C-\><C-n><C-w>k
     78     tnoremap <C-l> <C-\><C-n><C-w>l
     79 end
     80 
     81 " launch terminal in current window
     82 nnoremap <leader><cr> :terminal<cr>
     83 
     84 " bindings to fugitive
     85 nnoremap <leader>ga :Gwrite<cr>
     86 nnoremap <leader>gm :Gmove
     87 nnoremap <leader>gb :Gblame<cr>
     88 nnoremap <leader>gw :Gbrowse<cr>
     89 nnoremap <leader>gs :Gstatus<cr>
     90 nnoremap <leader>gc :Gcommit -v -S<cr>
     91 nnoremap <leader>gp :Gpush<cr>
     92 nnoremap <leader>gP :Gpull<cr>
     93 
     94 " Use home row keys as Esc
     95 inoremap jk <Esc>
     96 
     97 " using fzf.vim
     98 augroup FzfBinds
     99     autocmd VimEnter * if exists(":Buffers") |
    100                 \ exe "nnoremap <leader><leader> :Rg<cr>" |
    101                 \ exe "nnoremap <leader>o :History<cr>" |
    102                 \ exe "nnoremap <leader>, :Buffers<cr>" |
    103                 \ exe "nnoremap <leader>f :Files<cr>" |
    104                 \ exe "nnoremap <leader>F :GFiles<cr>" |
    105                 \ exe "nnoremap <leader>l :Lines<cr>" |
    106                 \ exe "nnoremap <leader>t :Tags<cr>" |
    107                 \ else |
    108                 \ exe "nnoremap <leader>o :browse oldfiles<cr>" |
    109                 \ exe "nnoremap <leader>, :b <c-d>" |
    110                 \ exe "nnoremap <leader>f :e <c-d>" |
    111                 \ endif
    112 augroup end
    113 
    114 " ALE navigation
    115 nnoremap <silent> [W :ALEFirst<cr>
    116 nnoremap <silent> [w :ALEPreviousWrap<cr>
    117 nnoremap <silent> ]w :ALENextWrap<cr>
    118 nnoremap <silent> ]W :ALELast<cr>
    119 
    120 " cycle through quickfix items
    121 nnoremap <silent> ]c :cnext<cr>
    122 nnoremap <silent> [c :cprevious<cr>
    123 
    124 " Add completion bindings (cycle with C-n, C-p), see :h ins-completion
    125 " <C-x><C-l>: while line
    126 " <C-x><C-n>: keywords in current file
    127 " <C-x><C-i>: keywords in current and included files
    128 " <C-x><C-k>: keywords in dictionary (:set dictionary)
    129 " <C-x><C-t>: keywords in thesaurus (not functional)
    130 " <C-x><C-]>: tags
    131 " <C-x><C-f>: file names
    132 " <C-x><C-d>: definitions or macros
    133 " <C-x><C-v>: vim command-line
    134 " <C-x><C-v>: omni completion
    135 " <C-x>s:     spelling suggestions
    136 
    137 " show as presentation in sent
    138 nnoremap <silent><F7> :w!<cr>:Start! sent <c-r>%<cr><cr>
    139 
    140 " save current session
    141 " (open with `vim -S <sessionname>.vim` or :source <sessionname>
    142 nnoremap <leader>S :mksession! <c-r>%.session.vim
    143 
    144 " analyze written text with statistics and neural network
    145 nnoremap <leader>L :w<cr>:cexpr system('languagetool-vim ' . shellescape(expand('%')))<cr>