From da4f05613c3d6a0825e26e0d807261dbb708bf61 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 23 Jun 2022 10:45:58 +0300 Subject: [PATCH] configure nvim via nix --- nix/home.nix | 2 +- nix/progs/nvim.nix | 37 ------------ nix/progs/nvim/coc.vim | 42 +++++++++++++ nix/progs/nvim/coc_settings.nix | 24 ++++++++ nix/progs/nvim/config.vim | 99 +++++++++++++++++++++++++++++++ nix/progs/nvim/custom_plugins.nix | 12 ++++ nix/progs/nvim/default.nix | 82 +++++++++++++++++++++++++ nix/progs/nvim/nvim_nightly.nix | 17 ++++++ nix/progs/nvim/plugins.vim | 32 ++++++++++ 9 files changed, 309 insertions(+), 38 deletions(-) delete mode 100644 nix/progs/nvim.nix create mode 100644 nix/progs/nvim/coc.vim create mode 100644 nix/progs/nvim/coc_settings.nix create mode 100644 nix/progs/nvim/config.vim create mode 100644 nix/progs/nvim/custom_plugins.nix create mode 100644 nix/progs/nvim/default.nix create mode 100644 nix/progs/nvim/nvim_nightly.nix create mode 100644 nix/progs/nvim/plugins.vim diff --git a/nix/home.nix b/nix/home.nix index b800400..dcf0fa9 100644 --- a/nix/home.nix +++ b/nix/home.nix @@ -10,7 +10,7 @@ in ./progs/git.nix ./progs/pass.nix ./progs/himalaya.nix - ./progs/nvim.nix + ./progs/nvim ./progs/exa.nix ./progs/zoxide.nix ./progs/hledger.nix diff --git a/nix/progs/nvim.nix b/nix/progs/nvim.nix deleted file mode 100644 index e451b22..0000000 --- a/nix/progs/nvim.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ lib, config, pkgs, ... }: - -with lib; - -let - cfg = config.progs.nvim; - bin = "nvim"; -in -{ - options.progs.nvim = { - enable = mkOption { - type = types.bool; - default = false; - description = "Add and configure exa, a modern replacement for ls"; - }; - - default = mkOption { - type = types.bool; - default = false; - description = "Set neovim as default editor"; - }; - }; - - config = mkIf cfg.enable { - # TODO: install and configure neovim from home-manager - - home.sessionVariables = mkIf cfg.default { - EDITOR = bin; - }; - - programs.zsh.shellAliases = mkIf config.shell.zsh.enable { - vi = bin; - vim = bin; - }; - }; -} - diff --git a/nix/progs/nvim/coc.vim b/nix/progs/nvim/coc.vim new file mode 100644 index 0000000..b5edd79 --- /dev/null +++ b/nix/progs/nvim/coc.vim @@ -0,0 +1,42 @@ +" Smaller updatetime for CursorHold & CursorHoldI +set updatetime=300 + +" don't give |ins-completion-menu| messages. +set shortmess+=c + +" always show signcolumns +set signcolumn=yes + +" Some server have issues with backup files, see coc#649 +set nobackup +set nowritebackup + +" Better display for messages +set cmdheight=2 + +" Use for trigger completion. +inoremap coc#refresh() + +" Use for confirm completion, `u` means break undo chain at current +" position. Coc only does snippet and additional edit on confirm. +inoremap pumvisible() ? "\" : "\u\" + +" Use `[g` and `]g` for navigate diagnostics +nmap [g (coc-diagnostic-prev) +nmap ]g (coc-diagnostic-next) + +" Remap keys for gotos +nmap gd (coc-definition) +nmap gt (coc-type-definition) +nmap gi (coc-implementation) +nmap gr (coc-references) + +" Remap for do code action of current line +nmap la (coc-codeaction) + +" Remap for rename current word +nmap ln (coc-rename) + +" Remap for do action format +nnoremap F :call CocAction('format') + diff --git a/nix/progs/nvim/coc_settings.nix b/nix/progs/nvim/coc_settings.nix new file mode 100644 index 0000000..fe41bad --- /dev/null +++ b/nix/progs/nvim/coc_settings.nix @@ -0,0 +1,24 @@ +{ + languageserver = { + nix = { + command = "rnix-lsp"; + filetypes = ["nix"]; + }; + + haskell = { + command = "haskell-language-server-wrapper"; + args = ["--lsp"]; + rootPatterns = [ + "stack.yaml" + ".cabal" + "cabal.project" + "package.yaml" + ]; + filetypes = [ + "hs" + "lhs" + "haskell" + ]; + }; + }; +} diff --git a/nix/progs/nvim/config.vim b/nix/progs/nvim/config.vim new file mode 100644 index 0000000..638f453 --- /dev/null +++ b/nix/progs/nvim/config.vim @@ -0,0 +1,99 @@ +" Basic settings {{{ +filetype off + +" Leaders +let g:mapleader = ',' +let g:maplocalleader = '-' + +" Better Unix support +set viewoptions=folds,options,cursor,unix,slash +set encoding=utf-8 + +" True color support +set termguicolors + +" Theme (required plugin 'material-vim') +"let g:material_theme_style = 'default' | 'palenight' | 'ocean' | 'lighter' | 'darker' | 'default-community' | 'palenight-community' | 'ocean-community' | 'lighter-community' | 'darker-community' +let g:material_theme_style = 'ocean-community' +let g:lightline = { 'colorscheme': 'material_vim' } +colorscheme material + +" Other options +syntax on +set backspace=2 +set laststatus=2 +set noshowmode + +" Tabs as spaces +set expandtab +set tabstop=2 +set softtabstop=2 +set shiftwidth=2 + +" Clear search highlighting +nnoremap :nohlsearch + +" Fixes broken cursor on Linux +set guicursor= + +" General editor options +set hidden " Hide files when leaving them. +set number " Show line numbers. +set numberwidth=1 " Minimum line number column width. +set cmdheight=2 " Number of screen lines to use for the commandline. +set textwidth=0 " Lines length limit (0 if no limit). +set linebreak " Don't cut lines in the middle of a work. +set showmatch " Show matching parenthesis. +set matchtime=2 " Time during which the matching parenthesis is shown. +set formatoptions=jtcrq " Sensible default line auto cutting and formatting. +set listchars=tab:▸\ ,eol:¬ " Invisible characters representation when :set list. +set clipboard=unnamedplus " Copy/Past to/from clipboard +set cursorline " Highlight line cursor is currently on +set completeopt+=noinsert " Select the first item of popup menu automatically without inserting it + +" Search +set incsearch " Incremental search. +set ignorecase " Case insensitive. +set smartcase " Case insensitive if no uppercase letter in pattern, case sensitive otherwise + +" Spell check for markdown files +au BufNewFile,BufRead *.md set spell + +" Disable arrow keys and page up / down +noremap +noremap +noremap +noremap +inoremap +inoremap +inoremap +inoremap +vnoremap +vnoremap +vnoremap +vnoremap +noremap +inoremap +vnoremap +noremap +inoremap +vnoremap + +" Disable mouse / touchpad (only in vim) +set mouse=nicr +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap +inoremap + +" Incremental substitutin +set inccommand=split + diff --git a/nix/progs/nvim/custom_plugins.nix b/nix/progs/nvim/custom_plugins.nix new file mode 100644 index 0000000..a39f5ea --- /dev/null +++ b/nix/progs/nvim/custom_plugins.nix @@ -0,0 +1,12 @@ +{ buildVimPlugin }: + +{ + material-vim = buildVimPlugin { + name = "material-vim"; + src = builtins.fetchTarball { + name = "material-vim-2021-12-10"; + url = "https://github.com/kaicataldo/material.vim/archive/445534b2db7f7ec3dc088eae21c86ff0e9bb19de.tar.gz"; + sha256 = "1lwlr6haj1damzmk6i6a1la7vql4y1wmb62iqvm6xgy2svr0s36i"; + }; + }; +} diff --git a/nix/progs/nvim/default.nix b/nix/progs/nvim/default.nix new file mode 100644 index 0000000..d1c3824 --- /dev/null +++ b/nix/progs/nvim/default.nix @@ -0,0 +1,82 @@ +{ lib, config, pkgs, ... }: + +with lib; + +let + cfg = config.progs.nvim; + + customPlugins = pkgs.callPackage ./custom_plugins.nix { + inherit (pkgs.vimUtils) buildVimPlugin; + }; + + plugins = pkgs.vimPlugins // customPlugins; + + myVimPlugins = with plugins; [ + coc-nvim # LSP client + autocompletion plugin + coc-tsserver # typescript LSP + coc-eslint # eslint LSP + + editorconfig-vim # use project .editorconfig to configure editor + lightline-vim # configurable status line + material-vim # modern theme with true colors support + vim-nix # nix support + vim-easymotion # highlights keys to move quickly + nerdtree # tree explorer + nerdtree-git-plugin # shows files git status on the NerdTree + neoformat # formating code + nvim-treesitter # treesitter configurations and abstraction layer + ]; + + # Additional language servers that we should install mannually + lspPackages = with pkgs; [ + rnix-lsp + ]; + + baseConfig = builtins.readFile ./config.vim; + pluginsConfig = builtins.readFile ./plugins.vim; + cocConfig = builtins.readFile ./coc.vim; + cocSettings = builtins.toJSON (import ./coc_settings.nix); + + vimConfig = baseConfig + pluginsConfig + cocConfig; +in +{ + options.progs.nvim = { + enable = mkOption { + type = types.bool; + default = false; + description = "Add and configure exa, a modern replacement for ls"; + }; + + default = mkOption { + type = types.bool; + default = false; + description = "Set neovim as default editor"; + }; + }; + + config = mkIf cfg.enable { + home.packages = lspPackages; + + programs.neovim = { + enable = true; + extraConfig = vimConfig; + plugins = myVimPlugins; + viAlias = true; + vimAlias = true; + }; + + xdg.configFile = { + "nvim/coc-settings.json".text = cocSettings; + }; + + # home.sessionVariables = mkIf cfg.default { + # EDITOR = bin; + # }; + + # programs.zsh.shellAliases = mkIf config.shell.zsh.enable { + # vi = bin; + # vim = bin; + # }; + }; +} + diff --git a/nix/progs/nvim/nvim_nightly.nix b/nix/progs/nvim/nvim_nightly.nix new file mode 100644 index 0000000..1c3ec6d --- /dev/null +++ b/nix/progs/nvim/nvim_nightly.nix @@ -0,0 +1,17 @@ +{ pkgs }: + +pkgs.neovim-unwrapped.overrideAttrs ( + old: { + name = "neovim-nightly"; + version = "nightly"; + + src = pkgs.fetchFromGitHub { + owner = "neovim"; + repo = "neovim"; + rev = "f17d88c47a6a647f2230a61e7cd952926abc4473"; + sha256 = "0lgbf90sbachdag1zm9pmnlbn35964l3khs27qy4462qzpqyi9fi"; + }; + + buildInputs = old.buildInputs ++ [ pkgs.tree-sitter ]; + } +) diff --git a/nix/progs/nvim/plugins.vim b/nix/progs/nvim/plugins.vim new file mode 100644 index 0000000..be6dda7 --- /dev/null +++ b/nix/progs/nvim/plugins.vim @@ -0,0 +1,32 @@ +" Nerdtree + +noremap nt :NERDTreeToggle +noremap nf :NERDTreeFind + +let g:NERDTreeDirArrowExpandable = '▸' +let g:NERDTreeDriArrowCollapsible = '▾' + +let g:NERDTreeMiniamlUI = 1 +let g:NERDTreeDirArrows = 1 + +" Nerdtree git plugin symbols +let g:NERDTreeGitStatusIndicatorMapCustom = { + \ "Modified" : "ᵐ", + \ "Staged" : "ˢ", + \ "Untracked" : "ᵘ", + \ "Renamed" : "ʳ", + \ "Unmerged" : "ᶴ", + \ "Deleted" : "ˣ", + \ "Dirty" : "˜", + \ "Clean" : "ᵅ", + \ "Unknown" : "?" + \ } + +" NeoFormat +let g:neoformat_try_node_exe = 1 +let g:neoformat_only_msg_on_error = 1 +let g:neoformat_enabled_markdown = ["denofmt"] +aug fmt + au! + au BufWritePre * try | undojoin | Neoformat | catch /E790/ | Neoformat | endtry +aug END