bindings.vim 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. let mapleader = " "
  2. " move text buffer in visual mode
  3. vnoremap K :m '<-2<CR>gv=gv
  4. vnoremap J :m '>+1<CR>gv=gv
  5. " write and quit easier
  6. nnoremap <Leader>w :w<CR>
  7. nnoremap <Leader>z :wq<CR>
  8. nnoremap <Leader>q :qa<CR>
  9. nnoremap <Leader>e :q<CR>
  10. " windows commands
  11. nnoremap <leader>pv :wincmd v<bar> :Ex <bar> :vertical resize 30<CR>
  12. nnoremap <leader>ps :Rg<CR>
  13. nnoremap <leader>rh :vertical resize +5<CR>
  14. nnoremap <leader>rl :vertical resize -5<CR>
  15. " general custom commands
  16. command D filetype detect
  17. " commands for opening and compiling various document types
  18. command S silent !vshow '%:p'
  19. command C !compile "%"
  20. " general compile button
  21. map <F3> :w<CR>:!compile "%" && pkill -HUP mupdf<CR>
  22. " bibtex extra compiler
  23. map <F2> :w<CR>:!latexmk -pdf "%" && pkill -HUP mupdf<CR>
  24. map <F4> :noh<CR>
  25. map <F5> :set spell!<CR>
  26. map <F6> :w<CR>:!glosscompile "%" && pkill -HUP mupdf<CR>
  27. " jumper
  28. vnoremap <Space><Space> <Esc>/<++><Enter>"_c4l
  29. map <Space><Space> <Esc>/<++><Enter>"_c4l
  30. "copy from / to clipboard
  31. vnoremap <leader>y "+y
  32. vnoremap <leader>Y "+Y
  33. nmap <leader>p "+p
  34. nmap <leader>P "+P
  35. " Use <c-space> to trigger completion.
  36. inoremap <silent><expr> <c-space> coc#refresh()
  37. " Use `[g` and `]g` to navigate diagnostics
  38. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  39. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  40. " Remap keys for gotos
  41. nmap <silent> gd <Plug>(coc-definition)
  42. nmap <silent> gy <Plug>(coc-type-definition)
  43. nmap <silent> gi <Plug>(coc-implementation)
  44. nmap <silent> gr <Plug>(coc-references)
  45. nmap <leader>rn <Plug>(coc-rename)
  46. vmap <leader>f <Plug>(coc-format-selected)
  47. " switch (back and forth) to (and from) the last opened file
  48. nmap <leader>b <c-^><cr>
  49. nmap <leader>f <Plug>(coc-format-selected)
  50. noremap <silent> <Leader>f :Fern . -drawer -reveal=% -toggle -width=35<CR><C-w>=
  51. function! FernInit() abort
  52. nmap <buffer><expr>
  53. \ <Plug>(fern-my-open-expand-collapse)
  54. \ fern#smart#leaf(
  55. \ "\<Plug>(fern-action-open:select)",
  56. \ "\<Plug>(fern-action-expand:stay)",
  57. \ "\<Plug>(fern-action-collapse)",
  58. \ )
  59. nmap <buffer> <CR> <Plug>(fern-my-open-expand-collapse)
  60. nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
  61. nmap <buffer> n <Plug>(fern-action-new-path)
  62. nmap <buffer> d <Plug>(fern-action-remove)
  63. nmap <buffer> m <Plug>(fern-action-move)
  64. nmap <buffer> M <Plug>(fern-action-rename)
  65. nmap <buffer> c <Plug>(fern-action-hidden:toggle)
  66. nmap <buffer> r <Plug>(fern-action-reload)
  67. nmap <buffer> g <Plug>(fern-action-mark:toggle)
  68. nmap <buffer> o <Plug>(fern-action-open)
  69. nmap <buffer> b <Plug>(fern-action-open:split)
  70. nmap <buffer> v <Plug>(fern-action-open:vsplit)
  71. nmap <buffer> h <Plug>(fern-action-collapse)
  72. nmap <buffer> l <Plug>(fern-action-expand:stay)
  73. nmap <silent> <buffer> p <Plug>(fern-action-preview:toggle)
  74. nmap <silent> <buffer> <C-p> <Plug>(fern-action-preview:auto:toggle)
  75. nmap <silent> <buffer> <C-d> <Plug>(fern-action-preview:scroll:down:half)
  76. nmap <silent> <buffer> <C-u> <Plug>(fern-action-preview:scroll:up:half)
  77. nmap <buffer><nowait> < <Plug>(fern-action-leave)
  78. nmap <buffer><nowait> > <Plug>(fern-action-enter)
  79. endfunction
  80. " use (shift-)TAB to autocomplete w/ coc
  81. inoremap <expr> <Tab> coc#pum#visible() ? coc#pum#next(1) : "\<Tab>"
  82. inoremap <expr> <S-Tab> coc#pum#visible() ? coc#pum#prev(1) : "\<S-Tab>"
  83. " use Ctrl + Space to trigger autocomplete box
  84. inoremap <silent><expr> <c-space> coc#refresh()
  85. " Use `:Format` to format current buffer
  86. command! -nargs=0 Format :call CocAction('format')
  87. " Go to tab by number
  88. noremap <leader>1 1gt
  89. noremap <leader>2 2gt
  90. noremap <leader>3 3gt
  91. noremap <leader>4 4gt
  92. noremap <leader>5 5gt
  93. noremap <leader>6 6gt
  94. noremap <leader>7 7gt
  95. noremap <leader>8 8gt
  96. noremap <leader>9 9gt
  97. noremap <leader>0 :tablast<cr>
  98. " Applying codeAction to the selected region.
  99. " Example: `<leader>aap` for current paragraph
  100. xmap <leader>a <Plug>(coc-codeaction-selected)
  101. nmap <leader>a <Plug>(coc-codeaction-selected)
  102. " Remap keys for applying codeAction to the current buffer.
  103. nmap <leader>ac <Plug>(coc-codeaction)
  104. " Apply AutoFix to problem on the current line.
  105. nmap <leader>qf <Plug>(coc-fix-current)
  106. " Run the Code Lens action on the current line.
  107. nmap <leader>cl <Plug>(coc-codelens-action)
  108. " auto center view when walking through searches
  109. nnoremap n nzzzv
  110. nnoremap N Nzzzv
  111. " toggle tag bar
  112. nmap <leader>g :TagbarToggle<CR>
  113. " please write
  114. cmap w!! w !doas tee %
  115. " navigate chunks of current buffer
  116. nmap [h <Plug>(coc-git-prevchunk)
  117. nmap ]h <Plug>(coc-git-nextchunk)
  118. " navigate conflicts of current buffer
  119. nmap [c <Plug>(coc-git-prevconflict)
  120. nmap ]c <Plug>(coc-git-nextconflict)
  121. function! WinMove(key)
  122. let t:curwin = winnr()
  123. exec "wincmd ".a:key
  124. if (t:curwin == winnr())
  125. if (match(a:key,'[jk]'))
  126. wincmd v
  127. else
  128. wincmd s
  129. endif
  130. exec "wincmd ".a:key
  131. endif
  132. endfunction
  133. " smart global buffor / window switching
  134. nnoremap <silent> <C-h> :call WinMove('h')<CR>
  135. nnoremap <silent> <C-j> :call WinMove('j')<CR>
  136. nnoremap <silent> <C-k> :call WinMove('k')<CR>
  137. nnoremap <silent> <C-l> :call WinMove('l')<CR>
  138. " source vim config
  139. nnoremap <Leader>sv :source $XDG_CONFIG_HOME/nvim/init.vim<CR>
  140. nnoremap <leader>l :Telescope live_grep<CR>
  141. nnoremap <leader>t :Telescope git_files<CR>
  142. nnoremap <leader>z :Telescope find_files<CR>
  143. nnoremap <C-s> :Telescope grep_string<CR>
  144. " markdown preview mappings
  145. nmap <leader>mg <Plug>MarkdownPreview
  146. nmap <leader>ms <Plug>MarkdownPreviewStop
  147. nmap <leader>mt <Plug>MarkdownPreviewToggle
  148. " correct whitespace
  149. nnoremap <leader>cw :StripWhitespace<CR>
  150. " move to next / previous trailing whitespace
  151. nnoremap ]w :NextTrailingWhitespace<CR>
  152. nnoremap [w :PrevTrailingWhitespace<CR>
  153. " trigger snippet expand
  154. imap <C-l> <Plug>(coc-snippets-expand)
  155. " select text for visual placeholder of snippet
  156. vmap <C-j> <Plug>(coc-snippets-select)
  157. " jump to next placeholder
  158. let g:coc_snippet_next = '<c-n>'
  159. " jump to previous placeholder
  160. let g:coc_snippet_prev = '<c-b>'
  161. " for both expand and jump (make expand higher priority.)
  162. imap <C-j> <Plug>(coc-snippets-expand-jump)
  163. nnoremap <leader>da :call vimspector#Launch()<CR>
  164. nnoremap <leader>dc :call GotoWindow(g:vimspector_session_windows.code)<CR>
  165. nnoremap <leader>dv :call GotoWindow(g:vimspector_session_windows.variables)<CR>
  166. nnoremap <leader>dw :call GotoWindow(g:vimspector_session_windows.watches)<CR>
  167. nnoremap <leader>ds :call GotoWindow(g:vimspector_session_windows.stack_trace)<CR>
  168. nnoremap <leader>do :call GotoWindow(g:vimspector_session_windows.output)<CR>
  169. nnoremap <leader>di :call AddToWatch()<CR>
  170. nnoremap <leader>dx :call vimspector#Reset()<CR>
  171. nnoremap <leader>dX :call vimspector#ClearBreakpoints()<CR>
  172. nnoremap <S-k> :call vimspector#StepOut()<CR>
  173. nnoremap <S-l> :call vimspector#StepInto()<CR>
  174. nnoremap <S-j> :call vimspector#StepOver()<CR>
  175. nnoremap <leader>d_ :call vimspector#Restart()<CR>
  176. nnoremap <leader>dn :call vimspector#Continue()<CR>
  177. nnoremap <leader>drc :call vimspector#RunToCursor()<CR>
  178. nnoremap <leader>dh :call vimspector#ToggleBreakpoint()<CR>
  179. nnoremap <leader>de :call vimspector#ToggleConditionalBreakpoint()<CR>