From ad8fa192f9792237dcda118b442047838fe4be01 Mon Sep 17 00:00:00 2001 From: Rouven Seifert Date: Tue, 21 Feb 2023 17:59:05 +0100 Subject: [PATCH] nvim configuraion --- flake.lock | 24 ++-- users/rouven/modules/neovim/default.nix | 92 ++------------ users/rouven/modules/neovim/nvim.lua | 153 ++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 95 deletions(-) create mode 100644 users/rouven/modules/neovim/nvim.lua diff --git a/flake.lock b/flake.lock index d973f7d..c028613 100644 --- a/flake.lock +++ b/flake.lock @@ -24,11 +24,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1676892629, - "narHash": "sha256-rlvsqoSBO5dCwfnn7xvImYREidIPJaiFS3b54TZF4pU=", + "lastModified": 1676933022, + "narHash": "sha256-gLghsEHOy2W2ZmSwqNOyj2mSHe9SMpdcbqnoySlZnmY=", "owner": "nix-community", "repo": "home-manager", - "rev": "72ce74d3eae78a6b31538ea7ebe0c1fcf4a10f7a", + "rev": "5e889b385c43a8a72ada5ebc4888bbebb129b438", "type": "github" }, "original": { @@ -47,11 +47,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1676902515, - "narHash": "sha256-tFvDUIWmsEdAWnbwCDCDwcPxcZNGQzPfRpx5tSL/yl0=", + "lastModified": 1676981621, + "narHash": "sha256-kRvteNQ8kkhtyJF4b+CHBDUkleZFxsIxtbCDn7gEK20=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "474ada9267ccb98015991ee9d0d93fbb5da72034", + "rev": "a66ef50469c7a347d27a9afec83db1be70be1c84", "type": "github" }, "original": { @@ -122,11 +122,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1676721149, - "narHash": "sha256-mN2EpTGxxVNnFZLoLWRwh6f7UWhXy4qE+wO2CZyrXps=", + "lastModified": 1676885936, + "narHash": "sha256-ZRKb6zBfTvdCOXI7nGC1L9UWSU5ay2ltxg+f5UIzBOU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5f4e07deb7c44f27d498f8df9c5f34750acf52d2", + "rev": "b69883faca9542d135fa6bab7928ff1b233c167f", "type": "github" }, "original": { @@ -185,11 +185,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1676776227, - "narHash": "sha256-CSBeyGiDMYDw/nmafLfuu0ErVu7rzGoWIQwm2NkQQKY=", + "lastModified": 1676959847, + "narHash": "sha256-KZS6sIsMXiNyN7jW45MrEo95iEXj6nMLKvxgxO181no=", "owner": "Mic92", "repo": "sops-nix", - "rev": "1da7257baa1d6801c45d9d3dedae7ce79c0e6498", + "rev": "2c5828439d718a6cddd9a511997d9ac7626a4aff", "type": "github" }, "original": { diff --git a/users/rouven/modules/neovim/default.nix b/users/rouven/modules/neovim/default.nix index 1ca1850..83b954e 100644 --- a/users/rouven/modules/neovim/default.nix +++ b/users/rouven/modules/neovim/default.nix @@ -1,99 +1,25 @@ { config, pkgs, ... }: { + home.packages = with pkgs; [ + python310Packages.python-lsp-server + ]; programs.neovim = { enable = true; - # defaultEditor = true; why the hell doesn't this work :( vimAlias = true; plugins = with pkgs.vimPlugins; [ nerdtree nerdcommenter - fugitive-gitlab-vim vim-repeat vim-airline fzf-vim dracula-vim vim-nix # this destroys my tab settings, ffs + nvim-lspconfig + nvim-cmp + cmp-buffer + cmp-nvim-lsp + cmp-path ]; - extraConfig = - '' - " basic commands bound to uppercase key - command Q q - command W w - command Wq wq - command WQ wq - - set shiftwidth=4 - set noexpandtab - set preserveindent - set number relativenumber - set tabstop=4 - set smartcase - set colorcolumn=120 - set nowrap - highlight ColorColumn ctermbg=darkgray - - - " beautify indents - :set list lcs=tab:\|\ - - nnoremap ; : - nnoremap : ; - vnoremap ; : - vnoremap : ; - - " set space as leader - nnoremap - let mapleader = " " - - " air-line - let g:airline_powerline_fonts = 1 - - " NERDTree - nnoremap n :NERDTreeFocus :NERDTreeRefreshRoot - " NERDTree autostart" - autocmd VimEnter * NERDTree | wincmd p - - " Close the tab if NERDTree is the only window remaining in it. - autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif - - "remove ex-mode shortcut - nmap Q - - " trigger the fuzzy finder (fzf) - nnoremap f :Files - nnoremap g :GFiles - nnoremap b :Buffers - nnoremap r :Rg - - " keybinds for coc - nnoremap d :CocDiagnostics - - " quickfixlist binds - nnoremap :cnext - nnoremap :cprev - - " locallist binds - nnoremap :lnext - nnoremap :lprev - - " split keybinds - nnoremap s :sp - nnoremap v :vs - - nnoremap h h - nnoremap j j - nnoremap k k - nnoremap l l - - " coloring stuff - let g:dracula_colorterm = 0 - colorscheme dracula - - " better autocompletion menu colors - highlight Pmenu ctermbg=darkgray ctermfg=black - highlight PmenuSel ctermbg=gray ctermfg=black - - ''; }; - + xdg.configFile."nvim/init.lua".source = ./nvim.lua; } diff --git a/users/rouven/modules/neovim/nvim.lua b/users/rouven/modules/neovim/nvim.lua new file mode 100644 index 0000000..dc8ae37 --- /dev/null +++ b/users/rouven/modules/neovim/nvim.lua @@ -0,0 +1,153 @@ +local g = vim.g +local opt = vim.opt +local cmd = vim.cmd +local autocmd = vim.api.nvim_create_autocmd +--local map = vim.api.nvim_set_keymap opt.shiftwidth = 4 +opt.expandtab = false +opt.preserveindent = true +opt.number = true +opt.relativenumber = true +opt.tabstop = 4 +opt.smartcase = true +opt.colorcolumn = { '120' } +opt.wrap = false +cmd('highlight ColorColumn ctermbg=darkgray') + + +local function map(mode, lhs, rhs, opts) + local options = { noremap=true } + if opts then + options = vim.tbl_extend('force', options, opts) + end + vim.keymap.set(mode, lhs, rhs, options) +end + +map({'n', 'v'}, ';', ':') +map({'n', 'v'}, ':', ';') + +-- set space as leader +map('n', '', '') +g.mapleader = " " + +--air-line +g.airline_powerline_fonts = 1 + +--NERDTree +map('n', 'n :NERDTreeFocus', ':NERDTreeRefreshRoot') +--NERDTree autostart" +autocmd('VimEnter', {command = 'NERDTree | wincmd p'}) + +--Close the tab if NERDTree is the only window remaining in it. +autocmd("BufEnter", { + pattern = "*", + command = "if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif" +}) + +-- remove ex-mode shortcut +map('n', 'Q', '') + +--trigger the fuzzy finder (fzf) +map('n', 'f', ":Files") +map('n', 'g', ":GFiles") +map('n', 'b', ":Buffers") +map('n', 'r', ":Rg") + +--quickfixlist binds +map('n', '', ":cnext") +map('n', '', ":cprev") + +--locallist binds +map('n', '', ":lnext") +map('n', '', ":lprev") + +--split keybinds +map('n', 's', ":sp") +map('n', 'v', ":vs") + +map('n', 'h', "h") +map('n', 'j', "j") +map('n', 'k', "k") +map('n', 'l', "l") + +--coloring stuff +g.dracula_colorterm = 0 +cmd('colorscheme dracula') + +local lsp = require("lspconfig") + +vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) +end + + +lsp.pylsp.setup { + on_attach = on_attach +} + + +local cmp = require("cmp") + +cmp.setup { + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping.confirm({ select = false }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { 'i', 's' }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'path' } + }, { + { + name = 'buffer', + option = { + keyword_pattern = [[\k\+]], -- allow unicode multibyte characters + }, + } + }), +} +