# Yanked from Misterio77's great config: https://github.com/Misterio77/nix-config { pkgs, config, lib, ... }: let inherit (lib) mkIf mkEnableOption; cfg = config.modules.devtools.neovim; in { imports = [ ./plugins ./lsp.nix ./syntaxes.nix ]; options = { modules.devtools.neovim.enable = mkEnableOption "Enable neovim"; }; config = mkIf cfg.enable { programs.neovim = { enable = true; extraConfig = /* vim */ '' "Use system clipboard set clipboard=unnamedplus "colorscheme colorscheme gruvbox-material set number "Lets us easily trigger completion from binds set wildcharm= "Folding set foldmethod=manual "Should be expr, but it's slow. So just use ':set fdm=expr' when it's needed. "Tabs set tabstop=4 "4 char-wide tab set expandtab "Use spaces set softtabstop=0 "Use same length as 'tabstop' set shiftwidth=0 "Use same length as 'tabstop' "2 char-wide overrides augroup two_space_tab autocmd! autocmd FileType json,html,htmldjango,hamlet,nix,scss,typescript,php,haskell,terraform setlocal tabstop=2 augroup END "Set tera to use htmldjango syntax augroup tera_htmldjango autocmd! autocmd BufRead,BufNewFile *.tera setfiletype htmldjango augroup END "Options when composing mutt mail augroup mail_settings autocmd FileType mail set noautoindent wrapmargin=0 textwidth=0 linebreak wrap formatoptions +=w augroup END "Fix nvim size according to terminal "(https://github.com/neovim/neovim/issues/11330) augroup fix_size autocmd VimEnter * silent exec "!kill -s SIGWINCH" getpid() augroup END "Scroll up and down nmap nmap "Buffers nmap b :buffers nmap :bnext nmap :bprev nmap :bdel "Navigate nmap e :e nmap e :e %:h "CD to current dir nmap c :cd nmap C :cd %:h "Loclist nmap l :lwindow nmap [l :lprev nmap ]l :lnext nmap L :lhistory nmap [L :lolder nmap ]L :lnewer "Quickfix nmap q :cwindow nmap [q :cprev nmap ]q :cnext nmap Q :chistory nmap [Q :colder nmap ]Q :cnewer "Make nmap m :make "Grep (replace with ripgrep) nmap g :grep if executable('rg') set grepprg=rg\ --vimgrep set grepformat=%f:%l:%c:%m endif "Close other splits nmap o :only "Sudo save cmap w!! w !sudo tee > /dev/null % ''; extraLuaConfig = /* lua */ '' vim.g.have_nerd_font = true vim.wo.relativenumber = false vim.opt.cursorline = true vim.keymap.set("n", "", "ggVG", { desc = "Select all" }) vim.keymap.set("n", "", "p", { desc = "Paste" }) vim.keymap.set("i", "", "p", { desc = "Paste" }) vim.keymap.set("v", "", "y", { desc = "Yank" }) vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { desc = "Go to declaration" }) vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition" }) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "Go to implementation" }) vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Hover Documentation" }) vim.keymap.set("n", "a", vim.lsp.buf.code_action, { desc = "Code action" }) -- Diagnostic vim.keymap.set("n", "d", vim.diagnostic.open_float, { desc = "Floating diagnostic" }) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Previous diagnostic" }) vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Next diagnostic" }) vim.keymap.set("n", "gl", vim.diagnostic.setloclist, { desc = "Diagnostics on loclist" }) vim.keymap.set("n", "gq", vim.diagnostic.setqflist, { desc = "Diagnostics on quickfix" }) function add_sign(name, text) vim.fn.sign_define(name, { text = text, texthl = name, numhl = name }) end add_sign("DiagnosticSignError", "󰅚 ") add_sign("DiagnosticSignWarn", " ") add_sign("DiagnosticSignHint", "󰌶 ") add_sign("DiagnosticSignInfo", " ") vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()" -- When it releases -- vim.opt.foldexpr = "v:lua.vim.treesitter.foldtext()" -- Highlight when yanking (copying) text vim.api.nvim_create_autocmd("TextYankPost", { desc = "Highlight when yanking (copying) text", group = vim.api.nvim_create_augroup("kickstart-highlight-yank", { clear = true }), callback = function() vim.highlight.on_yank() end, }) ''; plugins = with pkgs.vimPlugins; [ vim-table-mode editorconfig-nvim vim-surround gruvbox-material-nvim { plugin = nvim-autopairs; type = "lua"; config = /* lua */ '' require("nvim-autopairs").setup({}) ''; } ]; }; xdg.desktopEntries = { nvim = { name = "Neovim"; genericName = "Text Editor"; comment = "Edit text files"; exec = "nvim %F"; icon = "nvim"; mimeType = [ "text/english" "text/plain" "text/x-makefile" "text/x-c++hdr" "text/x-c++src" "text/x-chdr" "text/x-csrc" "text/x-java" "text/x-moc" "text/x-pascal" "text/x-tcl" "text/x-tex" "application/x-shellscript" "text/x-c" "text/x-c++" ]; terminal = true; type = "Application"; categories = [ "Utility" "TextEditor" ]; }; }; }; }