settings.vim 5.1 KB

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