Hans Martin преди 2 години
родител
ревизия
ba8c6f399c
променени са 3 файла, в които са добавени 68 реда и са изтрити 44 реда
  1. 12 0
      .config/nvim/README.md
  2. 11 44
      .config/nvim/init.vim
  3. 45 0
      .config/nvim/lua/init.lua

+ 12 - 0
.config/nvim/README.md

@@ -0,0 +1,12 @@
+# Neovim Settings
+
+
+## Tags, LSP & Co
+
+Keybindings:
+
+- Shift-K (normal mode) to get hover help msg
+- gd: goto definition (use C-t / C-o to get back to function)
+- gi: goto implementation (won't work for python)
+- gt: goto type definition (e.g. structs in nim)
+- <leader>r: rename variable (will rename all variables that make sense)

+ 11 - 44
.config/nvim/init.vim

@@ -32,11 +32,16 @@ call plug#begin('~/.vim/plugged')
     Plug 'tpope/vim-fugitive'                               " Git for Vim
     Plug 'zah/nim.vim'                                      " Nim Plugin
     Plug 'neovim/nvim-lspconfig'                            " Official Language Server Protocol
-    Plug 'nvim-lua/completion-nvim'
+    " All the lua completion plugins
+    Plug 'hrsh7th/nvim-cmp', {'branch': 'main'}
+    Plug 'hrsh7th/cmp-nvim-lsp', {'branch': 'main'}
+    Plug 'hrsh7th/cmp-buffer', {'branch': 'main'}
+    Plug 'hrsh7th/cmp-path', {'branch': 'main'}
+
     Plug 'nvim-lua/plenary.nvim'
     Plug 'nvim-telescope/telescope.nvim'
     Plug 'catppuccin/nvim', {'as': 'catppuccin', 'branch':'main'}
-    Plug 'neoclide/coc.nvim', {'branch': 'release'}          " Testing
+    "Plug 'neoclide/coc.nvim', {'branch': 'release'}          " Testing
     Plug 'chriskempson/base16-vim'
 
 call plug#end()
@@ -49,7 +54,6 @@ lua require('init')
 
 " Color Settings
 colorscheme wal             " using the wal colorscheme
-"colorscheme catppuccin      " using the wal colorscheme
 set mouse=a                 " for moving splits with the mouse
 
 " Encoding
@@ -148,29 +152,16 @@ let g:lightline = {
       \ }
 
 " FZF - Best Tool ever
-nnoremap <C-t> :Tags<CR>
 nnoremap <C-b> :Telescope buffers<CR>
 nnoremap <C-n> :Telescope find_files<CR>
 
-" Nerdtree (tmp replacement with Vifm
-nnoremap <C-t> :NERDTreeToggle<CR>
-
 " Map the Python Evaluation into the vim-expression command(Q)
 nnoremap Q :EvalPython <CR>
 let g:il_append=1
 let g:il_use_nextline=0
 
 
-" UltiSnips (Ancient, but could come in handy at some day)
-"let g:UltiSnipsExpandTrigger = '<tab>'
-let g:UltiSnipsExpandTrigger = '<c-s>'
-let g:UltiSnipsJumpForwardTrigger = '<tab>'
-let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
-let g:UltiSnipsSnippetsDir='~/.vim/UltiSnips/'
-
-
 " Goyo Configuration
-
 let g:goyo_width=100
 let g:goyo_height=100
 
@@ -276,33 +267,9 @@ endif
 
 " -----[ Completion ]----- "
 
-" Use <Tab> and <S-Tab> to navigate through popup menu
-"inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
-"inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
-" imap <silent> <c-space> :<Plug>(completion_trigger)
-
-" Set completeopt to have a better completion experience
-set completeopt=menuone,noinsert,noselect
-
-" Avoid showing message extra message when using completion
-set shortmess+=c
-let g:completion_trigger_character = ['.', '::']
-
-
-
-" -----[ COC ]----- "
-set signcolumn=number
-
-" use <tab> for trigger completion and navigate to the next complete item
-function! CheckBackspace() abort
-  let col = col('.') - 1
-  return !col || getline('.')[col - 1]  =~# '\s'
-endfunction
+" --> Completion is handled in `init.lua`
 
-inoremap <silent><expr> <Tab>
-      \ coc#pum#visible() ? coc#pum#next(1) :
-      \ CheckBackspace() ? "\<Tab>" :
-      \ coc#refresh()
+" LSP / Completion Stuff
+" keep the left column for hinte.g. structs in nim)
+set signcolumn=yes
 
-inoremap <expr> <Tab> coc#pum#visible() ? coc#pum#next(1) : "\<Tab>"
-inoremap <expr> <S-Tab> coc#pum#visible() ? coc#pum#prev(1) : "\<S-Tab>"

+ 45 - 0
.config/nvim/lua/init.lua

@@ -0,0 +1,45 @@
+local nvim_lsp = require "lspconfig"
+local protocol = require "vim.lsp.protocol"
+
+-- Set up lspconfig.
+local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
+
+
+--- the on-attach function that is called for all Language Servers
+local on_attach = function(client, bufnr)
+    vim.keymap.set("n", "K", vim.lsp.buf.hover, {buffer = 0})
+    vim.keymap.set("n", "gd", vim.lsp.buf.definition, {buffer = 0})
+    vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, {buffer = 0})
+    vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {buffer = 0})
+    vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, {buffer = 0})
+end
+
+require('lspconfig')['pylsp'].setup {
+    on_attach= on_attach,
+    capabilities = capabilities
+}
+
+require('lspconfig')['nimls'].setup {
+    on_attach= on_attach,
+    capabilities = capabilities
+}
+
+--- Completion Stuff
+
+vim.opt.completeopt={"menu", "menuone", "noinsert" ,"noselect"}
+
+local cmp = require'cmp'
+
+cmp.setup({
+    mapping = {
+      ['<C-b>'] = cmp.mapping.scroll_docs(-4),
+      ['<C-f>'] = cmp.mapping.scroll_docs(4),
+      ['<C-Space>'] = cmp.mapping.complete(),
+      ['<C-e>'] = cmp.mapping.abort(),
+      ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
+    },
+    sources = cmp.config.sources({
+      { name = 'nvim_lsp' },
+    })
+})
+