NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.06k stars 14.12k forks source link

vim: vim.customize.vimrcConfig breaks syntax highlighting, completely resets default vim configuration #301790

Open iFreilicht opened 7 months ago

iFreilicht commented 7 months ago

Describe the bug

When using vim.customize (or vim-full.customize) to add a few plugins, all default plugins and settings are no longer included, which breaks syntax highlighting and many features that the regular vim (or vim-full) have enabled.

This is very confusing, especially with the current documentation, which says (emphasis mine):

Custom configuration

Adding custom .vimrc lines can be done using the following code:

vim-full.customize {
  # `name` optionally specifies the name of the executable and package
  name = "vim-with-plugins";

  vimrcConfig.customRC = ''
    set hidden
  '';
}

I understand that some users might want to completely ignore the default configuration, but as that default is built from the plugins that are installed by default, that seems undesirable in most cases.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Put this flake into flake.nix in a new directory (replace aarch64-darwin with your system):
    inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    outputs = { self, nixpkgs, ... }:
    let
      pkgs = nixpkgs.legacyPackages.aarch64-darwin;
    in
    {
      packages.aarch64-darwin.vim = pkgs.vim.customize {
        vimrcConfig = {
          packages.myPlugins = with pkgs.vimPlugins; {
            start = [ vim-airline surround-nvim repeat ];
            opt = [ ];
          };
        };
      };
    };
    }
  2. Run nix run github:NixOS/nixpkgs/nixpkgs-unstable#vim flake.nix
  3. Observe syntax highlighting is working with the non-customized package
  4. Run nix run path:$PWD#vim flake.nix
  5. Observe syntax highlighting is broken with the customized package
  6. Change the flake.nix to have this content
    {
    inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    outputs = { self, nixpkgs, ... }:
    let
      pkgs = nixpkgs.legacyPackages.aarch64-darwin;
      vim = pkgs.vim;
    in
    {
      packages.aarch64-darwin.vim = vim.customize {
        vimrcConfig = {
          packages.myPlugins = with pkgs.vimPlugins; {
            start = [ vim-airline surround-nvim repeat ];
            opt = [ ];
          };
          customRC = ''
            source ${vim}/share/vim/vim*/defaults.vim
          '';
        };
      };
    };
    }
  7. Run nix run path:$PWD#vim flake.nix again
  8. Observe syntax highlighting now works properly

Expected behavior

customRC should add lines to the existing vimrc instead of replacing it fully.

Screenshots

When running nix run github:NixOS/nixpkgs/nixpkgs-unstable#vim flake.nix

naive flake.nix, shown in default vim, syntax highlighting working

When running nix run path:$PWD#vim flake.nix with the "naive" customization

naive flake.nix, shown in slightly customized vim, syntax highlighting not working

When running nix run path:$PWD#vim flake.nix with the workaround of manually sourcing the default configuration

flake.nix with workaround, shown in customized vim with workaround, syntax highlighting working

Additional context

I'm willing to work on and submit a PR for this myself, but I'm uncertain what the correct solution for this problem is.

My proposal is to add a sourceDefaultRC boolean parameter to vimrcConfig that is true by default, and adding the source source ${vim}/share/vim/vim*/defaults.vim line by default before the customRC. This seems to be the most compatible solution without limiting choice.

I'm not sure if there is a better solution than globbing vim* to find that file, but it seems stable enough to me.

Notify maintainers

@dasJ @equirosa please let me know if you have opinions on my proposed solution.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.4.0, macOS 14.4.1`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.22.0pre20240320_7d2ead5`
 - channels(root): `"nixpkgs"`
 - channels(feuh): `"unstable"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Add a :+1: reaction to issues you find important.

mpickering commented 1 week ago

:+1: This change broke my configuration as well.