Chris vor 4 Jahren
Ursprung
Commit
570e143562
3 geänderte Dateien mit 156 neuen und 36 gelöschten Zeilen
  1. 14 2
      README.md
  2. 37 34
      init.lua
  3. 105 0
      lua/nv-vscode/init.vim

+ 14 - 2
README.md

@@ -22,19 +22,31 @@ cd ~
 sudo rm -r neovim
 ```
 
+## VSCode support
+
+After installing the Neovim extension in VSCode
+
+Point the nvim path to your `nvim` binary
+
+Point your `init.vim` path to:
+
+```vim
+$HOME/.config/nvim/lua/nv-vscode/init.vim
+```
+
 ## TODO
 
 **HIGH PRIORITY**
-- add vscode support
 - snippet support
+- update whichkey bindings
 - add lots of lsp
 - react commenting
 - better autoimport
 - toggle virtual text diagnostics
 
 **LOW PRIORITY**
+- improve VSCode support
 - move language servers not installed with npm to neovim local share location
-- update whichkey bindings
 - more handsome/modern galaxyline
 - potentially custom colorscheme
 - look into autoinstall lsp

+ 37 - 34
init.lua

@@ -1,37 +1,40 @@
--- General mappings
-require('plugins')
-require('keymappings')
-require('settings')
-require('colorscheme')
+if vim.g.vscode then
+  vim.cmd('source ~/.config/nvim/lua/nv-vscode/init.vim')
+else
+  -- General mappings
+  require('plugins')
+  require('keymappings')
+  require('settings')
+  require('colorscheme')
 
--- Plugins
-require('nv-colorizer')
-require('nv-nvimtree')
-require('nv-treesitter')
-require('nv-galaxyline')
-require('nv-barbar')
-require('nv-gitsigns')
-require('nv-nvim-autopairs')
-require('nv-kommentary')
-require('nv-quickscope')
-require('nv-rnvimr')
-require('nv-startify')
-require('nv-telescope')
-require('nv-floaterm')
-require('nv-vim-rooter')
-require('nv-lspkind')
-require('nv-hop')
-require('nv-compe')
-require('nv-closetag')
-require('nv-gitblame')
+  -- Plugins
+  require('nv-colorizer')
+  require('nv-nvimtree')
+  require('nv-treesitter')
+  require('nv-galaxyline')
+  require('nv-barbar')
+  require('nv-gitsigns')
+  require('nv-nvim-autopairs')
+  require('nv-kommentary')
+  require('nv-quickscope')
+  require('nv-rnvimr')
+  require('nv-startify')
+  require('nv-telescope')
+  require('nv-floaterm')
+  require('nv-vim-rooter')
+  require('nv-lspkind')
+  require('nv-hop')
+  require('nv-compe')
+  require('nv-closetag')
+  require('nv-gitblame')
 
--- Which Key (Hope to replace with Lua plugin someday)
-vim.cmd('source ~/.config/nvim/lua/nv-whichkey/init.vim')
+  -- Which Key (Hope to replace with Lua plugin someday)
+  vim.cmd('source ~/.config/nvim/lua/nv-whichkey/init.vim')
 
--- LSP
-require('lsp')
-require('utils')
-require('lsp.lua-ls')
-require('lsp.bash-ls')
-require('lsp.js-ts-ls')
-vim.cmd('highlight default link gitblame SpecialComment')
+  -- LSP
+  require('lsp')
+  require('utils')
+  require('lsp.lua-ls')
+  require('lsp.bash-ls')
+  require('lsp.js-ts-ls')
+end

+ 105 - 0
lua/nv-vscode/init.vim

@@ -0,0 +1,105 @@
+" TODO there is a more contemporary version of this file
+" TODO Also some of it is redundant
+"VSCode
+function! s:split(...) abort
+    let direction = a:1
+    let file = a:2
+    call VSCodeCall(direction == 'h' ? 'workbench.action.splitEditorDown' : 'workbench.action.splitEditorRight')
+    if file != ''
+        call VSCodeExtensionNotify('open-file', expand(file), 'all')
+    endif
+endfunction
+
+function! s:splitNew(...)
+    let file = a:2
+    call s:split(a:1, file == '' ? '__vscode_new__' : file)
+endfunction
+
+function! s:closeOtherEditors()
+    call VSCodeNotify('workbench.action.closeEditorsInOtherGroups')
+    call VSCodeNotify('workbench.action.closeOtherEditors')
+endfunction
+
+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('<sfile>'), '[^. ]*$')
+        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
+
+
+command! -complete=file -nargs=? Split call <SID>split('h', <q-args>)
+command! -complete=file -nargs=? Vsplit call <SID>split('v', <q-args>)
+command! -complete=file -nargs=? New call <SID>split('h', '__vscode_new__')
+command! -complete=file -nargs=? Vnew call <SID>split('v', '__vscode_new__')
+command! -bang Only if <q-bang> == '!' | call <SID>closeOtherEditors() | else | call VSCodeNotify('workbench.action.joinAllGroups') | endif
+
+" Better Navigation
+nnoremap <silent> <C-j> :call VSCodeNotify('workbench.action.navigateDown')<CR>
+xnoremap <silent> <C-j> :call VSCodeNotify('workbench.action.navigateDown')<CR>
+nnoremap <silent> <C-k> :call VSCodeNotify('workbench.action.navigateUp')<CR>
+xnoremap <silent> <C-k> :call VSCodeNotify('workbench.action.navigateUp')<CR>
+nnoremap <silent> <C-h> :call VSCodeNotify('workbench.action.navigateLeft')<CR>
+xnoremap <silent> <C-h> :call VSCodeNotify('workbench.action.navigateLeft')<CR>
+nnoremap <silent> <C-l> :call VSCodeNotify('workbench.action.navigateRight')<CR>
+xnoremap <silent> <C-l> :call VSCodeNotify('workbench.action.navigateRight')<CR>
+
+nnoremap gr <Cmd>call VSCodeNotify('editor.action.goToReferences')<CR>
+
+" Bind C-/ to vscode commentary since calling from vscode produces double comments due to multiple cursors
+xnoremap <expr> <C-/> <SID>vscodeCommentary()
+nnoremap <expr> <C-/> <SID>vscodeCommentary() . '_'
+
+nnoremap <silent> <C-w>_ :<C-u>call VSCodeNotify('workbench.action.toggleEditorWidths')<CR>
+
+nnoremap <silent> <Space> :call VSCodeNotify('whichkey.show')<CR>
+xnoremap <silent> <Space> :<C-u>call <SID>openWhichKeyInVisualMode()<CR>
+
+xnoremap <silent> <C-P> :<C-u>call <SID>openVSCodeCommandsInVisualMode()<CR>
+
+xmap gc  <Plug>VSCodeCommentary
+nmap gc  <Plug>VSCodeCommentary
+omap gc  <Plug>VSCodeCommentary
+nmap gcc <Plug>VSCodeCommentaryLine