init.vim 4.4 KB

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