From c9bd045293b1f805b0199458723450725d5e1a0a Mon Sep 17 00:00:00 2001 From: Sergey Zubkov Date: Fri, 31 May 2024 23:26:12 +0300 Subject: [PATCH] rewrite neovim config --- packages/neovim.nix | 10 +- readme.md | 10 +- sys/aliases.nix | 2 - users/root.nix | 5 +- users/shared.nix | 5 +- .../shared/nvim/{lua/config.lua => init.lua} | 201 +++++++++++++-- users/shared/nvim/init.vim | 243 ------------------ 7 files changed, 189 insertions(+), 287 deletions(-) rename users/shared/nvim/{lua/config.lua => init.lua} (70%) delete mode 100644 users/shared/nvim/init.vim diff --git a/packages/neovim.nix b/packages/neovim.nix index 27f949a..0003438 100644 --- a/packages/neovim.nix +++ b/packages/neovim.nix @@ -2,16 +2,8 @@ pkgs, ... }: { - programs.neovim = { - enable = true; - withRuby = false; - withPython3 = false; - configure = { - customRC = builtins.readFile ../users/shared/nvim/init.vim; - }; - }; - environment.systemPackages = with pkgs; [ + neovim # nix nil alejandra diff --git a/readme.md b/readme.md index a6b85bd..192c385 100644 --- a/readme.md +++ b/readme.md @@ -12,15 +12,15 @@ This repo is just a bunch of NixOS modules, so you can pick or override anything * [Terminus](http://terminus-font.sourceforge.net/shots.html) and [NerdFonts](/sys/fonts.nix) * [Brutal Doom](https://github.com/ksevelyar/brutal-doom), [Quake](https://github.com/ksevelyar/quake), [Steam](https://github.com/ksevelyar/idempotent-desktop/blob/main/packages/games.nix) * [battery optimisation](/hardware/power-management.nix) for laptops -* [picard][picard], [mpd](/services/mpd.nix), [ncmpcpp][ncmpcpp], [mpdscribble](https://listenbrainz.org/user/ksevelyar/) +* [picard][picard], [mpd](/services/mpd.nix), [ncmpcpp][ncmpcpp], [mpdscribble](https://listenbrainz.org/user/ksevelyar/) * [mpv](/users/shared/mpv), [imv][imv] * [live-usb](/live-usb/live-usb.nix) * [tealdeer](https://github.com/dbrgn/tealdeer) aliased to h ## Linux as IDE -* Tiling with [leftwm](/users/shared/leftwm/config.toml), polybar, dunst and [tmux](/packages/tmux.nix) -* [fish](/doc/fish.md), direnv, alacritty, ripgrep, rsync, fzf, [zoxide][zoxide], [delta][delta], gitg, bat, exa -* [Neovim with LSP](https://github.com/ksevelyar/idempotent-desktop/blob/main/users/shared/nvim/init.vim) for Elixir, Rust, Nix, Lua and others +* Tiling with [leftwm](/users/shared/leftwm/config.ron), polybar, dunst and [tmux](/packages/tmux.nix) +* [fish](/doc/fish.md), direnv, alacritty, ripgrep, rsync, fzf, [zoxide][zoxide], [delta][delta], bat, exa +* [Neovim with LSP and TS](https://github.com/ksevelyar/idempotent-desktop/blob/main/users/shared/nvim/init.lua) * fuzzy search by apps [`mod`](/doc/run-rofi-with-one-key.md), emojis `mod + z` and clipboard history `mod + c` wih [rofi](https://github.com/ksevelyar/idempotent-desktop/blob/main/users/shared/rofi/grey.rasi) * [copy color of pixel under mouse cursor](/services/x.nix#L5-L14) to clipboard with `mod + k` * [`PrtScn`](https://github.com/ksevelyar/idempotent-desktop/blob/ea28dfc28596d8edb3b88683e9960b4a32cc9c46/users/shared/leftwm/config.toml#L180-L184) to capture region, `mod + PrtScn` to capture fullscreen, record desktop videos with `vokoscreen` @@ -30,7 +30,7 @@ This repo is just a bunch of NixOS modules, so you can pick or override anything * [EdDSA for ssh and gpg keys](/doc/keys.md) * gopass / [browserpass](https://github.com/browserpass/browserpass-extension#available-keyboard-shortcuts) integration * [uBlock](https://github.com/gorhill/uBlock) -* [VPN](https://github.com/ksevelyar/idempotent-desktop/blob/main/services/vpn.nix) +* [nekoray](https://github.com/MatsuriDayo/nekoray) [picard]: https://picard.musicbrainz.org/quick-start/ [imv]: /users/shared/imv/config diff --git a/sys/aliases.nix b/sys/aliases.nix index d451a98..9566150 100644 --- a/sys/aliases.nix +++ b/sys/aliases.nix @@ -9,7 +9,6 @@ pgrep = "pgrep --full"; pkill = "pkill --full"; i = "host-info"; - ms = "mosh"; cat = "bat --paging=never --plain"; bat = "bat --paging=never -n"; @@ -47,7 +46,6 @@ # vim v = "nvim"; - vv = "nvim -U none"; # vanilla v, don't load plugins & init.vim # sec p = "gopass"; diff --git a/users/root.nix b/users/root.nix index a54957b..092031d 100644 --- a/users/root.nix +++ b/users/root.nix @@ -2,9 +2,8 @@ home-manager = { useGlobalPkgs = true; users.root = { - home.stateVersion = "23.11"; - home.file.".config/nvim/init.vim".source = ../users/shared/nvim/init.vim; - home.file.".config/nvim/lua/config.lua".source = ../users/shared/nvim/lua/config.lua; + home.stateVersion = "24.05"; + home.file.".config/nvim/init.lua".source = ../users/shared/nvim/init.lua; home.file.".config/fish/config.fish".source = ../users/shared/fish/config.fish; home.file.".config/fish/functions/fish_prompt.fish".source = ../users/shared/fish/functions/fish_prompt.fish; diff --git a/users/shared.nix b/users/shared.nix index eabe818..6a3cc4f 100644 --- a/users/shared.nix +++ b/users/shared.nix @@ -55,7 +55,7 @@ home-manager = { useGlobalPkgs = true; users.${user} = { - home.stateVersion = "23.11"; + home.stateVersion = "24.05"; home.pointerCursor = lib.mkDefault { x11.enable = true; @@ -97,8 +97,7 @@ home.file.".npmrc".source = ../users/shared/.npmrc; - home.file.".config/nvim/init.vim".source = ../users/shared/nvim/init.vim; - home.file.".config/nvim/lua/config.lua".source = ../users/shared/nvim/lua/config.lua; + home.file.".config/nvim/init.lua".source = ../users/shared/nvim/init.lua; home.file.".config/fish/config.fish".source = ../users/shared/fish/config.fish; home.file.".config/fish/functions/fish_prompt.fish".source = ../users/shared/fish/functions/fish_prompt.fish; diff --git a/users/shared/nvim/lua/config.lua b/users/shared/nvim/init.lua similarity index 70% rename from users/shared/nvim/lua/config.lua rename to users/shared/nvim/init.lua index 17e1816..9cbf21d 100644 --- a/users/shared/nvim/lua/config.lua +++ b/users/shared/nvim/init.lua @@ -1,3 +1,151 @@ +-- https://neovim.io/doc/user/lua-guide.html#lua-guide + +-- deps +-- :checkhealth lazy +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +-- disable netrw at the very start of your init.lua +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +-- history +vim.opt.undofile = true + +vim.opt.laststatus = 2 +vim.opt.signcolumn = "yes" +vim.opt.number = true +vim.opt.title = true + +-- tabs +vim.opt.shiftwidth = 2 +vim.opt.softtabstop = 2 +vim.opt.tabstop = 2 +vim.opt.expandtab = true + +-- delays +vim.opt.updatetime = 250 +vim.opt.timeoutlen = 300 + +-- search +vim.opt.ignorecase = true +vim.opt.smartcase = true +vim.opt.gdefault = true + +vim.opt.shortmess = "AIT" + +-- windows +vim.opt.splitright = true +vim.opt.splitbelow = true + +vim.opt.list = true +vim.opt.listchars = { nbsp = "¬", tab = ">•", extends = "»", precedes = "«", trail = "¶" } +vim.opt.clipboard = "unnamedplus" + +vim.g.mapleader = " " + +vim.keymap.set('n', '', 'nohlsearch') +vim.keymap.set('n', 'w', ":write") + +vim.keymap.set('n', 't', ":NvimTreeToggle") +vim.keymap.set('n', ";", ":") +vim.keymap.set('n', 'f', ":NvimTreeFindFile") + +vim.keymap.set('n', 'c', ':normal gcc', { desc = '[/] Toggle comment line' }) +-- - exists visual mode. +-- :normal executes keystrokes in normal mode. +-- gv - restores selection. +-- gc - toggles comment +-- sends the command +vim.keymap.set('v', 'c', ':normal gvgc', { desc = '[/] Toggle comment block' }) + +require("lazy").setup({ + "airblade/vim-rooter", + "tpope/vim-fugitive", + { + "lewis6991/gitsigns.nvim", + config = function() + require("gitsigns").setup() + end + }, + { + 'ethanholz/nvim-lastplace', + config = function() + require('nvim-lastplace').setup {} + end, + }, + "sirtaj/vim-openscad", + "nvim-tree/nvim-tree.lua", + { + "nvim-telescope/telescope.nvim", + dependencies = { 'nvim-lua/plenary.nvim' } + }, + "lukas-reineke/indent-blankline.nvim", + "nvim-lualine/lualine.nvim", + -- lsp + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-vsnip", + "hrsh7th/vim-vsnip", + "neovim/nvim-lspconfig", + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + opts = { + ensure_installed = { + "lua", + "html", + "markdown", + "elixir", + "eex", + "heex", + "rust", + "javascript", + "css", + "dockerfile", + "sql", + "css", + "json", + "nix" + }, + auto_install = true, + highlight = { + enable = true + }, + indent = { enable = true } + }, + config = function(_, opts) + require('nvim-treesitter.install').prefer_git = true + require('nvim-treesitter.configs').setup(opts) + end + }, + -- themes + { + "ksevelyar/joker.vim", + lazy = false, -- to make sure it's loaded on startup + priority = 1000, -- to load before other plugins + config = function() + vim.cmd.colorscheme("joker") + end + }, + { + "shmerl/neogotham", + }, +}) + -- # LSP local lspconfig = require('lspconfig') @@ -23,38 +171,41 @@ cmp.setup({ [''] = cmp.mapping.confirm({ select = true }) }, sources = cmp.config.sources({ - { name = 'nvim_lsp' }, { name = 'vsnip' } - }, { { name = 'buffer' } }) + { name = 'nvim_lsp' }, + { name = 'vsnip' } + }, { + { name = 'buffer' } }) }) -local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) +local capabilities = require('cmp_nvim_lsp').default_capabilities() -- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap = true, silent = true } -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) +local silent = { noremap = true, silent = true } +vim.keymap.set('n', 'e', vim.diagnostic.open_float, silent) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, silent) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, silent) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, silent) -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(_, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - -- 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', '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) + local bufsilent = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufsilent) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufsilent) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufsilent) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufsilent) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufsilent) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufsilent) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufsilent) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufsilent) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufsilent) vim.keymap.set('n', '=', function() vim.lsp.buf.format { async = true } - end, opts) + end, silent) + + vim.keymap.set('n', 'h', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) + end) end lspconfig.rust_analyzer.setup { @@ -285,5 +436,11 @@ require 'telescope'.setup { } } +local builtin = require('telescope.builtin') +vim.keymap.set('n', '', builtin.find_files, {}) +vim.keymap.set('n', 'r', builtin.live_grep, {}) +vim.keymap.set('n', 'b', builtin.git_branches, {}) +vim.keymap.set('n', 'm', builtin.oldfiles, {}) + -- # indent_blankline require("ibl").setup { indent = { char = "|" } } diff --git a/users/shared/nvim/init.vim b/users/shared/nvim/init.vim deleted file mode 100644 index d7fca5f..0000000 --- a/users/shared/nvim/init.vim +++ /dev/null @@ -1,243 +0,0 @@ -" TODO: rewrite to lua modules - -if empty(glob('~/.config/nvim' . '/autoload/plug.vim')) - silent execute '!curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' - autocmd VimEnter * PlugInstall --sync | source $MYVIMRC -endif - -" Plugins -call plug#begin() - -" Behaviour -Plug 'rbgrouleff/bclose.vim' -Plug 'tpope/vim-surround' -Plug 'alvan/vim-closetag' -Plug 'tpope/vim-endwise' -Plug 'janko-m/vim-test' -Plug 'airblade/vim-rooter' -let g:rooter_silent_chdir = 1 - -Plug 'ruanyl/vim-gh-line' " :GH - -Plug 'tomtom/tcomment_vim' -let g:tcomment_maps = 0 - -Plug 'tpope/vim-fugitive' -Plug 'airblade/vim-gitgutter' - -" Syntax -Plug 'plasticboy/vim-markdown' -let g:vim_markdown_folding_disabled=1 - -Plug 'LnL7/vim-nix' -Plug 'dag/vim-fish' - -Plug 'elixir-editors/vim-elixir' - -Plug 'cakebaker/scss-syntax.vim' " TODO: replace with sugarss -Plug 'digitaltoad/vim-pug' - -Plug 'elzr/vim-json' -let g:vim_json_syntax_conceal = 0 - -Plug 'chr4/nginx.vim' - -Plug 'sirtaj/vim-openscad' - -" Navigation -Plug 'kyazdani42/nvim-tree.lua' -Plug 'nvim-lua/plenary.nvim' -Plug 'nvim-telescope/telescope.nvim' - -" UI -Plug 'lukas-reineke/indent-blankline.nvim' -Plug 'nvim-lualine/lualine.nvim' - -" Color Themes -Plug 'ksevelyar/joker.vim' -" Plug '/c/joker.vim' -Plug 'shaunsingh/nord.nvim' -Plug 'folke/tokyonight.nvim' -Plug 'rafalbromirski/vim-aurora' -Plug 'dracula/vim' -Plug 'whatyouhide/vim-gotham' -Plug 'arcticicestudio/nord-vim' -Plug 'cocopon/iceberg.vim' - -Plug 'luochen1990/rainbow' -Plug 'tpope/vim-scriptease' - -" IDE -Plug 'hrsh7th/cmp-nvim-lsp' -Plug 'hrsh7th/cmp-buffer' -Plug 'hrsh7th/cmp-path' -Plug 'hrsh7th/cmp-cmdline' -Plug 'hrsh7th/nvim-cmp' - -" For vsnip users. -Plug 'hrsh7th/cmp-vsnip' -Plug 'hrsh7th/vim-vsnip' - -Plug 'neovim/nvim-lspconfig' - -Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} - -call plug#end() - -lua require('config') - -" Core Settings -set conceallevel=0 - -set splitbelow -set splitright - -syntax on -filetype plugin on " to use filetype plugin -filetype indent on " to use filetype indent - -set updatetime=100 -set laststatus=2 -set signcolumn=yes -set hidden -set path+=** " type gf to open file under cursor -set number -set colorcolumn=100 - -set encoding=utf-8 -set fileformat=unix - -set title - -" Disable annoying sound on errors -set noerrorbells -set novisualbell - -" UI ---------------------------------------------------------------------------------------------- -set mouse=a - -" T truncate other messages in the middle if they are too long -" A don't give the "ATTENTION" message when an existing swap file is found -" I don't give the intro message when starting Vim |:intro| -set shortmess=AIT - -set wildmenu -set wildmode=list:longest,full - -if (has("termguicolors")) - set termguicolors -endif - -" :Colors to change theme -silent! colorscheme joker - -" Tree view for netrw -let g:netrw_liststyle = 3 - -set noshowmode " cause the shape of cursor indicates the mode already -set clipboard=unnamedplus " sync vim clipboard with linux clipboard - -" Backups ----------------------------------------------------------------------------------------- -if isdirectory($HOME . '/.config/nvim/undo') == 0 - :silent !mkdir -p ~/.config/nvim/undo > /dev/null 2>&1 -endif -if isdirectory($HOME . '/.config/nvim/backup') == 0 - :silent !mkdir -p ~/.config/nvim/backup > /dev/null 2>&1 -endif - -set history=1000 -set undodir=~/.config/nvim/undo// -set noswapfile - -set backup -set backupdir=~/.config/nvim/backup// -set writebackup "Make backup before overwriting the current buffer -set backupcopy=yes "Overwrite the original backup file - -" Meaningful backup name, ex: filename@2015-04-05.14 -autocmd BufWritePre * let &bex = 'gh' . '@' . strftime("%F.%H") . '.bac' - -set undofile -set undolevels=999 -set display+=lastline -set nojoinspaces - -" Behaviour ------------------------------------------------------------------------------------------ -" go to last file on startup -autocmd VimEnter * nested - \ if argc() == 0 - \| let last = filter(filter(copy(v:oldfiles), 'match(v:val, getcwd()) == 0'), 'filereadable(v:val)') - \| if !empty(last) - \| execute 'edit' fnameescape(last[0]) - \| endif - \| endif - -" go to last position in file on sttartup -autocmd BufReadPost * - \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' - \ | exe "normal! g`\"" - \ | endif - -" Do not automatically insert a comment leader after an enter -autocmd FileType * setlocal formatoptions-=ro - -set shiftwidth=2 -set softtabstop=2 -set tabstop=2 -set expandtab - -set list -set listchars=nbsp:¬,tab:>•,extends:»,precedes:«,trail:¶ - -" Search ------------------------------------------------------------------------------------------ -set ignorecase -set smartcase - -set incsearch -set inccommand=split -set gdefault - -" JK motions: Line motions -set so=2 " Set 2 lines to the cursor - when moving vertically using j/k - -" ------------------------------------------------------------------------------------------------- -" Key Mappings -" ------------------------------------------------------------------------------------------------- -let g:mapleader = " " - -nnoremap " navigate down -nnoremap " navigate up -nnoremap " navigate right -nnoremap " navigate left - -nmap c :TComment -xmap c :TComment - -nnoremap v v -nnoremap h s - -nnoremap Telescope find_files -nnoremap r Telescope live_grep -nnoremap b Telescope git_branches -nnoremap m Telescope oldfiles -nnoremap l Telescope lsp_document_symbols - -nnoremap t :NvimTreeToggle -nnoremap f :NvimTreeFindFile -nnoremap w :w - -nnoremap y :%y+ - -set spelllang=en_us -nnoremap o :set spell! - -" copy / paste -imap "+pi - -nnoremap ; : -" Shift+V d for cut -nnoremap d "_d - -" Treat long lines as break lines (useful when moving around in them) -map j gj -map k gk