configure nvim via nix

This commit is contained in:
Dmitriy Pleshevskiy 2022-06-23 10:45:58 +03:00
parent a59f68122f
commit da4f05613c
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
9 changed files with 309 additions and 38 deletions

View file

@ -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

View file

@ -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;
};
};
}

42
nix/progs/nvim/coc.vim Normal file
View file

@ -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 <c-space> for trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> for confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Use `[g` and `]g` for navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gt <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Remap for do code action of current line
nmap <leader>la <Plug>(coc-codeaction)
" Remap for rename current word
nmap <leader>ln <Plug>(coc-rename)
" Remap for do action format
nnoremap <silent> F :call CocAction('format')<CR>

View file

@ -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"
];
};
};
}

99
nix/progs/nvim/config.vim Normal file
View file

@ -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 <C-z> :nohlsearch<CR>
" 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 <Up> <nop>
noremap <Down> <nop>
noremap <Left> <nop>
noremap <Right> <nop>
inoremap <Up> <nop>
inoremap <Down> <nop>
inoremap <Left> <nop>
inoremap <Right> <nop>
vnoremap <Up> <nop>
vnoremap <Down> <nop>
vnoremap <Left> <nop>
vnoremap <Right> <nop>
noremap <PageUp> <nop>
inoremap <PageUp> <nop>
vnoremap <PageUp> <nop>
noremap <PageDown> <nop>
inoremap <PageDown> <nop>
vnoremap <PageDown> <nop>
" Disable mouse / touchpad (only in vim)
set mouse=nicr
inoremap <ScrollWheelUp> <nop>
inoremap <S-ScrollWheelUp> <nop>
inoremap <C-ScrollWheelUp> <nop>
inoremap <ScrollWheelDown> <nop>
inoremap <S-ScrollWheelDown> <nop>
inoremap <C-ScrollWheelDown> <nop>
inoremap <ScrollWheelLeft> <nop>
inoremap <S-ScrollWheelLeft> <nop>
inoremap <C-ScrollWheelLeft> <nop>
inoremap <ScrollWheelRight> <nop>
inoremap <S-ScrollWheelRight> <nop>
inoremap <C-ScrollWheelRight> <nop>
" Incremental substitutin
set inccommand=split

View file

@ -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";
};
};
}

View file

@ -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;
# };
};
}

View file

@ -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 ];
}
)

View file

@ -0,0 +1,32 @@
" Nerdtree
noremap <leader>nt :NERDTreeToggle<CR>
noremap <leader>nf :NERDTreeFind<CR>
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