init.vim 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. " TODO there is a more contemporary version of this file
  2. " TODO Also some of it is redundant
  3. "VSCode
  4. function! s:split(...) abort
  5. let direction = a:1
  6. let file = a:2
  7. call VSCodeCall(direction == 'h' ? 'workbench.action.splitEditorDown' : 'workbench.action.splitEditorRight')
  8. if file != ''
  9. call VSCodeExtensionNotify('open-file', expand(file), 'all')
  10. endif
  11. endfunction
  12. function! s:splitNew(...)
  13. let file = a:2
  14. call s:split(a:1, file == '' ? '__vscode_new__' : file)
  15. endfunction
  16. function! s:closeOtherEditors()
  17. call VSCodeNotify('workbench.action.closeEditorsInOtherGroups')
  18. call VSCodeNotify('workbench.action.closeOtherEditors')
  19. endfunction
  20. function! s:manageEditorSize(...)
  21. let count = a:1
  22. let to = a:2
  23. for i in range(1, count ? count : 1)
  24. call VSCodeNotify(to == 'increase' ? 'workbench.action.increaseViewSize' : 'workbench.action.decreaseViewSize')
  25. endfor
  26. endfunction
  27. function! s:vscodeCommentary(...) abort
  28. if !a:0
  29. let &operatorfunc = matchstr(expand('<sfile>'), '[^. ]*$')
  30. return 'g@'
  31. elseif a:0 > 1
  32. let [line1, line2] = [a:1, a:2]
  33. else
  34. let [line1, line2] = [line("'["), line("']")]
  35. endif
  36. call VSCodeCallRange("editor.action.commentLine", line1, line2, 0)
  37. endfunction
  38. function! s:openVSCodeCommandsInVisualMode()
  39. normal! gv
  40. let visualmode = visualmode()
  41. if visualmode == "V"
  42. let startLine = line("v")
  43. let endLine = line(".")
  44. call VSCodeNotifyRange("workbench.action.showCommands", startLine, endLine, 1)
  45. else
  46. let startPos = getpos("v")
  47. let endPos = getpos(".")
  48. call VSCodeNotifyRangePos("workbench.action.showCommands", startPos[1], endPos[1], startPos[2], endPos[2], 1)
  49. endif
  50. endfunction
  51. function! s:openWhichKeyInVisualMode()
  52. normal! gv
  53. let visualmode = visualmode()
  54. if visualmode == "V"
  55. let startLine = line("v")
  56. let endLine = line(".")
  57. call VSCodeNotifyRange("whichkey.show", startLine, endLine, 1)
  58. else
  59. let startPos = getpos("v")
  60. let endPos = getpos(".")
  61. call VSCodeNotifyRangePos("whichkey.show", startPos[1], endPos[1], startPos[2], endPos[2], 1)
  62. endif
  63. endfunction
  64. command! -complete=file -nargs=? Split call <SID>split('h', <q-args>)
  65. command! -complete=file -nargs=? Vsplit call <SID>split('v', <q-args>)
  66. command! -complete=file -nargs=? New call <SID>split('h', '__vscode_new__')
  67. command! -complete=file -nargs=? Vnew call <SID>split('v', '__vscode_new__')
  68. command! -bang Only if <q-bang> == '!' | call <SID>closeOtherEditors() | else | call VSCodeNotify('workbench.action.joinAllGroups') | endif
  69. " Better Navigation
  70. nnoremap <silent> <C-j> :call VSCodeNotify('workbench.action.navigateDown')<CR>
  71. xnoremap <silent> <C-j> :call VSCodeNotify('workbench.action.navigateDown')<CR>
  72. nnoremap <silent> <C-k> :call VSCodeNotify('workbench.action.navigateUp')<CR>
  73. xnoremap <silent> <C-k> :call VSCodeNotify('workbench.action.navigateUp')<CR>
  74. nnoremap <silent> <C-h> :call VSCodeNotify('workbench.action.navigateLeft')<CR>
  75. xnoremap <silent> <C-h> :call VSCodeNotify('workbench.action.navigateLeft')<CR>
  76. nnoremap <silent> <C-l> :call VSCodeNotify('workbench.action.navigateRight')<CR>
  77. xnoremap <silent> <C-l> :call VSCodeNotify('workbench.action.navigateRight')<CR>
  78. nnoremap gr <Cmd>call VSCodeNotify('editor.action.goToReferences')<CR>
  79. " Bind C-/ to vscode commentary since calling from vscode produces double comments due to multiple cursors
  80. xnoremap <expr> <C-/> <SID>vscodeCommentary()
  81. nnoremap <expr> <C-/> <SID>vscodeCommentary() . '_'
  82. nnoremap <silent> <C-w>_ :<C-u>call VSCodeNotify('workbench.action.toggleEditorWidths')<CR>
  83. nnoremap <silent> <Space> :call VSCodeNotify('whichkey.show')<CR>
  84. xnoremap <silent> <Space> :<C-u>call <SID>openWhichKeyInVisualMode()<CR>
  85. xnoremap <silent> <C-P> :<C-u>call <SID>openVSCodeCommandsInVisualMode()<CR>
  86. xmap gc <Plug>VSCodeCommentary
  87. nmap gc <Plug>VSCodeCommentary
  88. omap gc <Plug>VSCodeCommentary
  89. nmap gcc <Plug>VSCodeCommentaryLine