{ pkgs, ... }:
{
  imports = [
    ./telescope.nix
  ];
  programs.nixvim = {
    colorscheme = "sonokai";
    clipboard.register = "unnamedplus"; # Copy to system clipboard
    enable = true;
    extraPlugins = [
      pkgs.vimPlugins.indentLine
      pkgs.vimPlugins.nvim-lspconfig
      pkgs.vimPlugins.polyglot
      pkgs.vimPlugins.sonokai
      pkgs.vimPlugins.vim-better-whitespace
      (pkgs.vimUtils.buildVimPlugin {
        pname = "lualine-so-fancy.nvim";
        version = "HEAD";
        src = pkgs.fetchFromGitHub {
          owner = "meuter";
          repo = "lualine-so-fancy.nvim";
          rev = "45197358e5274d301d98638bf079f3437d6eacf8";
          sha256 = "sha256-j6XI4cw1ouYEvSiKdam8RAqxefDqeLwe37Qir/UO+8g=";
        };
      })
    ];
    globals = {
      mapleader = ",";
      sonokai_style = "atlantis";
      sonokai_disable_italic_comment = 1;
    };
    keymaps = [
      {
        key = "<leader>rm";
        action = "<cmd>RenderMarkdown toggle<CR>";
      }
      {
        key = "<leader>g";
        action = "<cmd>Git<CR>";
      }
      {
        key = "<leader>gp";
        action = "<cmd>Git push<CR>";
      }
      {
        key = "<leader>gl";
        action = "<cmd>Git log<CR>";
      }
      {
        key = "<leader>gbl";
        action = "<cmd>Git blame<CR>";
      }
      {
        key = "<leader>gbr";
        action = "<cmd>Git branch<CR>";
      }
      {
        key = "<leader>t";
        action = "<cmd>Neotree toggle<CR>";
      }
    ];
    opts = {
      colorcolumn = "88";
      cursorline = true;
      number = true;
      spell = false;
      termguicolors = true;
      textwidth = 80;
    };
    plugins = {
      cmp = {
        enable = true;  # Completion
        autoEnableSources = true;
        settings.sources = [
          { name = "nvim_lsp"; }
          { name = "path"; }
          { name = "buffer"; }
        ];
        settings.mapping = {
          "<C-d>" = "cmp.mapping.scroll_docs(-2)";
          "<C-f>" = "cmp.mapping.scroll_docs(2)";
          "<C-Space>" = "cmp.mapping.complete()";
          "<C-e>" = "cmp.mapping.close()";
          "<Tab>" = "cmp.mapping(cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})";
          "<S-Tab>" = "cmp.mapping(cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})";
          "<CR>" = "cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace })";
        };
      };
      committia.enable = true;  # Enhanced git commits
      fugitive.enable = true;
      gitsigns.enable = true;  # Show git change in first line
      guess-indent.enable = true;  # Guess indent of the file
      lsp.enable = true;
      lsp.servers = {
        bashls.enable = true;
        dockerls.enable = true;
        gitlab_ci_ls.enable = true;
        gitlab_ci_ls.package = pkgs.gitlab-ci-ls;
        gopls.enable = true;
        helm_ls.enable = true;
        jsonls.enable = true;
        nixd.enable = true;
        pyright.enable = true;
        pylsp = {
          enable = true;
          settings.plugins = {
            black.enabled = true;
            isort.enabled = true;
            ruff.enabled = true;
            ruff.formatEnabled = false;
          };
        };
        terraformls = {
          enable = true;
          rootDir = "require('lspconfig.util').root_pattern('.git', '.terraform')";
        };
        tflint.enable = true;
        yamlls.enable = true;
      };
      lsp-format.enable = true;  # Automatically format on save
      lsp-lines.enable = true;  # Display LSP hints in lines
      lsp-signature.enable = true;  # Show function signature when typing
      lualine.enable = true;  # Status line
      lualine.settings.sections = {
        lualine_a = [ "fancy_mode" ];
        lualine_b = [ "fancy_branch" "fancy_diff" ];
        lualine_c = [ "fancy_cwd" "filename" ];
        lualine_x = [ "fancy_diagnostics" "fancy_searchcount" ];
        lualine_y = [ "fancy_filetype" ];
        lualine_z = [ "fancy_lsp_servers" ];
      };
      neo-tree.enable = true;
      render-markdown.enable = true;
      tmux-navigator.enable = true;
      treesitter.enable = true;
      web-devicons.enable = true;
    };
  };
}