From 832b55fa23ae1e49bd805b6e0e9f5d20b08f46a0 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Mon, 28 Jun 2021 11:39:37 -0400 Subject: less vimscript --- utils/lv-vscode/init.vim | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 utils/lv-vscode/init.vim (limited to 'utils/lv-vscode/init.vim') diff --git a/utils/lv-vscode/init.vim b/utils/lv-vscode/init.vim new file mode 100644 index 00000000..1aa30934 --- /dev/null +++ b/utils/lv-vscode/init.vim @@ -0,0 +1,84 @@ +" packadd quickscope + +execute 'luafile ' . stdpath('config') . '/lua/settings.lua' + +function! s:manageEditorSize(...) + let count = a:1 + let to = a:2 + for i in range(1, count ? count : 1) + call VSCodeNotify(to == 'increase' ? 'workbench.action.increaseViewSize' : 'workbench.action.decreaseViewSize') + endfor +endfunction + +function! s:vscodeCommentary(...) abort + if !a:0 + let &operatorfunc = matchstr(expand(''), '[^. ]*$') + return 'g@' + elseif a:0 > 1 + let [line1, line2] = [a:1, a:2] + else + let [line1, line2] = [line("'["), line("']")] + endif + + call VSCodeCallRange("editor.action.commentLine", line1, line2, 0) +endfunction + +function! s:openVSCodeCommandsInVisualMode() + normal! gv + let visualmode = visualmode() + if visualmode == "V" + let startLine = line("v") + let endLine = line(".") + call VSCodeNotifyRange("workbench.action.showCommands", startLine, endLine, 1) + else + let startPos = getpos("v") + let endPos = getpos(".") + call VSCodeNotifyRangePos("workbench.action.showCommands", startPos[1], endPos[1], startPos[2], endPos[2], 1) + endif +endfunction + +function! s:openWhichKeyInVisualMode() + normal! gv + let visualmode = visualmode() + if visualmode == "V" + let startLine = line("v") + let endLine = line(".") + call VSCodeNotifyRange("whichkey.show", startLine, endLine, 1) + else + let startPos = getpos("v") + let endPos = getpos(".") + call VSCodeNotifyRangePos("whichkey.show", startPos[1], endPos[1], startPos[2], endPos[2], 1) + endif +endfunction + +" Better Navigation +nnoremap :call VSCodeNotify('workbench.action.navigateDown') +xnoremap :call VSCodeNotify('workbench.action.navigateDown') +nnoremap :call VSCodeNotify('workbench.action.navigateUp') +xnoremap :call VSCodeNotify('workbench.action.navigateUp') +nnoremap :call VSCodeNotify('workbench.action.navigateLeft') +xnoremap :call VSCodeNotify('workbench.action.navigateLeft') +nnoremap :call VSCodeNotify('workbench.action.navigateRight') +xnoremap :call VSCodeNotify('workbench.action.navigateRight') + +nnoremap gr call VSCodeNotify('editor.action.goToReferences') + +" Bind C-/ to vscode commentary since calling from vscode produces double comments due to multiple cursors +xnoremap vscodeCommentary() +nnoremap vscodeCommentary() . '_' + +nnoremap _ :call VSCodeNotify('workbench.action.toggleEditorWidths') + +nnoremap :call VSCodeNotify('whichkey.show') +xnoremap :call openWhichKeyInVisualMode() + +xnoremap :call openVSCodeCommandsInVisualMode() + +xmap gc VSCodeCommentary +nmap gc VSCodeCommentary +omap gc VSCodeCommentary +nmap gcc VSCodeCommentaryLine + +" Simulate same TAB behavior in VSCode +nmap :Tabnext +nmap :Tabprev -- cgit v1.2.3