init.vim 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. " packadd quickscope
  2. execute 'luafile ' . stdpath('config') . '/lua/settings.lua'
  3. function! s:manageEditorSize(...)
  4. let count = a:1
  5. let to = a:2
  6. for i in range(1, count ? count : 1)
  7. call VSCodeNotify(to == 'increase' ? 'workbench.action.increaseViewSize' : 'workbench.action.decreaseViewSize')
  8. endfor
  9. endfunction
  10. function! s:vscodeCommentary(...) abort
  11. if !a:0
  12. let &operatorfunc = matchstr(expand('<sfile>'), '[^. ]*$')
  13. return 'g@'
  14. elseif a:0 > 1
  15. let [line1, line2] = [a:1, a:2]
  16. else
  17. let [line1, line2] = [line("'["), line("']")]
  18. endif
  19. call VSCodeCallRange("editor.action.commentLine", line1, line2, 0)
  20. endfunction
  21. function! s:openVSCodeCommandsInVisualMode()
  22. normal! gv
  23. let visualmode = visualmode()
  24. if visualmode == "V"
  25. let startLine = line("v")
  26. let endLine = line(".")
  27. call VSCodeNotifyRange("workbench.action.showCommands", startLine, endLine, 1)
  28. else
  29. let startPos = getpos("v")
  30. let endPos = getpos(".")
  31. call VSCodeNotifyRangePos("workbench.action.showCommands", startPos[1], endPos[1], startPos[2], endPos[2], 1)
  32. endif
  33. endfunction
  34. function! s:openWhichKeyInVisualMode()
  35. normal! gv
  36. let visualmode = visualmode()
  37. if visualmode == "V"
  38. let startLine = line("v")
  39. let endLine = line(".")
  40. call VSCodeNotifyRange("whichkey.show", startLine, endLine, 1)
  41. else
  42. let startPos = getpos("v")
  43. let endPos = getpos(".")
  44. call VSCodeNotifyRangePos("whichkey.show", startPos[1], endPos[1], startPos[2], endPos[2], 1)
  45. endif
  46. endfunction
  47. " Better Navigation
  48. nnoremap <silent> <C-j> :call VSCodeNotify('workbench.action.navigateDown')<CR>
  49. xnoremap <silent> <C-j> :call VSCodeNotify('workbench.action.navigateDown')<CR>
  50. nnoremap <silent> <C-k> :call VSCodeNotify('workbench.action.navigateUp')<CR>
  51. xnoremap <silent> <C-k> :call VSCodeNotify('workbench.action.navigateUp')<CR>
  52. nnoremap <silent> <C-h> :call VSCodeNotify('workbench.action.navigateLeft')<CR>
  53. xnoremap <silent> <C-h> :call VSCodeNotify('workbench.action.navigateLeft')<CR>
  54. nnoremap <silent> <C-l> :call VSCodeNotify('workbench.action.navigateRight')<CR>
  55. xnoremap <silent> <C-l> :call VSCodeNotify('workbench.action.navigateRight')<CR>
  56. nnoremap gr <Cmd>call VSCodeNotify('editor.action.goToReferences')<CR>
  57. " Bind C-/ to vscode commentary since calling from vscode produces double comments due to multiple cursors
  58. xnoremap <expr> <C-/> <SID>vscodeCommentary()
  59. nnoremap <expr> <C-/> <SID>vscodeCommentary() . '_'
  60. nnoremap <silent> <C-w>_ :<C-u>call VSCodeNotify('workbench.action.toggleEditorWidths')<CR>
  61. nnoremap <silent> <Space> :call VSCodeNotify('whichkey.show')<CR>
  62. xnoremap <silent> <Space> :<C-u>call <SID>openWhichKeyInVisualMode()<CR>
  63. xnoremap <silent> <C-P> :<C-u>call <SID>openVSCodeCommandsInVisualMode()<CR>
  64. xmap gc <Plug>VSCodeCommentary
  65. nmap gc <Plug>VSCodeCommentary
  66. omap gc <Plug>VSCodeCommentary
  67. nmap gcc <Plug>VSCodeCommentaryLine
  68. " Simulate same TAB behavior in VSCode
  69. nmap <Tab> :Tabnext<CR>
  70. nmap <S-Tab> :Tabprev<CR>