Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install further vim plugins? #416

Closed
turion opened this issue Oct 9, 2018 · 11 comments
Closed

How to install further vim plugins? #416

turion opened this issue Oct 9, 2018 · 11 comments

Comments

@turion
Copy link

turion commented Oct 9, 2018

How do I best install vim plugins that aren't listed by nix-env -f '<nixpkgs>' -qaP -A vimPlugins? Is it possible to use vam or pathogen?

@rycee
Copy link
Member

rycee commented Oct 18, 2018

Sorry, I know very little about vim nowadays but on 18.09 I get

$ nix-env -f '<nixpkgs>' -qaP -A vimPlugins | egrep "(pathogen|vam)"
vimPlugins.pathogen                        vimplugin-vim-pathogen-2018-04-05

so at least pathogen (whatever it may be 🙂) should be available. For vam I can't help, I would guess that it mainly is an issue for Nixpkgs.

@teto
Copy link
Collaborator

teto commented Oct 20, 2018

you can add the missing plugins to nixpkgs or keep installing them manually. Parts of my plugins are handled by nixpkgs (with vam I think), the other I keep updating with vim-plug.
Note that vim-plug was added to nixpkgs recently but it is not possible to have several plug#begin blocks so you should have nixpkgs use a different plugin-manager than the one you use manually.

@tobim
Copy link

tobim commented Oct 25, 2018

vam is available from nixpkgs: https://nixos.wiki/wiki/Vim#Using_VAM_as_manager
here is what i do in home.nix:

let
    customPlugins = {
      neoterm = pkgs.vimUtils.buildVimPlugin {
        name = "neoterm";
        src = pkgs.fetchFromGitHub {
          owner = "kassio";
          repo = "neoterm";
          rev = "287eb27d0a21d81c92c1183a5527e1ff0fdc95cb";
          sha256 = "06ny9khdyckszxr77w13hsw2jlf92caifr8x382cda2v2vq3jz4n";
        };
      };
      ...
    };
...
in
  home = {
    programs.neovim = {
      ...
      configure = {
         vam.knownPlugins = pkgs.vimPlugings // customPlugins;
         vam.pluginDictionaries = [
           { names = [
             ...
             "neoterm"
             ...
           ]; }
        ];
      };
    };
  };

@akavel
Copy link

akavel commented Oct 31, 2018

I have a custom HM module I wrote for neovim plugins — see below:

Click to view: ~/.config/nixpkgs/modules/neovim-plugins.nix

{ config, lib, pkgs, ... }:

with lib;

# See: https://nixos.org/nixos/manual/index.html#sec-writing-modules

let
  cfg = config.programs.neovim.plugins;
  oneOf = typeList: foldList (types.either) typeList;
  foldList = f: list: builtins.foldl' f (builtins.head list) (builtins.tail list);
  filterMap = f: list:
    builtins.filter (x: x != null) (map f list);

  pluginFromGitHubURL = url:
    let
      matches = builtins.match "https://github[.]com/([^/]+)/([^/]+)/archive/(.+)\\.tar\\.gz#?([a-z0-9]*)" url;
      parts = if matches == null then null else {
        owner = builtins.elemAt matches 0;
        repo = builtins.elemAt matches 1;
        rev = builtins.elemAt matches 2;
        sha256 = builtins.elemAt matches 3;
      };
    in
      if parts == null then null else pkgs.vimUtils.buildVimPluginFrom2Nix {
        name = "${parts.owner}-${parts.repo}";
        src = pkgs.fetchFromGitHub parts;
      };

  isSimpleString = x:
    (builtins.isString x) && ((pluginFromGitHubURL x) == null);

  toVamPlugin = x:
    if builtins.isAttrs x
      then x
    else
      pluginFromGitHubURL x;

  loadPlugin = plugin: ''
      set rtp^=${plugin.rtp}
      set rtp+=${plugin.rtp}/after
    '';

in {
  # Interface
  options = {
    programs.neovim.plugins = mkOption {
      type = types.listOf (oneOf [types.str types.package]);
      default = [];
      description = ''
        A list of neovim plugins. Elements can be:
        - Vam plugins - those will be installed in neovim; example:
            pkgs.vimPlugins.fugitive
        - GitHub archive URLs - those will be treated as plugin URLs, downloaded and
          installed in neovim. The URLs must have a # and sha256 suffix, which can be
          found by running `nix-prefetch-url --unpack <GitHub-URL>`. Example:
            https://github.com/bkad/CamelCaseMotion/archive/3ae9bf93cce28ddc1f2776999ad516e153769ea4.tar.gz#086q1n0d8xaa0nxvwxlhpwi1hbdz86iaskbl639z788z0ysh4dxw
        - non-URL strings - those will be copied verbatim to vim config (.vimrc); example:
            '''
              " bash-like (or, readline-like) tab completion of paths, case insensitive
              set wildmode=longest,list,full
              set wildmenu
              if exists("&wildignorecase")
                set wildignorecase
              endif
            '''
      '';
    };
  };

  # Implementation
  config = {
    # Note: see `man home-configuration.nix` -> programs.neovim.configure
    programs.neovim.configure.customRC = ''
      " Workaround for broken handling of packpath by vim8/neovim for ftplugins
      filetype off | syn off
      ${builtins.concatStringsSep "\n"
        (map loadPlugin
          (filterMap toVamPlugin cfg))}
      filetype indent plugin on | syn on

      ${builtins.concatStringsSep "\n" (builtins.filter isSimpleString cfg)}
    '';
  };
}

I use it in my ~/.config/nixpkgs/home.nix with:

{ pkgs, ... }:
with pkgs;
{
  imports = [
    ./modules/neovim-plugins.nix
  ];

  config = {
    # ... usual home.nix contents ...

    programs.neovim = {
      enable = true;
      viAlias = true;
      vimAlias = true;

      # My own customizations, added with ./modules/neovim-plugins.nix
      plugins = with pkgs.vimPlugins; [
        # "Defaults everyone can agree on" by Tim Pope.
        sensible
        # Deoplete (auto-completion)
        deoplete-nvim
        ''
          let g:deoplete#enable_at_startup = 1
        ''
        # Press `gS` on line to split it smart, or `gJ` on first line of block to join it smart.
        "https://github.com/AndrewRadev/splitjoin.vim/archive/20868936ea2af5f8a929b0924db65f8a27035a89.tar.gz#0fxsksv25waxaszl81za6qkfiakr4zm63lib5ryvks5d3xvf3697"
        # Highlighting of ANSI escape-coded colours
        "https://github.com/powerman/vim-plugin-AnsiEsc/archive/1ffd1371ba19e5e287ce9e1a689ca974dc02f2b5.tar.gz#1i1fcan27109iq9p9jmhzx6i68dj524f688d7zv3g7yk94ygabj2"
        # ... etc. ...
      ];
    };
  };
}

@rycee Would it be useful for inclusion in home-manager?

@teto
Copy link
Collaborator

teto commented Nov 2, 2018

@akavel Thanks for sharing your solution.
The nixpkgs vim configure mechanism needs a rehaul, ideally with the module system. Merging different types (strings/url/modules) is kinda confusing IMO.

@rpearce
Copy link

rpearce commented May 25, 2019

Here's a solution I found for doing this that I think is pretty useful (using neovim & vimplug, but the same concept applies to the others, I think):

# programs/neovim/custom-plugins.nix

{ pkgs, ... }:

{
  onedark-vim = pkgs.vimUtils.buildVimPlugin {
    name = "onedark-vim";
    src = pkgs.fetchFromGitHub {
      owner = "joshdick";
      repo = "onedark.vim";
      rev = "7f36f83f13d3bdbd3dca4e3e8b2a10a5ecdca5e9";
      sha256 = "0cnn3j3invasqh5sn20gf9lvcksqhracrbyr3pn3fs9shp7f1kxw";
    };
  };
  
  # ...
}

See this file in action here: https://github.com/rpearce/.config/blob/master/programs/neovim/custom-plugins.nix#L4-L12

Then

# programs/neovim/default.nix

let
  plugins = pkgs.vimPlugins // pkgs.callPackage ./custom-plugins.nix {};
in {
  programs.neovim = {
    # ...

    configure = {
      customRC = builtins.readFile ./vimrc;

      plug.plugins = with plugins; [
        # Themes
        onedark-vim
        # ...
      ];
    };
  };
}

See this file in action here: https://github.com/rpearce/.config/blob/master/programs/neovim/default.nix

@rycee
Copy link
Member

rycee commented Dec 1, 2019

Perhaps this was fixed with the merging of #792?

@turion
Copy link
Author

turion commented Dec 1, 2019

I guess so, if people know how to make new vim plugins themselves? (I think I wouldn't by heart, and I'm not sure this is documented anywhere)

@rycee
Copy link
Member

rycee commented Dec 1, 2019

Yeah, I'm sure the situation could improve in that area. There is some mention about how to add new plugins to Nixpkgs in the manual but I'm not sure about how to package plugins outside Nixpkgs. In any case, I believe that is an issue for https://github.com/NixOS/nixpkgs/ and not this repo.

@turion
Copy link
Author

turion commented Dec 1, 2019

Yes, good point.

@turion turion closed this as completed Dec 1, 2019
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/vim-plugin-not-available-on-my-system-but-it-is-in-nixpkgs/11723/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants